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

Started by
4 comments, last by AhmedSaleh 10 years, 1 month ago

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!

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?

SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.

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);
Game Programming is the process of converting dead pictures to live ones .

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

Make sure to set the colour with SDL_SetRenderDrawColor first.

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.

This was my reference to write a software rasterizer:

http://joshbeam.com/articles/triangle_rasterization

Game Programming is the process of converting dead pictures to live ones .

This topic is closed to new replies.

Advertisement