   Enabling textures disables colours
  I've been following NeHe's lessons, not directly copying the code but working the function calls and whatnot into my own (code I wrote based on a sample app and header files :p). Everything was going fine until I got to texture mapping. It worked at first, but after changing a few colours around, all the colours disappeared. Any non-textured surface shows up black.This is the code that loads the texture image:TextureBMP[0] = SDL_LoadBMP("texture.bmp");glGenTextures(1,&Texture[0]); //Generate a textureglBindTexture(GL_TEXTURE_2D,Texture[0]); //Bind itglTexImage2D(GL_TEXTURE_2D, //2D texture0, //Detail level3, //# of data components (red, green & blue) - may be bytes per pixelTextureBMP[0]->w, TextureBMP[0]->h, //Size0, //BorderGL_BGR, //BGR imageGL_UNSIGNED_BYTE, //Data is unsigned bytes (when isn't it?)TextureBMP[0]->pixels); //Where to get the image dataglTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); //Don't filter when shrunk (faster, looks cruddy)glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);//Use linear filtering when stretched (slower, looks better)SDL_FreeSurface(TextureBMP[0]); //Don't need this anymoreglEnable(GL_TEXTURE_2D); //Turn on texturesAnd this draws the shapes:OBJECT* O = Object[Obj];if((!O->Triangle) || (!O->NumTriangles) || (!O->Visible)) return;//printf("Drawing object %d... ",Obj);int i;glLoadIdentity();glTranslatef(O->XPos + Camera->XPos, O->YPos + Camera->YPos, O->ZPos + Camera->ZPos);glRotatef(O->YRot + Camera->YRot, 1.0, 0.0, 0.0); //This works, except that it seems to distort the objects themselvesglRotatef(O->XRot + Camera->XRot, 0.0, 1.0, 0.0);glRotatef(O->ZRot + Camera->ZRot, 0.0, 0.0, 1.0);glScalef(O->XSize,O->YSize,O->ZSize);if(O->Texture >= 0) //Any texture?glBindTexture(GL_TEXTURE_2D, Texture[O->Texture]); //Select the texture we wantglBegin(GL_TRIANGLES);for(i=0;i<O->NumTriangles;i++){//int j;//for(j=0;j<3;j++)//printf("%03d->%d: tx %d/%d, coord %2.2f, %2.2f, col %02X %02X %02X %02X mask %02X %02X %02X %02X\n",i,j,O->Texture,O->Triangle.Textured,O->Triangle.point[j].tx,O->Triangle.point[j].ty,O->Triangle.point[j].col.r,O->Triangle.point[j].col.g,O->Triangle.point[j].col.b,O->Triangle.point[j].col.a,O->RMask,O->GMask,O->BMask,O->AMask);//Draw the triangles manually instead of using DrawTriangle, so we can adjust positions and coloursif((O->Texture >= 0) && (O->Triangle.Textured)) glTexCoord2f(O->Triangle.point[0].tx, O->Triangle.point[0].ty);//else//{glColor4ub(O->Triangle.point[0].col.r & O->RMask,O->Triangle.point[0].col.g & O->GMask,O->Triangle.point[0].col.b & O->BMask,O->Triangle.point[0].col.a & O->AMask);//}glVertex3f((O->Triangle.point[0].pos.x),(O->Triangle.point[0].pos.y),(O->Triangle.point[0].pos.z));if((O->Texture >= 0) && (O->Triangle.Textured)) glTexCoord2f(O->Triangle.point[1].tx, O->Triangle.point[1].ty);//else//{glColor4ub(O->Triangle.point[1].col.r & O->RMask,O->Triangle.point[1].col.g & O->GMask,O->Triangle.point[1].col.b & O->BMask,O->Triangle.point[1].col.a & O->AMask);//}glVertex3f((O->Triangle.point[1].pos.x),(O->Triangle.point[1].pos.y),(O->Triangle.point[1].pos.z));if((O->Texture >= 0) && (O->Triangle.Textured)) glTexCoord2f(O->Triangle.point[2].tx, O->Triangle.point[2].ty);//else//{glColor4ub(O->Triangle.point[2].col.r & O->RMask,O->Triangle.point[2].col.g & O->GMask,O->Triangle.point[2].col.b & O->BMask,O->Triangle.point[2].col.a & O->AMask);//}glVertex3f((O->Triangle.point[2].pos.x),(O->Triangle.point[2].pos.y),(O->Triangle.point[2].pos.z));}glEnd();(OBJECT is a datatype of my own which holds triangle lists, position, scaling, etc for each model. As you may have noticed, I'm using SDL.)It worked at first, but there was some colour oddity (any texture drawn on a non-white surface had all non-white colours converted to black). However, I then changed the image type from GL_RGB to GL_BGR (as I was using BGR images), and since then, I haven't been able to get any colours. I've tried changing it back, verifying that no texture is being applied to the given surface, etc, but everything shows up black. The only way to get things to show in colour is to disable textures entirely (remove the glEnable(GL_TEXTURE_2D) line).PS: I know my camera rotation code is totally stupid. [embarrass]   
  GL_BGR is an extension (GL_BGR_EXT). I wonder why you call it GL_BGR (SDL maybe?) but although it's likely that every card supports it (even Microsoft's generic implementation), you should check it.Manually convert BGR to RGB and then load, to see whether it is the problem.   ;  That's normal behaviour as far as I know. You'll need to diable textures to get normal untextured quads to display correctly.So: enable textures, draw textured surfaces, disable textures, draw untextured surfaces.Concerning the colour blending with textures, check out glTexEnv;  I had it using GL_RGB, but the images were standard Windows BMPs which are BGR, so they looked wrong. I simply changed it to GL_BGR and it worked, but then colours stopped showing up.To toggle textures on and off before drawing a given surface, wouldn't I have to call glBegin before each surface and glEnd afterward? Would that not cause a lot of slowdown?   ;  Not glBegin / End. Before you draw an untetured object, glDisable (GL_TEXTURE_*D). If you don't do this, something like 1 texel of the last bound texture is stretched across your quad. This maybe black, for all you know, and that is what is causing the black surfaces.   ;  Yes, but I can't call glDisable between glBegin and glEnd.Am I wrong in thinking that calling glEnd instructs the GPU to draw all the shapes given to it since glBegin, and thus calling them once per surface would be really inefficient? I'm beginning to think I am. I haven't added an FPS count (in fact, I think I'll do that now), but my program so far consists of one cube circling another, so I don't think it'd show any major difference. It's not exactly a real-world scenario.   ;Quote:Original post by HyperHackerYes, but I can't call glDisable between glBegin and glEnd.Am I wrong in thinking that calling glEnd instructs the GPU to draw all the shapes given to it since glBegin, and thus calling them once per surface would be really inefficient? I'm beginning to think I am. I haven't added an FPS count (in fact, I think I'll do that now), but my program so far consists of one cube circling another, so I don't think it'd show any major difference. It's not exactly a real-world scenario.You should separate your textured objects from your non-textured objects. Call glBegin, draw non-textured objects, call glEnd. Enable texturing, repeat the process for textured polys, and disable texturing. That's basically it.   ;  That's a thought, but I want to be able to have different textures for each surface, plus it would mean going through the objects list twice (once for textured and once for nontextured).I already have to call glEnd after each object to do positioning, scaling and rotation, so I'm wondering if calling it after each surface will cause a major performance hit or not, or if I need to find a totally different method. (Scaling and rotation I can do with some simple math by factoring these values into the vertex coordinates, but it's kinda hacky, and I can't think of any simple way to do this with rotation, at least not one that wouldn't eat up a lot of CPU power.)   ;Quote:Original post by HyperHackerThat's a thought, but I want to be able to have different textures for each surface, plus it would mean going through the objects list twice (once for textured and once for nontextured).I already have to call glEnd after each object to do positioning, scaling and rotation, so I'm wondering if calling it after each surface will cause a major performance hit or not, or if I need to find a totally different method. (Scaling and rotation I can do with some simple math by factoring these values into the vertex coordinates, but it's kinda hacky, and I can't think of any simple way to do this with rotation, at least not one that wouldn't eat up a lot of CPU power.)Look, it's good that you want to keep everything optimized, but don't worry about that bit so much at this stage. Just try and get what you are expecting onscreen. You will learn numerous ways to speed things up later on when you are drawing thousands of polys--display lists, vertex arrays, vertex buffer objects, etc.If you still want to, I suggest using a display list--one for the static cube and one for the spinning cube. And just calling those 2 each frame, using the required transformations in between. And also remember, to bind a new texture, you don't need to disable and enable texturing. If you go with the dlist, it won't matter much that you have to go through the list of objects twice as you will do that only once.   ;  Yeah, suppose I'll do that. I'm the kind who just likes to optimize the hell out of everything even if it's not necessary. :p Seems to be working rather well now, thanks!BTW, in the FAQ it says to disable V-sync in your video options if your frame rate is locked to your refresh rate... is there a certain place I would look for that option, or is it driver-specific? I can't seem to find it anywhere. I may not have a fancy-pants $700 graphic card but I think 2 spinning cubes should be able to render at more than 75FPS!   