I am trying to auto-generate a series of polygons in orthographic mode with the same BMP texture mapped to each one. On some of polygons, the image isn’t drawn like I am expecting. I used the NeHe Lesson 6 as a basis.
Some portions of the code:
#define IMAGE_COUNT 10
struct FPOINT
{
float x;
float y;
};
struct POLY_DATA
{
FPOINT ul;
FPOINT ur;
FPOINT ll;
FPOINT lr;
};
POLY_DATA TextureCoords =
{
{ 0.0, 1.0 }, { 1.0, 1.0 },
{ 0.0, 0.0 }, { 1.0, 0.0 }
};
POLY_DATA VertexList[IMAGE_COUNT] =
{
{ { 2.0,2.0 }, { 18.0,2.0 },
{ 2.0,21.0 }, { 18.0,21.0 } },
{ { 132.0,2.0 }, { 148.0,2.0 },
{ 132.0,21.0 }, { 148.0,21.0 } },
{ { 262.0,2.0 }, { 278.0,19.0 },
{ 262.0,60.0 }, { 278.0,38.0 } },
{ { 392.0,19.0 }, { 408.0,2.0 },
{ 392.0,38.0 }, { 408.0,60.0 } },
{ { 522.0,2.0 }, { 570.0,2.0 },
{ 522.0,60.0 }, { 570.0,60.0 } },
{ { 2.0,146.0 }, { 34.0,183.0 },
{ 2.0,279.0 }, { 34.0,242.0 } },
{ { 132.0,183.0 }, { 164.0,146.0 },
{ 132.0,242.0 }, { 164.0,279.0 } },
{ { 262.0,146.0 }, { 374.0,146.0 },
{ 262.0,280.0 }, { 374.0,280.0 } },
{ { 392.0,147.0 }, { 424.0,184.0 },
{ 392.0,357.0 }, { 424.0,320.0 } },
{ { 522.0,184.0 }, { 554.0,147.0 },
{ 522.0,320.0 }, { 554.0,357.0 } }
};
AUX_RGBImageRec *LoadBMP(char *Filename)
{
FILE *File=NULL;
if (!Filename)
return NULL;
File=fopen(Filename,“r”);
if (File)
{
fclose(File);
return auxDIBImageLoad(Filename);
}
return NULL;
}
int LoadGLTextures()
{
int Status=FALSE;
AUX_RGBImageRec *TextureImage[1];
memset(TextureImage,0,sizeof(void *)*1);
if (TextureImage[0]=LoadBMP(“Data/wall.bmp”))
{
Status=TRUE;
glGenTextures(1, &texture[0]);
glBindTexture(GL_TEXTURE_2D, texture[0]);
glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
}
if (TextureImage[0])
{
if (TextureImage[0]->data)
free(TextureImage[0]->data);
free(TextureImage[0]);
}
return Status;
}
GLvoid ReSizeGLScene(GLsizei width, GLsizei height)
{
glViewport(0,0,width,height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, width, height, 0, 0, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
int InitGL(GLvoid)
{
if (!LoadGLTextures())
return FALSE;
glEnable(GL_TEXTURE_2D);
glShadeModel(GL_SMOOTH);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
return TRUE;
}
int DrawGLScene(GLvoid)
{
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
glBindTexture(GL_TEXTURE_2D, texture[0]);
for (int i=0;i<IMAGE_COUNT; i++)
{
glBegin(GL_QUADS);
glTexCoord2f(TextureCoords.ll.x, TextureCoords.ll.y);
glVertex2f(VertexList[i].ll.x, VertexList[i].ll.y);
glTexCoord2f(TextureCoords.lr.x, TextureCoords.lr.y);
glVertex2f(VertexList[i].lr.x, VertexList[i].lr.y);
glTexCoord2f(TextureCoords.ur.x, TextureCoords.ur.y);
glVertex2f(VertexList[i].ur.x, VertexList[i].ur.y);
glTexCoord2f(TextureCoords.ul.x, TextureCoords.ul.y);
glVertex2f(VertexList[i].ul.x, VertexList[i].ul.y);
glEnd();
}
return TRUE;
}
And a picture of the problem, notice the bend in some of the images.
Any ideas on what would fix this?
Richard