View Full Version : Drawing mere pixel
09-19-2003, 11:37 PM
I'm trying to just draw a single pixel in an opengl view... I've tried the following code but not seen anything but the black background...what else is needed?
glClearColor(0.0, 0.0, 0.0, 0.0);
09-19-2003, 11:42 PM
You need to setup the modelview transformation, the default "camera" in OpenGL is located at 0,0,0 looking along Z axis and you would probably need to change that to make your point visible, take a look at a tutorial on OpenGL, you can just do a glTranslate( 0, 0, distance_from_origin) or use gluLookAt() to change the "camera"
09-20-2003, 12:18 AM
On the default modelview and projection (identity matrices), a glVertex3f(0.0f,0.0f,0.0f); will give you a point in the center of the screen.
Not sure, but maybe DrawPixels would be closer to what you are trying to do.
09-20-2003, 09:09 AM
Yeah, the problem is I have be able to draw a pixel in the right spot in a view...
I'm required for a class to write the code to draw a line and to convert from world coordinates to screen coordinates. Once in screen coordinates, I'm supposedly able to use this code:
void Pixel::drawPixel(int xPixel, int yPixel)
//convert from pixel to world projected coordinates and plot one pixel
xCanonical=(xPixel*2.0)/xWindow + (-1.0*(xWindow-1))/xWindow;
yCanonical=(-1.0*yPixel*2.0)/yWindow + (1.0*(yWindow-1))/yWindow;
to actually draw the pixel, but I haven't had any luck as of yet...
How far can you stretch the assignment? You can make the conversion trivial, but I expect that will break the rules...
Use glOrtho or gluOrtho2D to create a scene with the xmax and ymax set to the window's width and height, and xmin and ymin set to 0. This should give a one-to-one correspondence between your drawing space and the pixels on the screen.
Hint for the future: instead of adding together values in the glClear call, bitwise OR them (use | instead of +). If you ever typo and include the same value twice, this will save a lot of head-scratching.
09-20-2003, 11:29 AM
Thanks for the tip with the or operand YA Anonymous User...
Turns out what I was forgetting was the fact that I have to use values between -1 and 1... *oops*
Powered by vBulletin® Version 4.2.3 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.