Olof Bjarnason wrote:
Please send the code you are using to draw the texture too…
DrawGLScene() is used to draw the quad with the texture, InitGL is used
to initialize OpenGL. This is a modified nehe-example.
void DrawGLScene() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0.0f, 0.0f, -10.0f);
glBindTexture( GL_TEXTURE_2D, texture[0] );
glBegin(GL_QUADS);
glVertex3f(-1.0f, -1.0f, 0.0f);
glVertex3f( 1.0f, -1.0f, 0.0f);
glVertex3f( 1.0f, 1.0f, 0.0f);
glVertex3f(-1.0f, 1.0f, 0.0f);
glEnd();
SDL_GL_SwapBuffers();
}
void InitGL(int width, int height) {
glViewport(0,0,width, height);
//Todo: load textures
if (!LoadGLTextures()) {
cout<<“Failure to load textures”<<endl;
exit(1);
}
glEnable(GL_TEXTURE_2D); //enable texture mapping
glClearColor(0.0f, 0.0f, 0.0f, 0.0f); //Black Background
glClearDepth(1.0); //enables clearing of deapth buffer
glDepthFunc(GL_LESS); //type of depth test
glEnable(GL_DEPTH_TEST); //enables depth testing
glShadeModel(GL_SMOOTH); //enables smooth color shading
glMatrixMode(GL_PROJECTION);
glLoadIdentity(); //Reste projection matrix
gluPerspective(45.0f, (GLfloat)width/(GLfloat)height, 0.1f, 100.0f);
//calculate aspect ratio of the window
glMatrixMode(GL_MODELVIEW);
}> /Olof
On Sun, 20 Feb 2005 14:45:14 +0100, Tobias Langner <@Tobias_Langner> wrote:
Hi
I am trying to load textures from png-Files using SDL_image. The problem
is, the output shows only the general color of the png, but not any
patterns on it (e.g. a green background with a black cross on it only
shows the background).
I use this code:
bool LoadGLTextures() {
bool status=false;
SDL_Surface *TextureImage[1];
if ( (TextureImage[0]=IMG_Load("tile1.png")) ) {
status=true;
glGenTextures(1, &texture[0]);
glBindTexture(GL_TEXTURE_2D, texture[0]);
glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->w,
TextureImage[0]->h, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->pixels);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
}
if (TextureImage[0]) {
SDL_FreeSurface(TextureImage[0]);
}
return status;
}
What am I doing wrong?
SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl