Hi all.
Right this is the scenario. Ive created a 2D square using GL_POLYGON to it takes up the entire screen (by setting the view point so it does). Ive then successfully mapped a BMP onto this polygon so the bmp takes up the entire screen (kind of like a wallpaper). This works correctly and this is the code ive used:
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glEnable(GL_TEXTURE_2D);
Texture t = Texture();
int i = t.LoadBitmapW("c:/board.bmp");
glBindTexture(GL_TEXTURE_2D, i);
//DRAW THE BACKGROUND
glBegin(GL_POLYGON);
glTexCoord2f(0.0,0.0);glVertex3f(0.0,0.0,0.0);
glTexCoord2f(1.0,0.0);glVertex3f(1.0,0.0,0.0);
glTexCoord2f(1.0,1);glVertex3f(1.0,1,0.0);
glTexCoord2f(0.0,1);glVertex3f(0.0,1,0.0);
glEnd();
glPopMatrix();
glPushMatrix();
glEnable(GL_TEXTURE_2D);
i = t.LoadBitmapW("c:/img.bmp");
glBindTexture(GL_TEXTURE_2D, i);
glBegin(GL_POLYGON);
glTexCoord2f(0.0,0.0);glVertex3f(0.77, 0.628, 0.1);
glTexCoord2f(1.0,0.0);glVertex3f(0.92, 0.628,0.1);
glTexCoord2f(1.0,1.0);glVertex3f(0.92, 0.885, 0.1);
glTexCoord2f(0.0,1.0);glVertex3f(0.77, 0.885,0.1);
glEnd();
glPopMatrix();
glutSwapBuffers();
glFlush();
The code should be easy enough to understand. A big polygon is created and the file “c:/board.jpg” is mapped onto it, this works fine. Then i create a smaller polygon and place it near the top right hand corner the the viewpoint and map the bmp “c:/card.bmp” onto it. However this image isnt mapped correctly onto the polygon, it is stretched to the corners. I believe I have my rotation correct of the polygons (counter clockwise) and the glTexCoord2f is also constructed counter clockwise, however this second polygons mapping is wrong unlike the first polygon. Can anyone see what I’ve done wrong.
Also I have another question for you. Im very new to OpenGL and this is my first program. Would you say that the current way of made my program is untidy, unclean and unprofessional? If so then how can I improve it?
Thanks guys