Original Post
Can anyone help me with my texture mapping app. The texture mapping part is from NeHe-s tutorial.
Code is here:
#include <gl/glut.h>
#include <gl/gl.h>
#include <gl/glu.h>
#include <gl/glaux.h>
unsigned texture[1];
AUX_RGBImageRec *LoadBMP(char *Filename)
{
ifstream fin(Filename);
if(fin.is_open())
{
fin.close();
return auxDIBImageLoad(Filename);
}
return NULL;
}
bool LoadGLTextures()
{
bool status=false;
AUX_RGBImageRec *TextureImage[1];
memset(TextureImage,0,sizeof(void *)*1);
if(TextureImage[0]=LoadBMP("texture.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)
delete TextureImage[0]->data;
delete TextureImage[0];
}
return status;
}
void changeSize(int w, int h)
{
if(h==0)
h=1;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glViewport(0, 0, w, h);
gluPerspective(45, (float)w/h, 1, 1000);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0.0,0.0,5.0,
0.0,0.0,-1.0,
0.0f,1.0f,0.0f);
}
void renderScene()
{
glClear(GL_COLOR_BUFFER_BIT);
glBindTexture(GL_TEXTURE_2D, texture[0]);
glColor3f(0.0, 1.0, 0.0);
glPopMatrix();
glRotatef(90, 1.0, 0.0, 0.0);
glRotatef(20, 0.0, 0.0, 1.0);
glutWireSphere(1.0, 12, 12);
glPushMatrix();
glutSwapBuffers();
glFlush();
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitWindowPosition(-1, -1);
glutInitWindowSize(1024, 768);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
glClearColor(0.0, 0.0, 0.0, 0.0);
glutCreateWindow("Globe");
if(!LoadGLTextures())
return 0;
glEnable(GL_TEXTURE_2D);
glutDisplayFunc(renderScene);
glutReshapeFunc(changeSize);
glutMainLoop();
return 0;
}
[edited by - emzee on June 18, 2002 6:40:43 AM]