   No textures are working in OpenGL with SDL
  When running the NeHe lession 6 using OpenGL with/in the WIN OS API style,the textures are working, but not when I'm using it with SDL.I toke the code from the SDL docs example with OpenGL and tryedit with textures instead for colors.I use the same code for loading the textures.I've tryed everything.I've tryed with glEnable(GL_TEXTURE_2D); but it still doesn't work.Do you know any special reasons that makestextures doesn't work in OpenGL with SDL?I don't have it here, so I can't post the code,I'm at school, I have it in my computer at home.But I will be traveling home tomorrow, so I will post it then.   
  Check out the Linux/SDL version of the tutorial source. Whether you're using Win32 or SDL shouldn't have any impact on whether textures work or not.;  Here's the code for it, it's a bit messy with comments, but I tryed to find the fault myself.// openGL.cpp : Defines the entry point for the application.//#include "stdafx.h"/*int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTRlpCmdLine, int  nCmdShow){ // TODO: Place code here.return 0;}*//* * SDL OpenGL Tutorial. * (c) Michael Vance, 2000 * briareos@lokigames.com * * Distributed under terms of the LGPL.  */#pragma comment(lib, "SDL.lib")#pragma comment(lib, "SDLmain.lib")#pragma comment(lib, "Glaux.lib")#pragma comment(lib, "Glu32.lib")#pragma comment(lib, "Opengl32.lib")#include <SDL/SDL.h>#include <GL/gl.h>#include <GL/glu.h>#include <GL/glaux.h>#include <stdio.h>#include <stdlib.h>/////////////////////*GLuinttexture[1];AUX_RGBImageRec *LoadBMP(char *Filename)// Loads A Bitmap Image{FILE *File=NULL;// File Handleif (!Filename)// Make Sure A Filename Was Given{return NULL;// If Not Return NULL}File=fopen(Filename,"r");// Check To See If The File Existsif (File)// Does The File Exist?{fclose(File);// Close The Handlereturn auxDIBImageLoad(Filename);// Load The Bitmap And Return A Pointer}return NULL;// If Load Failed Return NULL}int LoadGLTextures()// Load Bitmaps And Convert To Textures{int Status=FALSE;// Status IndicatorAUX_RGBImageRec *TextureImage[1];// Create Storage Space For The Texturememset(TextureImage,0,sizeof(void *)*1); // Set The Pointer To NULLglEnable(GL_TEXTURE_2D);// Load The Bitmap, Check For Errors, If Bitmap's Not Found Quitif (TextureImage[0]=LoadBMP("grid.bmp")){Status=TRUE;// Set The Status To TRUEglGenTextures(1, &texture[0]);// Create The Texturefprintf(stdout,"texture ID: %d\n",texture[1]);// Typical Texture Generation Using Data From The BitmapglBindTexture(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 Texture Exists{if (TextureImage[0]->data)// If Texture Image Exists{free(TextureImage[0]->data);// Free The Texture Image Memory}free(TextureImage[0]);// Free The Image Structure}return Status;// Return The Status}*///////////////////////////////////////enum {_texture_0,_texture_1,_texture_2,_texture_3,NUM_TEXTURES};const char *textureFiles[NUM_TEXTURES] ={"floor.bmp""grass.bmp","grid.bmp","water.bmp"};SDL_Surface *textureSurfaces[NUM_TEXTURES];void FreeTextures(void){SDL_Surface *texture;for (int i = 0; i < NUM_TEXTURES; i++){texture = textureSurfaces;if (texture) SDL_FreeSurface(texture);}}GLuint textureIDs[NUM_TEXTURES];GLuint textureID;bool LoadTexture(void){bool success;SDL_Surface *texture;//AUX_RGBImageRec *texture;FILE *pFile = fopen("test.txt","w");glGenTextures(1,&textureID);//fprintf(stdout,"texture ID %d\n",textureID);fprintf(pFile,"texture ID %d\n",textureID);fclose(pFile);for (int i = 0; i < NUM_TEXTURES; i++){texture = SDL_LoadBMP(textureFiles);//texture = auxDIBImageLoad(textureFiles);textureSurfaces = texture;fprintf(stdout,"texture ID %d: %d\n",i,textureIDs);if (texture){//fprintf(stdout,"texture ID %d: %d\n",i,textureIDs);glBindTexture(GL_TEXTURE_2D, textureIDs);glTexImage2D(GL_TEXTURE_2D, 0, 3, texture->w, texture->h, 0, GL_RGB, GL_UNSIGNED_BYTE, texture->pixels);//glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);//fprintf(stdout,"texture pixels: %s\n",texture->pixels);glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);//SDL_FreeSurface(texture);/*glBindTexture(GL_TEXTURE_2D, textureIDs);glTexImage2D(GL_TEXTURE_2D, 0, 3, texture->sizeX, texture->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, texture->data);glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);*/}else{textureSurfaces = NULL;success = false;break;}}return success;}/*bool LoadTextures(void){bool success = true;SDL_Surface *texture;//AUX_RGBImageRec *texture;glGenTextures(NUM_TEXTURES,textureIDs);for (int i = 0; i < NUM_TEXTURES; i++){texture = SDL_LoadBMP(textureFiles);//texture = auxDIBImageLoad(textureFiles);textureSurfaces = texture;fprintf(stdout,"texture ID %d: %d\n",i,textureIDs);if (texture){//fprintf(stdout,"texture ID %d: %d\n",i,textureIDs);glBindTexture(GL_TEXTURE_2D, textureIDs);glTexImage2D(GL_TEXTURE_2D, 0, 3, texture->w, texture->h, 0, GL_RGB, GL_UNSIGNED_BYTE, texture->pixels);//glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);//fprintf(stdout,"texture pixels: %s\n",texture->pixels);glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);//SDL_FreeSurface(texture);/*glBindTexture(GL_TEXTURE_2D, textureIDs);glTexImage2D(GL_TEXTURE_2D, 0, 3, texture->sizeX, texture->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, texture->data);glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);*}else{textureSurfaces = NULL;success = false;break;}}return success;}*/GLboolean should_rotate = GL_TRUE;SDL_Surface *ScreenSurface;void quit_tutorial( int code ){    /** Quit SDL so we can release the fullscreen* mode and restore the previous video settings,* etc.*///FreeTextures();    SDL_Quit( );    /* Exit program. */    exit( code );}void handle_key_down( SDL_keysym* keysym ){    /* * We're only interested if 'Esc' has* been presssed.** EXERCISE: * Handle the arrow keys and have that change the* viewing position/angle.*/    switch( keysym->sym ) {    case SDLK_ESCAPE:   quit_tutorial( 0 );   break;    case SDLK_SPACE:   should_rotate = !should_rotate;   break;    default:   break;    }}void process_events( void ){    /* Our SDL event placeholder. */    SDL_Event event;    /* Grab all the events off the queue. */    while( SDL_PollEvent( &event ) ) {   switch( event.type ) {   case SDL_KEYDOWN:  /* Handle key presses. */  handle_key_down( &event.key.keysym );  break;   case SDL_QUIT:  /* Handle quit requests (like Ctrl-c). */  quit_tutorial( 0 );  break;   }    }}/*glGenTextures(1, &texture[0]);// Create The Texture// Typical Texture Generation Using Data From The BitmapglBindTexture(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);*/void draw_screen( void ){    /* Our angle of rotation. */    float angle = 0.0f;    /** EXERCISE:* Replace this awful mess with vertex* arrays and a call to glDrawElements.** EXERCISE:* After completing the above, change* it to use compiled vertex arrays.** EXERCISE:* Verify my windings are correct here ;).*/    static GLfloat v0[] = { -1.0f, -1.0f,  1.0f };    static GLfloat v1[] = {  1.0f, -1.0f,  1.0f };    static GLfloat v2[] = {  1.0f,  1.0f,  1.0f };    static GLfloat v3[] = { -1.0f,  1.0f,  1.0f };    static GLfloat v4[] = { -1.0f, -1.0f, -1.0f };    static GLfloat v5[] = {  1.0f, -1.0f, -1.0f };    static GLfloat v6[] = {  1.0f,  1.0f, -1.0f };    static GLfloat v7[] = { -1.0f,  1.0f, -1.0f };/*    static GLubyte red[]    = { 255,   0,   0, 255 };    static GLubyte green[]  = {   0, 255,   0, 255 };    static GLubyte blue[]   = {   0,   0, 255, 255 };    static GLubyte white[]  = { 255, 255, 255, 255 };    static GLubyte yellow[] = {   0, 255, 255, 255 };    static GLubyte black[]  = {   0,   0,   0, 255 };    static GLubyte orange[] = { 255, 255,   0, 255 };    static GLubyte purple[] = { 255,   0, 255,   0 };*/static GLubyte red[]    = {255,   0,   0, 255 };    static GLubyte green[]  = { 255, 0,   0, 255 };    static GLubyte blue[]   = { 255,   0, 0, 255 };    static GLubyte white[]  = {255, 0, 0, 255 };    static GLubyte yellow[] = {   0, 255, 255, 255 };    static GLubyte black[]  = {   0,   0,   0, 255 };    static GLubyte orange[] = { 255, 255,   0, 255 };    static GLubyte purple[] = { 255,   0, 255,   0 };    /* Clear the color and depth buffers. */    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );    /* We don't want to modify the projection matrix. */    glMatrixMode( GL_MODELVIEW );    glLoadIdentity( );    /* Move down the z-axis. */    glTranslatef( 0.0, 0.0, -5.0 );    /* Rotate. */    glRotatef( angle, 5.0, 5.0, 5.0 );    if( should_rotate ) {   if( ++angle > 360.0f ) {  angle = 0.0f;   }    }glEnable(GL_TEXTURE_2D);//SDL_FillRect(ScreenSurface,0,0xffffffff);glBindTexture(GL_TEXTURE_2D, textureIDs[0]);glBegin(GL_QUADS);// Front FaceglTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f,  1.0f);glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f,  1.0f);// Back FaceglTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);// Top FaceglTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f,  1.0f,  1.0f);glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f,  1.0f,  1.0f);glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);// Bottom FaceglTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, -1.0f);glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, -1.0f, -1.0f);glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);// Right faceglTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f,  1.0f,  1.0f);glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);// Left FaceglTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f,  1.0f,  1.0f);glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);glEnd();    /* Send our triangle data to the pipeline. *//*    glBegin( GL_TRIANGLES );//glColor3f(1.0f, 0.0f, 0.0f);glTexCoord2f(0.0f, 0.0f);    glVertex3f(0.0f, 0.0f, 0.0f);  //  glColor3f(0.0f, 1.0f, 0.0f);glTexCoord2f(1.0f, 1.0f);    glVertex3f(1.0f, 1.0f, 1.0f);//    glColor3f(0.0f, 0.0f, 1.0f);glTexCoord2f(2.0f, 2.0f);    glVertex3f(1.0f, 0.0f, 1.0f);    glColor4ubv( red );glTexCoord2f(0.0f, 0.0f);    glVertex3fv( v0 );    glColor4ubv( green );glTexCoord2f(0.0f, 0.0f);    glVertex3fv( v1 );    glColor4ubv( blue );glTexCoord2f(0.0f, 0.0f);    glVertex3fv( v2 );    glColor4ubv( red );    glVertex3fv( v0 );    glColor4ubv( blue );    glVertex3fv( v2 );    glColor4ubv( white );    glVertex3fv( v3 );    glColor4ubv( green );    glVertex3fv( v1 );    glColor4ubv( black );    glVertex3fv( v5 );    glColor4ubv( orange );    glVertex3fv( v6 );    glColor4ubv( green );    glVertex3fv( v1 );    glColor4ubv( orange );    glVertex3fv( v6 );    glColor4ubv( blue );    glVertex3fv( v2 );    glColor4ubv( black );    glVertex3fv( v5 );    glColor4ubv( yellow );    glVertex3fv( v4 );    glColor4ubv( purple );    glVertex3fv( v7 );    glColor4ubv( black );    glVertex3fv( v5 );    glColor4ubv( purple );    glVertex3fv( v7 );    glColor4ubv( orange );    glVertex3fv( v6 );    glColor4ubv( yellow );    glVertex3fv( v4 );    glColor4ubv( red );    glVertex3fv( v0 );    glColor4ubv( white );    glVertex3fv( v3 );    glColor4ubv( yellow );    glVertex3fv( v4 );    glColor4ubv( white );    glVertex3fv( v3 );    glColor4ubv( purple );    glVertex3fv( v7 );    glColor4ubv( white );    glVertex3fv( v3 );    glColor4ubv( blue );    glVertex3fv( v2 );    glColor4ubv( orange );    glVertex3fv( v6 );    glColor4ubv( white );    glVertex3fv( v3 );    glColor4ubv( orange );    glVertex3fv( v6 );    glColor4ubv( purple );    glVertex3fv( v7 );    glColor4ubv( green );    glVertex3fv( v1 );    glColor4ubv( red );    glVertex3fv( v0 );    glColor4ubv( yellow );    glVertex3fv( v4 );    glColor4ubv( green );    glVertex3fv( v1 );    glColor4ubv( yellow );    glVertex3fv( v4 );    glColor4ubv( black );    glVertex3fv( v5 );    glEnd( );*/    /** EXERCISE:* Draw text telling the user that 'Spc'* pauses the rotation and 'Esc' quits.* Do it using vetors and textured quads.*/    /** Swap the buffers. This this tells the driver to* render the next frame from the contents of the* back-buffer, and to set all rendering operations* to occur on what was the front-buffer.** Double buffering prevents nasty visual tearing* from the application drawing on areas of the* screen that are being updated at the same time.*/    SDL_GL_SwapBuffers( );}static void setup_opengl( int width, int height ){    float ratio = (float) width / (float) height;    /* Our shading model--Gouraud (smooth). */    glShadeModel( GL_SMOOTH );    /* Culling. */    glCullFace( GL_BACK );    glFrontFace( GL_CCW );    glEnable( GL_CULL_FACE );glEnable( GL_TEXTURE_2D );    /* Set the clear color. */    glClearColor( 0, 0, 0, 0 );    /* Setup our viewport. */    glViewport( 0, 0, width, height );    /** Change to the projection matrix and set* our viewing volume.*/    glMatrixMode( GL_PROJECTION );    glLoadIdentity( );    /** EXERCISE:* Replace this with a call to glFrustum.*/    gluPerspective( 60.0, ratio, 1.0, 1024.0 );}int main( int argc, char* argv[] ){    /* Information about the current video settings. */    const SDL_VideoInfo* info = NULL;    /* Dimensions of our window. */    int width = 0;    int height = 0;    /* Color depth in bits of our window. */    int bpp = 0;    /* Flags we will pass into SDL_SetVideoMode. */    int flags = 0;    /* First, initialize SDL's video subsystem. */    if( SDL_Init( SDL_INIT_VIDEO ) < 0 ) {   /* Failed, exit. */   fprintf( stderr, "Video initialization failed: %s\n",   SDL_GetError( ) );   quit_tutorial( 1 );    }    /* Let's get some video information. */    info = SDL_GetVideoInfo( );    if( !info ) {   /* This should probably never happen. */   fprintf( stderr, "Video query failed: %s\n",   SDL_GetError( ) );   quit_tutorial( 1 );    }    /** Set our width/height to 640/480 (you would* of course let the user decide this in a normal* app). We get the bpp we will request from* the display. On X11, VidMode can't change* resolution, so this is probably being overly* safe. Under Win32, ChangeDisplaySettings* can change the bpp.*/    width = 640;    height = 480;    bpp = info->vfmt->BitsPerPixel;    /** Now, we want to setup our requested* window attributes for our OpenGL window.* We want *at least* 5 bits of red, green* and blue. We also want at least a 16-bit* depth buffer.** The last thing we do is request a double* buffered window. '1' turns on double* buffering, '0' turns it off.** Note that we do not use SDL_DOUBLEBUF in* the flags to SDL_SetVideoMode. That does* not affect the GL attribute state, only* the standard 2D blitting setup.*/    SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 5 );    SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 5 );    SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 5 );    SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 16 );    SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );    /** We want to request that SDL provide us* with an OpenGL window, in a fullscreen* video mode.** EXERCISE:* Make starting windowed an option, and* handle the resize events properly with* glViewport.*/    flags = SDL_OPENGL | SDL_FULLSCREEN;LoadTexture();    /** Set the video mode*/    if((ScreenSurface = SDL_SetVideoMode( width, height, bpp, flags )) == 0 ) {   /** This could happen for a variety of reasons,    * including DISPLAY not being set, the specified    * resolution not being available, etc.    */   fprintf( stderr, "Video mode set failed: %s\n",   SDL_GetError( ) );   quit_tutorial( 1 );    }    /** At this point, we should have a properly setup* double-buffered window for use with OpenGL.*/    setup_opengl( width, height );    /** Now we want to begin our normal app process--* an event loop with a lot of redrawing.*/SDL_Rect dst = {100,100};    while( 1 ) {   /* Process incoming events. */   process_events( );   /* Draw the screen. *///SDL_BlitSurface(textureSurfaces[0],0,ScreenSurface,&dst);draw_screen( );    }    /** EXERCISE:* Record timings using SDL_GetTicks() and* and print out frames per second at program* end.*/    /* Never reached. */    return 0;}glGenTextures() generates 0Something must be missing.Please help!;Quote:Original post by programeringHere's the code for it, it's a bit messy with comments, but I tryed to find the fault myself.*** Source Snippet Removed ***glGenTextures() generates 0Something must be missing.Please help!Try calling loadTextures() after the call to SDL_SetVideoMode.   ;  I googled for "sdl opengl" and found what Dave Hunt mentioned.   ;  I have downloaded the OpenGL tutorials with SDL.I've compiled them and run them and it works :-).   