   Simple textured object
  I'm trying to write a simple program to display a textured object to the screen using SDL/OpenGL with NeHe's Lesson 6 as my guide.  Unfortunately, I can't seem to get the "textured" part working.  I've checked through my code several times and tried everything I could think of, but it still displays my surfaces as plain white polygons.  I figured that some fresh sets of eyes might be able to see something that I'm missing, so I'm posting the entire source code to my program here (don't worry, it's small.)  It's kinda sparse on comments, so if you need clarification on anything just ask.   #include <SDL/SDL.h>#include <SDL/SDL_image.h>#include <GL/gl.h>#include <stdio.h>#include <stdlib.h>#define SCREEN_WIDTH640#define SCREEN_HEIGHT480int drawScene(int rot, GLuint shiptex);int loadTex(GLuint *shiptex);int init(int screenWidth, int screenHeight, GLuint *shiptex);int main() {int i;int rot;GLuint shiptex;if (!init(SCREEN_WIDTH, SCREEN_HEIGHT, &shiptex)) {return 1;}atexit(SDL_Quit);glMatrixMode(GL_MODELVIEW);for (i=0; i<60; i++) {drawScene(i * 6, shiptex);SDL_Delay(50);}return 0;}int drawScene(int rot, GLuint shiptex) {glLoadIdentity();glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);glTranslatef(0.0,0.0,-2.0);glRotatef(rot,0.0f,1.0f,0.0f);glBindTexture(GL_TEXTURE_2D, shiptex);glBegin(GL_TRIANGLES);/* Bottom */glTexCoord2f(128.0/255.0,120.0/255.0);glVertex3f(0.0, 0.5, -0.2);glTexCoord2f(0.0,1.0);glVertex3f(-0.5,-0.5,-0.2);glTexCoord2f(1.0,1.0);glVertex3f(0.5, -0.5, -0.2);/* Back (two triangles forming a quad) */glTexCoord2f(1.0,120.0/255.0);glVertex3f(0.5,-0.5,-0.2);glTexCoord2f(170.0/255.0,76.0/255.0);glVertex3f(0.2,-0.2,0.2);glTexCoord2f(85.0/255.0, 76.0/255.0);glVertex3f(-0.2,-0.2,0.2);glTexCoord2f(85.0/255.0,76.0/255.0);glVertex3f(-0.2,-0.2,0.2);glTexCoord2f(0.0,120.0/255.0);glVertex3f(-0.5,-0.5,-0.2);glTexCoord2f(1.0,120.0/255.0);glVertex3f(0.5,-0.5,-0.2);/* Right */glTexCoord2f(1.0,120.0/255.0);glVertex3f(0.5,-0.5,-0.2);glTexCoord2f(0.5,0.0);glVertex3f(0.0,0.5,-0.2);glTexCoord2f(170.0/255.0, 76.0/255.0);glVertex3f(0.2,-0.2,0.2);/* Left */glTexCoord2f(1.0,120.0/255.0);glVertex3f(-0.5,-0.5,-0.2);glTexCoord2f(85.0/255.0, 76.0/255.0);glVertex3f(-0.2,-0.2,0.2);glTexCoord2f(170.0/255.0, 76.0/255.0);glVertex3f(0.0,0.5,-0.2);/* Top */glTexCoord2f(0.5,0.0);glVertex3f(0,0.5,-0.2);glTexCoord2f(85.0/255.0,76.0/255.0);glVertex3f(-0.2,-0.2,0.2);glTexCoord2f(170.0/255.0, 76.0/255.0);glVertex3f(0.2,-0.2,0.2);glEnd();glFlush();SDL_GL_SwapBuffers();return 1;}int loadTex(GLuint *shiptex) {SDL_Surface *texture;int returner = 0;if (texture = SDL_LoadBMP("images/texture.bmp")) {glGenTextures( 1, shiptex);glBindTexture(GL_TEXTURE_2D, *shiptex);glTexImage2D( GL_TEXTURE_2D, 0, 3, texture->w,texture->h, 0, GL_BGR,GL_UNSIGNED_BYTE, texture->pixels);returner = 1;}glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);if (texture) {SDL_FreeSurface(texture);}return returner;}int init(int screenWidth, int screenHeight, GLuint *shiptex) {if (!loadTex(shiptex)) {return 0;}if (SDL_Init(SDL_INIT_VIDEO)) {fprintf(stderr, "Error: %s\n", SDL_GetError());return 0;}SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5);SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 6);SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);if (SDL_SetVideoMode(screenWidth, screenHeight, 16, SDL_OPENGL) == NULL) {fprintf(stderr, "Error: %s\n", SDL_GetError());return 0;}SDL_WM_SetCaption("OpenGL test", "OpenGL");glShadeModel(GL_SMOOTH);glClearDepth(1.0);glEnable(GL_DEPTH_TEST);glEnable(GL_TEXTURE_2D);glDepthFunc(GL_LEQUAL);glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);glViewport(0,0,screenWidth, screenHeight);glMatrixMode(GL_PROJECTION);glLoadIdentity();gluPerspective( 45.0f, (float)screenWidth/(float)screenHeight, 0.1f,100.0f );glClearColor(0, 0, 0, 0);return 1;}The "images/texture.bmp" file is a 256*256*256 bitmap, created in The Gimp.  Any help would be greatly appreciated.[edited by - Drooling Iguana on July 30, 2003 7:02:41 PM]
  If you figure this out, can you let me know, cos i am having similar problems and no-one''s spotted anything wrong in my code yet.  -----------------------"Without a sense of humour we couldn''t react to a lot of things" ;  I  have no clue if this will help you or not, but if you try to run the executable from within the compiler, it may not work (didn''t work for me in VC++ or DevC++). Try running it directly from its directory. I know your using Linux, which I''ve never done much programming in personally, but I hope this helps.   -- Joe Teague ;  How about the example from NeHe''s tutorial? Does it work? darkoneRegistered Linux User #317188 ;  Yeah it works....  for me it did...im workin with Dev-C++. Yeah, the horror ;  Yeah, the example from the tutorial worked, and I''ve been looking through both my program and the tutorial, trying to see what he did and I didn''t.  No luck so far, though. ;  As someone earlier sudgessted, you probably have the path to the filename wrong, this would duplicate this problem.  How about running it through the debugger and seeing the contents of the texture, or doing a simple if() type debugging mechanism. ;  It''s loading the texture.  If it wasn''t the program would exit immediately.  It doesn''t exit, it just displays a bunch of plain white polygons. ;  Your texture loading routine expects the file to be in 24-bit color. It won''t work with a 256-color bmp. Try saving your texture as a 24-bit file. ;  Tried that.  It still doesn''t work.  How would I change the type of bitmap that the texture loading routine expects, anyway? 