I am trying to get OpenGL to use pixels instead of units, and change its coordinate system to (0,0) = top right of screen and (WIDTH,HEIGHT) = bottom right of the screen. It seems like this is working, but i can't seem to get OpenGL to use pixels for length units.
code for, when the window is rezised/created
[source langg = "cpp"]
GLvoid ReSizeGLScene(GLsizei width, GLsizei height) // Resize And Initialize The GL Window
{
if (height==0) // Prevent A Divide By Zero By
{
height=1; // Making Height Equal One
}
glViewport(0,0,width,height); // Reset The Current Viewport
glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
glLoadIdentity(); // Reset The Projection Matrix
gluOrtho2D(0,WIDTH,HEIGHT,0);
// Calculate The Aspect Ratio Of The Window
gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);
glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
glLoadIdentity(); // Reset The Modelview Matrix
}
WIDTH = 800
HEIGHT = 600
The following code is supposed to draw my texture(top left corner at (0,0), this it is doing correctly so no problem there), but instead of producing a square, it produces a rectangle, width a greater height than width. It also seem to get the length units all wrong. ( i know i am translating into the screen, but if i don't, the image isn't being drawn, for some reason..)
[source langg = "cpp"]
int DrawGLScene(GLvoid) // Here's Where We Do All The Drawing
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0.0f,0.0f,-2.0f);
glBindTexture(GL_TEXTURE_2D, texture[0]);
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f); glVertex3f(0, 500, 0); // Bottom Left Of The Texture and Quad
glTexCoord2f(1.0f, 0.0f); glVertex3f( 500, 500, 0); // Bottom Right Of The Texture and Quad
glTexCoord2f(1.0f, 1.0f); glVertex3f( 500, 0, 0); // Top Right Of The Texture and Quad
glTexCoord2f(0.0f, 1.0f); glVertex3f(0, 0, 0); //top left of the texture and quad
glEnd();
return TRUE;
}
Thanks in advance!
-Mads
•°*”˜˜”*°•.˜”*°•..•°*”˜.•°*”˜˜”*°•..•°*”˜˜”*°•.˜”*°•.˜”*°•. Mads .•°*”˜.•°*”˜.•°*”˜˜”*°•.˜”*°•..•°*”˜.•°*”˜.•°*”˜ ˜”*°•.˜”*°•.˜”*°•..•°*”˜I am going to live forever... or die trying!