PDA

View Full Version : problem with texture



rom
08-30-2000, 12:02 AM
When the following program starts, there is an error whiwh says Error load DIBI texture.bmp. But my picture has
the good size and it is in the good directory.
Thanks for jour help


#include <gl/glut.h>
#include <gl/glu.h>
#include <gl/gl.h>
#include <gl/glaux.h>

////////////////////////////////////////////////////////


//Fenêtre GLUT
int Win;
double a=0;
//Fonction d'initialisation

//Fonction de redimensionnement
void LoadGLTextures();
//Fonction de dessin
void DrawGLScene(void);
void Reshape(int w,int h);
void InitGL();

BOOL keys[256];

GLfloat xrot;
GLfloat yrot;
GLfloat zrot;

GLuint texture[1];


////////////////////////////////////////////////////////

int main( int argc, char *argv[ ], char *envp[ ] )
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
Win=glutCreateWindow("Démo Texture");
glutReshapeFunc(Reshape);
glutDisplayFunc(DrawGLScene);
InitGL();
glutMainLoop();

return 0;

}

void LoadGLTextures()
{
// Load Texture
AUX_RGBImageRec *texture1;
texture1 = auxDIBImageLoad("texture.bmp");
if (!texture1) exit(1);

// Create Texture
glGenTextures(1, &texture[0]);
glBindTexture(GL_TEXTURE_2D, texture[0]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, 3, texture1->sizeX, texture1->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE,
texture1->data);
};


////////////////////////////////////////////////////////
void DrawGLScene(void)

{

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glLoadIdentity();

glTranslatef(0.0f,0.0f,-5.0f);


glRotatef(xrot,1.0f,0.0f,0.0f); // Rotate On The X Axis

glRotatef(yrot,0.0f,1.0f,0.0f); // Rotate On The Y Axis

glRotatef(zrot,0.0f,0.0f,1.0f); // Rotate On The Z Axis


glBindTexture(GL_TEXTURE_2D, texture[0]);

glBegin(GL_QUADS);

// Front Face

glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); // Bottom Left Of The Texture and Quad

glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f); // Bottom Right Of The Texture and Quad

glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f); // Top Right Of The Texture and Quad

glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f); // Top Left Of The Texture and Quad

// Back Face

glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f); // Bottom Right Of The Texture and Quad

glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); // Top Right Of The Texture and Quad

glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f); // Top Left Of The Texture and Quad

glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f); // Bottom Left Of The Texture and Quad

// Top Face

glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); // Top Left Of The Texture and Quad

glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, 1.0f, 1.0f); // Bottom Left Of The Texture and Quad

glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, 1.0f, 1.0f); // Bottom Right Of The Texture and Quad

glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f); // Top Right Of The Texture and Quad

// Bottom Face

glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, -1.0f); // Top Right Of The Texture and Quad

glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, -1.0f, -1.0f); // Top Left Of The Texture and Quad

glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f); // Bottom Left Of The Texture and Quad

glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); // Bottom Right Of The Texture and Quad

// Right face

glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f); // Bottom Right Of The Texture and Quad

glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f); // Top Right Of The Texture and Quad

glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f); // Top Left Of The Texture and Quad

glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f); // Bottom Left Of The Texture and Quad

// Left Face

glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f); // Bottom Left Of The Texture and Quad

glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); // Bottom Right Of The Texture and Quad

glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f); // Top Right Of The Texture and Quad

glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); // Top Left Of The Texture and Quad

glEnd();


xrot+=0.3f; // X Axis Rotation

yrot+=0.2f; // Y Axis Rotation

zrot+=0.4f; // Z Axis Rotation
glutSwapBuffers();
glutPostRedisplay();

}

void Reshape(int w,int h)
{
glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f,float(w)/float(h),0.1f,100.0f);
}

void InitGL()
{
LoadGLTextures();
glEnable(GL_TEXTURE_2D);
glClearColor(0.0f,0.0f,0.0f,0.0f);
glClearDepth(1.0);
glDepthFunc(GL_LESS);
glEnable(GL_DEPTH_TEST);
glShadeModel(GL_SMOOTH);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
//gluPerspective(45.0f,(GLfloat)Width/(GLfloat)Height,0.1f,100.0f);
glMatrixMode(GL_MODELVIEW);

}

Geniesser
08-30-2000, 02:35 AM
I had the same problem i think. I took a program like Paintshop Pro and converted the image to the .dib Format. Maybe there is another aux-function for BMP. But i read it in a tutorial that you can load bmp with the aux function you used.

Bye
Florian Breier www.open-gl.de (http://www.open-gl.de)