PDA

View Full Version : How to render in pixels



06-29-2004, 07:35 AM
i want to render in pixels and i dont know how to do it :( :(

jabe
06-29-2004, 08:55 AM
you want to do what?

do you mean, you want to give screen coordinates for rendering triangles? most of the time opengl is used for 3d applications. it is nearly impossible to specify geometry in screen coordinates. otherwise you would loose a lot of information. if you want to use opengl as a high speed 2d blitting api, your will is good and can be satisfied.

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, screenWidth, 0, screenHeight, -1, 1);

now your glVertex2x calls will use screen coordinates.

06-29-2004, 09:40 AM
I donīt know how long is the line when its lenght is 1.0f . But in pixels it must have some lenght. I need to draw as large quad as size of picture which will be its texture. how can I do that? please

jabe
06-29-2004, 11:18 AM
the glOrtho snipped from my last answer sets the opengl "2d coordinate system" to screen coordinates. you can draw your quad as follows:



// setting the projection to screen coordinates
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, screenWidth, 0, screenHeight, -1, 1);

// enabling texturing and bind the always loaded texture
glEnable(GL_TEXTURE2D);
glBindTexture(GL_TEXTURE_2D, myTexture);

// safety first
glColor4f(1,1,1,1);

// draws a quad
glBegin(GL_QUAD);

glTexCoord2d(0,0);
glVertex2f(0,0);

glTexCoord2f(1,0);
glVertex2f(imageWidth,0);

glTexCoord2f(1,1);
glVertex2f(imageWidth,imageHeight);

glTexCoord2f(0,1);
glVertex2f(0,imageHeight);

glEnd();thats it basically.
you should try to stop thinking in screen coordinates when using opengl as a 3d render api. it is much more flexible to be resolution independent :)

regards,
jan