Hi All,
I am doing texture mapping for the first time in my life, and i am a bit stuck, as i am a beginner and dont know much about programming hehe… but so far so good. I made 2 planes, one blue and one white (placed on top of the blue plane), and all i want to do is basically load a texture and map it to the blue plane. Now, my compiler tells me that this function —> gltLoadTGA ( FROM the line that reads: pBytes = gltLoadTGA(“stone.tga”, &iWidth, &iHeight, &iComponents, &eFormat)
is not declared… what am i doing wrong?
#include <GLUT/glut.h>
#include <OpenGL/OpenGL.h>
#include <stdlib.h>
#define ESC_KEY 27
GLuint textures[4];
void drawRGBCube();
void display ( void ) {
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix(); //----> SAVE
glTranslatef(-2.0f, -3.0f, -2.f);
drawRGBCube(); //DRAW CUBE
glPopMatrix(); //---------> RESTORE
}
void drawRGBCube() {
[b]//WHITE PLANE[/b]
glBegin(GL_QUADS);
glColor4f(1.0,1.0,1.0,1.0);
glVertex3f(-.15f, 10.0f, -6.0f);
glVertex3f( 4.5f, 10.0f, -6.0f);
glVertex3f( 6.5f,-2.0f, -6.0f);
glVertex3f(-2.5f,-2.0f, -6.0f);
glEnd();
[b]//BLUE PLANE [/b]
glColor3f(0.0f, 0.0f, 0.90f); // Blue
glBegin(GL_QUADS);
glVertex3f(-100.0f, -25.3f, -100.0f);
glVertex3f(-100.0f, -25.3f, 100.0f);
glVertex3f(100.0f, -25.3f, 100.0f);
glVertex3f(100.0f, -25.3f, -100.0f);
glEnd();
[b]//TEXTURE: mapping of texture [/b]
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, textures[0]);
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f); //TexCoord mapping the textures coordinate with the primitive or the blue plane
glVertex3f(-100.0f, -25.3f, -100.0f);
glTexCoord2f(0.0f, 1.0f); //the corners of the texture correspond to the corners of the quad.
glVertex3f(-100.0f, -25.3f, 100.0f);
glTexCoord2f(1.0f, 1.0f);
glVertex3f(100.0f, -25.3f, 100.0f);
glTexCoord2f(1.0f, 0.0f);
glVertex3f(100.0f, -25.3f, -100.0f);
glEnd();
glutPostRedisplay();
glutSwapBuffers();
}
void SetupRC()
{
GLbyte *pBytes;
GLint iWidth, iHeight, iComponents;
GLenum eFormat;
[b]// LOAD TEXTURE [/b]
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
pBytes = gltLoadTGA("stone.tga", &iWidth, &iHeight, &iComponents, &eFormat); [b]//here is the problem gltLoadTGA is not declared in this scope... uhhmmm where do i declare this? i mean what am i supposed to write? I dont understand this function[/b]
glTexImage2D(GL_TEXTURE_2D, 0, iComponents, iWidth, iHeight, 0, eFormat, GL_UNSIGNED_BYTE, pBytes);
free(pBytes);
[b]//TEXTURE PARAMETERS [/b]
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glEnable(GL_TEXTURE_2D);
}
//THE WINDOW
void reshape(int width, int height)
{
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if (height==0)
gluPerspective ( 175, float(width), 1.0, 500.0 ); //75 er en y-størrelse, af FOW, dvs kamera/aksen bliver ændre og ikke objektet
else
gluPerspective ( 175, float(width)/height, 1.0, 500.0); //-1.0 tæt på kamera
glMatrixMode(GL_MODELVIEW);
}
//WINDOW END
void keyboard ( unsigned char key, int x, int y )
{
glLoadIdentity();
switch ( key )
{
case ESC_KEY:
exit(1);
break;
glutPostRedisplay();
break;
default:
break;
}
glutPostRedisplay();
}
int main(int argc, char* argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH );
glutInitWindowSize(300, 300 );
glutCreateWindow("Cube Animation");
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glEnable(GL_DEPTH_TEST);
SetupRC();
glutMainLoop();
return 0;
}