Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Beginner: Pixel coordiates, put a pixel in the image  (Read 2453 times)

0 Members and 2 Guests are viewing this topic.

Namal

  • Newbie
  • *
  • Posts: 6
    • View Profile
Beginner: Pixel coordiates, put a pixel in the image
« on: June 23, 2012, 12:38:42 pm »
Hello,

I followed the tutorial and managed to compile that programm for a blank window. But then I tried to compile that code from the rendered window tutorial and I got that error

Quote
namal@ubuntu:~/Documents$ g++ -c w2.cpp
namal@ubuntu:~/Documents$ g++ -o w2 w2.o -lsfml-graphics
/usr/bin/ld: w2.o: undefined reference to symbol 'sf::VideoMode::VideoMode(unsigned int, unsigned int, unsigned int)'
/usr/bin/ld: note: 'sf::VideoMode::VideoMode(unsigned int, unsigned int, unsigned int)' is defined in DSO /usr/lib/libsfml-window.so.1.6 so try adding it to the linker command line
/usr/lib/libsfml-window.so.1.6: could not read symbols: Invalid operation
collect2: ld returned 1 exit status

My first question what do I do wrong here and second one: How do I put a single pixel into the screen.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Beginner: Pixel coordiates, put a pixel in the image
« Reply #1 on: June 23, 2012, 12:45:12 pm »
I'd strongly advice you to use SFML 2.0rc.
Although not all the tutorials are yet ported to work with SFML 2.0, the changes are mostly not that dramatic and there's still the good documentation.

If you use the RenderWindow there are more libraries involved than just sfml-graphics. You also need to specify: -lsfml-window and -lsfml-system.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Namal

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Beginner: Pixel coordiates, put a pixel in the image
« Reply #2 on: June 23, 2012, 12:49:35 pm »
I thought if I use graphics that I don't need to use window anymore, because it is included??

?



Edit: ok..now I got that red window, had to use

 g++ -o w2 w2.o -lsfml-graphics -lsfml-window

So I don't have to use it in the header, but Imust  still  link to it, right

But stil: I don't know how to drop a single pixel in that image.
« Last Edit: June 23, 2012, 12:58:24 pm by Namal »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Beginner: Pixel coordiates, put a pixel in the image
« Reply #3 on: June 23, 2012, 12:56:01 pm »
I thought if I use graphics that I don't need to use window anymore, because it is included??

There's a difference between library and header files!
If you use #include <SFMl/Graphics.hpp> you won't need to include System.hpp and Window.hpp, but the three modules are still seperated in the library. So your linker has to know how to link against those three libraries. ;)

But stil: I don't know how to drop a single pixel in that image.

sf::Image gives you a SetPixel() function, look it up in the documentation! :)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Namal

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Beginner: Pixel coordiates, put a pixel in the image
« Reply #4 on: June 23, 2012, 02:16:16 pm »
Ok I red a bit about it. But still, I don't understand, How are you able to manipulate the screen into red color, though you have no "image". Respectively, why do I need a image to manipulate single pisels?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Beginner: Pixel coordiates, put a pixel in the image
« Reply #5 on: June 23, 2012, 02:50:08 pm »
You don't get direct access to the window plane itself. SFML let's you set a color for the whole window though.
If you want to manipulate a pixel on the window, just create an sf::Image with the same size as the window, then call the SetPixel() function, add it to a sf::Sprite and draw the sprite to the window.

If you're using SFML 2, it would be slightly more complex. You'd either use an sf::Image use the setPixel function, convert it to a sf::Texture, add it to a sf::Sprite and draw it, or use your own pixel array, then use update() of a sf::Texture, add it to a sf::Sprite and then draw it.
The second version is faster.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/