2D Pixel Print in OpenGL?

Started by
5 comments, last by LanceVorgin 21 years, 12 months ago
Does anyone know a command like old school PSet (:p) that just puts a colored pixel at a coordinate? By coordinate I hopefully mean X/Y for the window. It''s for an OpenGL game, not for another program, so it needs to be opengl (?) to avoid flickers and the like. Thanks for reading :D
We are lucky!!! There isn''t any Kaspersky Anti-Virus!!!
Advertisement
you might try....


  glMatrixMode(GL_PROJECTION);glLoadIdentity();glOrtho(0.0, 640.0, 480.0, 0.0, -1.0, 1.0); // or whatever your screen resolution is....glMatrixMode(GL_MODELVIEW);glLoadIdentity();glBegin(GL_POINTS);glVertex2f(320.0f, 240.0f); // draw a point in the center of the screen.glEnd();  


tho, this might be slow....

To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.
To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.
I would REALLY recommend using texture mapped quads, or triangles. I don''t know if there is a Pset feature of OpenGL, but you can do something like that with glDrawPixels. Note that the pixel colors must be preprocessed, since you are only sending a bag of bytes to OpenGL. But if you cannot live without PSet, here is something I wrote out of the top of my head, check for errors!

void pset(float x, float y, unsigned byte colbyte)
{
glRasterPos2f(x, y);
glDrawPixels(1, 1, GL_RGB, GL_UNSIGNED_BYTE, colbyte);
}

Create a kick-ass game! Looking forward to see some good titles!

Dan Fekete
dan@skyersoft.com
Dan FeketeThe Shadowhand Co.If everybody has it's own matrix, then mine is an identity
I think the * is needed


  void pset(float x, float y, unsigned byte *colbyte){glRasterPos2f(x, y);glDrawPixels(1, 1, GL_RGB, GL_UNSIGNED_BYTE, colbyte);}  

Dan FeketeThe Shadowhand Co.If everybody has it's own matrix, then mine is an identity
Thanks for the help. How would I go about drawing a 2D rectangle on the screen. I know about 3d cubes, but not flat rectanges independant of movement.
We are lucky!!! There isn''t any Kaspersky Anti-Virus!!!
applying my code posted above....


  glMatrixMode(GL_PROJECTION);glLoadIdentity();glOrtho(0.0, 640.0, 480.0, 0.0, -1.0, 1.0); // or whatever your screen resolution is....glMatrixMode(GL_MODELVIEW);glLoadIdentity();glBegin(GL_QUADS);  glVertex2f(0.0f, 0.0f);  glVertex2f(10.0f, 0.0f);  glVertex2f(10.0f, 10.0f);  glVertex2f(0.0f, 10.0f);glEnd();    


also OpenGL has a glRect function.

To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.
To the vast majority of mankind, nothing is more agreeable than to escape the need for mental exertion... To most people, nothing is more troublesome than the effort of thinking.
2D raster operations are slow. It is much faster to draw a high-res, texture=mapped, gouraud-shaded, transparently-blended quad in ortho mode than it is to throw a few raw pixels at OpenGL. Sounds strange, right? Well it''s the nature of the beast. Modern graphics hardware wasn''t designed for pixel-plotting.

This topic is closed to new replies.

Advertisement