Jump to content

  • Log In with Google      Sign In   
  • Create Account

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


Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
5 replies to this topic

#1 uberNooble   Members   -  Reputation: 212

Like
0Likes
Like

Posted 11 March 2014 - 02:16 PM

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!



#2 Promit   Moderators   -  Reputation: 11898

Like
0Likes
Like

Posted 11 March 2014 - 02:47 PM

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 | Shark Eaters for iOS | Ventspace Blog | Twitter | Proud supporter of diversity and inclusiveness in game development

#3 AhmedSaleh   Members   -  Reputation: 155

Like
1Likes
Like

Posted 11 March 2014 - 04:07 PM

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 .

#4 Ludus   Members   -  Reputation: 1017

Like
1Likes
Like

Posted 11 March 2014 - 09:19 PM

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

Make sure to set the colour with SDL_SetRenderDrawColor first.



#5 uberNooble   Members   -  Reputation: 212

Like
0Likes
Like

Posted 11 March 2014 - 10:20 PM

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, 11 March 2014 - 10:22 PM.


#6 AhmedSaleh   Members   -  Reputation: 155

Like
0Likes
Like

Posted 13 March 2014 - 03:17 AM

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 .




Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.




PARTNERS