Bitmap loading (lesson 6 - but not glaux related)

Started by
3 comments, last by eSCHEn 19 years, 2 months ago
This is a slightly wierd problem and I'm hoping someone can shed some light on this. I've used the code from lesson 6 in one of my test programs and, although I can get it to load the NeHe logo without a problem, I can't load my own bitmaps. The test bitmap that I created is, as near as I can tell, exactly the same format (256x256, 24-bit and 71 dpi) but all I get is a black texture. Could anyone tell me where I'm going wrong? Both the NeHe.bmp and test.bmp in are in a subdirectory ( /res ) and I'm using Visual Studio .Net 2003. My source code is below, and my bitmap can be found here: http://members.iinet.net.au/~corsairx/test.bmp The source code itself can be found: http://members.iinet.net.au/~corsairx/gfx_main.cpp Thanks, Andrew ----------------Start code:

#include <iostream>
#include <GL/glut.h>
#include <GL/glaux.h>

using namespace std;

//Globals
GLuint	texture[1];	
//End Globals

//NeHE code:
AUX_RGBImageRec *LoadBMP(char *Filename)	// Loads A Bitmap Image
{
	FILE *File=NULL;			// File Handle

	if (!Filename)				// Make Sure A Filename Was Given
	{
		return NULL;			// If Not Return NULL
	}

	File=fopen(Filename,"r");		// Check To See If The File Exists

	if (File)				// Does The File Exist?
	{
		fclose(File);			// Close The Handle
		return 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 Indicator

	AUX_RGBImageRec *TextureImage[1];	// Create Storage Space For The Texture

	memset(TextureImage,0,sizeof(void *)*1); // Set The Pointer To NULL

	// Load The Bitmap, Check For Errors, If Bitmap's Not Found Quit
	if (TextureImage[0]=LoadBMP("res/test.bmp"))
	{
		Status=TRUE;			// Set The Status To TRUE

		glGenTextures(1, &texture[0]);	// Create The Texture

		// Typical Texture Generation Using Data From The Bitmap
		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 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
}

void lines(void)
{
	glBegin(GL_LINES);
		// x axis
		glColor3f(1.0, 0.0, 0.0); //red
		glVertex3f(-8.0, 0.0, 0.0);
		glVertex3f(8.0, 0.0, 0.0); 

		// y axis
		glColor3f(0.0, 1.0, 0.0); //green
		glVertex3f(0.0, -8.0, 0.0);
		glVertex3f(0.0, 8.0, 0.0);

		// z axis
		glColor3f(0.0, 0.0, 1.0); //blue
		glVertex3f(0.0, 0.0, -8.0);
		glVertex3f(0.0, 0.0, 8.0);
	glEnd();

}

void box(void)
{
	//NeHE code:

	glBegin(GL_QUADS);
		glColor3f(0.0f,1.0f,0.0f);				// Set The Color To Green
		glVertex3f( 1.0f, 1.0f,-1.0f);			// Top Right Of The Quad (Top)
		glVertex3f(-1.0f, 1.0f,-1.0f);			// Top Left Of The Quad (Top)
		glVertex3f(-1.0f, 1.0f, 1.0f);			// Bottom Left Of The Quad (Top)
		glVertex3f( 1.0f, 1.0f, 1.0f);			// Bottom Right Of The Quad (Top)

		glColor3f(1.0f,0.5f,0.0f);				// Set The Color To Orange
		glVertex3f( 1.0f,-1.0f, 1.0f);			// Top Right Of The Quad (Bottom)
		glVertex3f(-1.0f,-1.0f, 1.0f);			// Top Left Of The Quad (Bottom)
		glVertex3f(-1.0f,-1.0f,-1.0f);			// Bottom Left Of The Quad (Bottom)
		glVertex3f( 1.0f,-1.0f,-1.0f);			// Bottom Right Of The Quad (Bottom)

		glColor3f(1.0f,0.0f,0.0f);				// Set The Color To Red
		glVertex3f( 1.0f, 1.0f, 1.0f);			// Top Right Of The Quad (Front)
		glVertex3f(-1.0f, 1.0f, 1.0f);			// Top Left Of The Quad (Front)
		glVertex3f(-1.0f,-1.0f, 1.0f);			// Bottom Left Of The Quad (Front)
		glVertex3f( 1.0f,-1.0f, 1.0f);			// Bottom Right Of The Quad (Front)

		glColor3f(1.0f,1.0f,0.0f);			// Set The Color To Yellow
		glVertex3f( 1.0f,-1.0f,-1.0f);			// Bottom Left Of The Quad (Back)
		glVertex3f(-1.0f,-1.0f,-1.0f);			// Bottom Right Of The Quad (Back)
		glVertex3f(-1.0f, 1.0f,-1.0f);			// Top Right Of The Quad (Back)
		glVertex3f( 1.0f, 1.0f,-1.0f);			// Top Left Of The Quad (Back)

		glColor3f(0.0f,0.0f,1.0f);			// Set The Color To Blue
		glVertex3f(-1.0f, 1.0f, 1.0f);			// Top Right Of The Quad (Left)
		glVertex3f(-1.0f, 1.0f,-1.0f);			// Top Left Of The Quad (Left)
		glVertex3f(-1.0f,-1.0f,-1.0f);			// Bottom Left Of The Quad (Left)
		glVertex3f(-1.0f,-1.0f, 1.0f);			// Bottom Right Of The Quad (Left)

		glColor3f(1.0f,0.0f,1.0f);			// Set The Color To Violet
		glVertex3f( 1.0f, 1.0f,-1.0f);			// Top Right Of The Quad (Right)
		glVertex3f( 1.0f, 1.0f, 1.0f);			// Top Left Of The Quad (Right)
		glVertex3f( 1.0f,-1.0f, 1.0f);			// Bottom Left Of The Quad (Right)
		glVertex3f( 1.0f,-1.0f,-1.0f);			// Bottom Right Of The Quad (Right)
	glEnd();
}
void texBox(void)
{
	//NeHE code:
	glBegin(GL_QUADS);
		// Front Face
		glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);	// Bottom Left Of The Texture and Quad
		glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);	// Bottom Right Of The Texture and Quad
		glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f,  1.0f);	// Top Right Of The Texture and Quad
		glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f,  1.0f);	// Top Left Of The Texture and Quad

		// Back Face
		glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);	// Bottom Right Of The Texture and Quad
		glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);	// Top Right Of The Texture and Quad
		glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);	// Top Left Of The Texture and Quad
		glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);	// Bottom Left Of The Texture and Quad

		// Top Face
		glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);	// Top Left Of The Texture and Quad
		glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f,  1.0f,  1.0f);	// Bottom Left Of The Texture and Quad
		glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f,  1.0f,  1.0f);	// Bottom Right Of The Texture and Quad
		glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);	// Top Right Of The Texture and Quad

		// Bottom Face
		glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, -1.0f);	// Top Right Of The Texture and Quad
		glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, -1.0f, -1.0f);	// Top Left Of The Texture and Quad
		glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);	// Bottom Left Of The Texture and Quad
		glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);	// Bottom Right Of The Texture and Quad
		
		// Right face
		glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);	// Bottom Right Of The Texture and Quad
		glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);	// Top Right Of The Texture and Quad
		glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f,  1.0f,  1.0f);	// Top Left Of The Texture and Quad
		glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);	// Bottom Left Of The Texture and Quad
		
		// Left Face
		glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);	// Bottom Left Of The Texture and Quad
		glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);	// Bottom Right Of The Texture and Quad
		glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f,  1.0f,  1.0f);	// Top Right Of The Texture and Quad
		glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);	// Top Left Of The Texture and Quad
	glEnd();
}

void init(void)
{
	glClearColor(0.0, 0.0, 0.0, 0.0);

	if (!LoadGLTextures())
	{
		cout << "Load Gl Tex failed" << endl;
	}

	glShadeModel(GL_SMOOTH);
	glEnable(GL_DEPTH_TEST);
	glEnable(GL_COLOR_MATERIAL);
	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);


}
void Display(void)
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glLoadIdentity();

	gluLookAt(-3.0, 1.0, 6.0, 0, 0, 0, 0, 1, 0);
	
	glPushMatrix();
    	lines();
	glPopMatrix();

	glPushMatrix();
		glEnable(GL_TEXTURE_2D);
		glBindTexture(GL_TEXTURE_2D, texture[0]);
		texBox();
		glDisable(GL_TEXTURE_2D);
	glPopMatrix();

	glutSwapBuffers();
}
void Resize(int w, int h)
{
	glMatrixMode(GL_PROJECTION);	//Change to mode that handles the screen projection
	glLoadIdentity();		//Clear the current matrix

	if(h == 0)			//if the screen is zero units h, set it 1
		h = 1;

	glViewport(0, 0, w, h);		//Set how much of the screen the projection should take
	gluPerspective(45, (float)w / (float) h, 1.0, 1000.0); //45 viewable area, in perspective, correct ration, view from 1 unit to a 1000 units

	glMatrixMode(GL_MODELVIEW);		//Go back to the modelview mode
	glLoadIdentity();			//Reset the matrix
}

void Idle(void)
{}

int main (int argc, char** argv)
{
	//Basic glut
	glutInit(&argc, argv);				//Setting window name
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);	//Setting display mode
	glutInitWindowSize(640, 480);			//640 x 480 window
	glutInitWindowPosition(100, 100);
	glutCreateWindow("GfX");

	//Callbacks
	glutIdleFunc(Idle);
	glutReshapeFunc(Resize);
	glutDisplayFunc(Display);

	//Setup starting state
	init();

	glutMainLoop();
	return 0;
}

[Edited by - CorsairX on February 16, 2005 9:14:08 PM]
Advertisement
I've done a little more experimenting and its actually a different problem. It is displaying the texture, but it's only displaying it in shades of blue.

So I think it's something to do with the way the colour setup.
The problem lies in the fact that OpenGL is a state machine, that is to say that whatever value/variable you set will stay the same until you change it again. If you look at your display function you will see that you call 'lines' before you draw your textured box, the last colour call in the 'lines' function sets the colour to blue and therefore your box is blue also. To fix this simply call glColor before you render the box and set it to white.

As a side note, the code you posted is quite difficult to read, next time insert {source} and {/source} around it (changing the curly braces to square ones) and you will get a nice formatted box, thus:

#include <iostream>#include <GL/glut.h>#include <GL/glaux.h>using namespace std;//GlobalsGLuint texture[1];//End Globals//NeHE code: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 NULL// Load The Bitmap, Check For Errors, If Bitmap's Not Found Quitif (TextureImage[0]=LoadBMP("res/test.bmp")){Status=TRUE; // Set The Status To TRUEglGenTextures(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);}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}void lines(void){glBegin(GL_LINES);// x axisglColor3f(1.0, 0.0, 0.0); //redglVertex3f(-8.0, 0.0, 0.0);glVertex3f(8.0, 0.0, 0.0);// y axisglColor3f(0.0, 1.0, 0.0); //greenglVertex3f(0.0, -8.0, 0.0);glVertex3f(0.0, 8.0, 0.0);// z axisglColor3f(0.0, 0.0, 1.0); //blueglVertex3f(0.0, 0.0, -8.0);glVertex3f(0.0, 0.0, 8.0);glEnd();}void box(void){//NeHE code:glBegin(GL_QUADS);glColor3f(0.0f,1.0f,0.0f); // Set The Color To GreenglVertex3f( 1.0f, 1.0f,-1.0f); // Top Right Of The Quad (Top)glVertex3f(-1.0f, 1.0f,-1.0f); // Top Left Of The Quad (Top)glVertex3f(-1.0f, 1.0f, 1.0f); // Bottom Left Of The Quad (Top)glVertex3f( 1.0f, 1.0f, 1.0f); // Bottom Right Of The Quad (Top)glColor3f(1.0f,0.5f,0.0f); // Set The Color To OrangeglVertex3f( 1.0f,-1.0f, 1.0f); // Top Right Of The Quad (Bottom)glVertex3f(-1.0f,-1.0f, 1.0f); // Top Left Of The Quad (Bottom)glVertex3f(-1.0f,-1.0f,-1.0f); // Bottom Left Of The Quad (Bottom)glVertex3f( 1.0f,-1.0f,-1.0f); // Bottom Right Of The Quad (Bottom)glColor3f(1.0f,0.0f,0.0f); // Set The Color To RedglVertex3f( 1.0f, 1.0f, 1.0f); // Top Right Of The Quad (Front)glVertex3f(-1.0f, 1.0f, 1.0f); // Top Left Of The Quad (Front)glVertex3f(-1.0f,-1.0f, 1.0f); // Bottom Left Of The Quad (Front)glVertex3f( 1.0f,-1.0f, 1.0f); // Bottom Right Of The Quad (Front)glColor3f(1.0f,1.0f,0.0f); // Set The Color To YellowglVertex3f( 1.0f,-1.0f,-1.0f); // Bottom Left Of The Quad (Back)glVertex3f(-1.0f,-1.0f,-1.0f); // Bottom Right Of The Quad (Back)glVertex3f(-1.0f, 1.0f,-1.0f); // Top Right Of The Quad (Back)glVertex3f( 1.0f, 1.0f,-1.0f); // Top Left Of The Quad (Back)glColor3f(0.0f,0.0f,1.0f); // Set The Color To BlueglVertex3f(-1.0f, 1.0f, 1.0f); // Top Right Of The Quad (Left)glVertex3f(-1.0f, 1.0f,-1.0f); // Top Left Of The Quad (Left)glVertex3f(-1.0f,-1.0f,-1.0f); // Bottom Left Of The Quad (Left)glVertex3f(-1.0f,-1.0f, 1.0f); // Bottom Right Of The Quad (Left)glColor3f(1.0f,0.0f,1.0f); // Set The Color To VioletglVertex3f( 1.0f, 1.0f,-1.0f); // Top Right Of The Quad (Right)glVertex3f( 1.0f, 1.0f, 1.0f); // Top Left Of The Quad (Right)glVertex3f( 1.0f,-1.0f, 1.0f); // Bottom Left Of The Quad (Right)glVertex3f( 1.0f,-1.0f,-1.0f); // Bottom Right Of The Quad (Right)glEnd();}void texBox(void){//NeHE code:glBegin(GL_QUADS);// Front FaceglTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); // Bottom Left Of The Texture and QuadglTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f); // Bottom Right Of The Texture and QuadglTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f); // Top Right Of The Texture and QuadglTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f); // Top Left Of The Texture and Quad// Back FaceglTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f); // Bottom Right Of The Texture and QuadglTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); // Top Right Of The Texture and QuadglTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f); // Top Left Of The Texture and QuadglTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f); // Bottom Left Of The Texture and Quad// Top FaceglTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); // Top Left Of The Texture and QuadglTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, 1.0f, 1.0f); // Bottom Left Of The Texture and QuadglTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, 1.0f, 1.0f); // Bottom Right Of The Texture and QuadglTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f); // Top Right Of The Texture and Quad// Bottom FaceglTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, -1.0f); // Top Right Of The Texture and QuadglTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, -1.0f, -1.0f); // Top Left Of The Texture and QuadglTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f); // Bottom Left Of The Texture and QuadglTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); // Bottom Right Of The Texture and Quad// Right faceglTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f); // Bottom Right Of The Texture and QuadglTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, -1.0f); // Top Right Of The Texture and QuadglTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f); // Top Left Of The Texture and QuadglTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, 1.0f); // Bottom Left Of The Texture and Quad// Left FaceglTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f); // Bottom Left Of The Texture and QuadglTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); // Bottom Right Of The Texture and QuadglTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f); // Top Right Of The Texture and QuadglTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); // Top Left Of The Texture and QuadglEnd();}void init(void){glClearColor(0.0, 0.0, 0.0, 0.0);if (!LoadGLTextures()){cout << "Load Gl Tex failed" << endl;}glShadeModel(GL_SMOOTH);glEnable(GL_DEPTH_TEST);glEnable(GL_COLOR_MATERIAL);glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);}void Display(void){glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);glLoadIdentity();gluLookAt(-3.0, 1.0, 6.0, 0, 0, 0, 0, 1, 0);glPushMatrix();lines();glPopMatrix();glPushMatrix();glEnable(GL_TEXTURE_2D);glBindTexture(GL_TEXTURE_2D, texture[0]);texBox();glDisable(GL_TEXTURE_2D);glPopMatrix();glutSwapBuffers();}void Resize(int w, int h){glMatrixMode(GL_PROJECTION); //Change to mode that handles the screen projectionglLoadIdentity(); //Clear the current matrixif(h == 0) //if the screen is zero units h, set it 1h = 1;glViewport(0, 0, w, h); //Set how much of the screen the projection should takegluPerspective(45, (float)w / (float) h, 1.0, 1000.0); //45 viewable area, in perspective, correct ration, view from 1 unit to a 1000 unitsglMatrixMode(GL_MODELVIEW); //Go back to the modelview modeglLoadIdentity(); //Reset the matrix}void Idle(void){}int main (int argc, char** argv){//Basic glutglutInit(&argc, argv); //Setting window nameglutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB); //Setting display modeglutInitWindowSize(640, 480); //640 x 480 windowglutInitWindowPosition(100, 100);glutCreateWindow("GfX");//CallbacksglutIdleFunc(Idle);glutReshapeFunc(Resize);glutDisplayFunc(Display);//Setup starting stateinit();glutMainLoop();return 0;}


Hope that helped :)
--
Cheers,
Darren Clark
Thanks much, that was the problem - I got a little confused on what exactly glPopMatrix was doing. (Its a bit embarassing actually, I should have figured that out... ah well, my excuse is thats its been 6 months since I last touched OpenGL :) )

I fixed the first post too.
They [glPushMatrix() and glPopMatrix()] store the currently selected matrix on a stack, in the case of your program they store the modelview matrix as it is the last matrix called before you use them. You can use them to store and reset a matrix, thereby saving and restoring a default 'clean' matrix. One thing to watch is the depth of the stack, it varies from graphics card to graphics card but is guaranteed to be at least 32 for the modelview matrix and at least 2 for the texture and projection matrices.

Happy coding :)
--
Cheers,
Darren Clark

This topic is closed to new replies.

Advertisement