Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

LanceVorgin

OpenGL 2D Pixel Print in OpenGL?

This topic is 6084 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

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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);
}

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!