• Advertisement
Sign in to follow this  

Drawing a singular (or selection of) pixel(s) onto a screen using SDL2

This topic is 1409 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

HI gamedev,

 

First time posting on this site, I hope this is posted on the right sub-section. I have a question and I'm hoping someone may be able to send me in the right direction. 

 

I'm currently focusing on sdl2 (c++) in-order to do anything graphical. My question is simple, how would I go about drawing a pixel onto a window (possibly moving my the drawer(s) by one pixel and continue drawing the next pixel). If this isn't possible, how would I go about achieving something like this (by using a specific API, method)? I would appreciate documenation/tutorials.

 

Thanks in advance!

Share this post


Link to post
Share on other sites
Advertisement

That's not really going to be a good idea if you want any kind of reasonable performance. (And the concept of a drawer location was abandoned decades ago.) What are you actually trying to accomplish at a high level?

Share this post


Link to post
Share on other sites

You need to access the surface's pixel, it's called framerbuffer in computer graphics term. It's visualized as a 2D Array, where the bits per pixels define how many bytes per pixel, so consider an 24bit, RGB colored framebuffer then each channel is one byte.

 

pseudo code from my software rendering library test

SDL_Surface *screen = SDL_SetVideoMode(WINDOW_WIDTH, WINDOW_HEIGHT, 32, SDL_HWSURFACE);
graphics.InitFrameBuffer((uint32_t*)screen->pixels, WINDOW_WIDTH, WINDOW_HEIGHT);

Share this post


Link to post
Share on other sites

I believe this is what you're after: http://wiki.libsdl.org/SDL_RenderDrawPoint

Make sure to set the colour with SDL_SetRenderDrawColor first.

 

Thanks, that's very close to what I need. How would I be able to set the colour of the pixel? 

 

Edit: I'm a fool, I didn't notice the SDL_RenderDrawColor; you're awesome! 

 

 

You need to access the surface's pixel, it's called framerbuffer in computer graphics term. It's visualized as a 2D Array, where the bits per pixels define how many bytes per pixel, so consider an 24bit, RGB colored framebuffer then each channel is one byte.

 

pseudo code from my software rendering library test

SDL_Surface *screen = SDL_SetVideoMode(WINDOW_WIDTH, WINDOW_HEIGHT, 32, SDL_HWSURFACE);
graphics.InitFrameBuffer((uint32_t*)screen->pixels, WINDOW_WIDTH, WINDOW_HEIGHT);

 

 

Cool, sounds interesting. However, how would this allow me to go about drawing separate pixels onto the screen? 

 

That's not really going to be a good idea if you want any kind of reasonable performance. (And the concept of a drawer location was abandoned decades ago.) What are you actually trying to accomplish at a high level?

 

I'm not going for performance or anything fancy by trying to draw the pixels, i'm simply doing this for experimentation -nothing more.

Edited by uberNooble

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement