Sign in to follow this  
CorsairX

Bitmap loading (lesson 6 - but not glaux related)

Recommended Posts

CorsairX    122
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]

Share this post


Link to post
Share on other sites
CorsairX    122
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.

Share this post


Link to post
Share on other sites
eSCHEn    394
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;

//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;
}




Hope that helped :)

Share this post


Link to post
Share on other sites
CorsairX    122
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.

Share this post


Link to post
Share on other sites
eSCHEn    394
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 :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this