Advertisement

Problems with Lesson 6

Started by November 08, 2004 08:24 AM
6 comments, last by FireViper 20 years ago
I was trying to compile Lesson 6, (loading textures) in my compiler, DevC++ but got some errors. Can someone look at my source code and tell me how to fix it, or fix it for me. You Can get it form here, http://webvision.xdesignz.com/OpenGLSource.zip thanks,
I am 99% shure of what the problem is so try the links that this links lik to.
Advertisement
There is a reason that people format code nicely with consistent indenting. When I compile your code I get the following errors:
Error E2108 main.cpp 58: Improper use of typedef 'GLvoid' in function LoadGLTextures()Error E2379 main.cpp 58: Statement missing ; in function LoadGLTextures()Error E2451 main.cpp 73: Undefined symbol 'width' in function LoadGLTextures()Error E2451 main.cpp 73: Undefined symbol 'height' in function LoadGLTextures()Error E2190 main.cpp 91: Unexpected }Error E2268 main.cpp 330: Call to undefined function 'ReSizeGLScene' in function CreateGLWindow(char *,int,int,int,bool)Error E2268 main.cpp 398: Call to undefined function 'ReSizeGLScene' in function __stdcall WndProc(HWND__ *,unsigned int,unsigned int,long)

So I jump to line 58 and find:
35 int LoadGLTextures()36 {37      int Status=FALSE;38      AUX_RGBImageRec *TextureImage[1];	// Create Storage Space For The Texture39      memset(TextureImage,0,sizeof(void *)*1); //Clears TextureImage40      // Load The Bitmap, Check For Errors, If Bitmap's Not Found Quit41 	if (TextureImage[0]=LoadBMP("Data/NeHe.bmp"))42 	{Status=TRUE; // Set The Status To TRUE43      glGenTextures(1, &texture[0]);	// Create The Texture44      // Typical Texture Generation Using Data From The Bitmap45 	 glBindTexture(GL_TEXTURE_2D, texture[0]);46      // Generate The Texture47 	 glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);48     	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);	// Linear Filtering49 		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);	// Linear Filtering50 	}51 52 if (TextureImage[0])53 	{54 		if (TextureImage[0]->data){ free(TextureImage[0]->data); }55 		free(TextureImage[0]);56 	}57 58  GLvoid ReSizeGLScene(GLsizei width, GLsizei height)59 {60 	if (height==0)61 	{62 		height=1;63 	}64 	return Status;								// Return The Status65 }666768 	glViewport(0, 0, width, height);					// Reset The Current Viewport69 	glMatrixMode(GL_PROJECTION);						// Select The Projection Matrix70 	glLoadIdentity();							// Reset The Projection Matrix7172 	// Calculate The Aspect Ratio Of The Window73	gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);7475 	glMatrixMode(GL_MODELVIEW);					 	// Select The Modelview Matrix76 	glLoadIdentity();						 	// Reset The Modelview Matrix77 }

If I rewrite that with proper indenting:
35 int LoadGLTextures()36 {37 	int Status=FALSE;38 	AUX_RGBImageRec *TextureImage[1];	// Create Storage Space For The Texture39 	memset(TextureImage,0,sizeof(void *)*1); //Clears TextureImage40 	// Load The Bitmap, Check For Errors, If Bitmap's Not Found Quit41 	if (TextureImage[0]=LoadBMP("Data/NeHe.bmp"))42 	{43 		Status=TRUE; // Set The Status To TRUE44 		glGenTextures(1, &texture[0]);	// Create The Texture45 		// Typical Texture Generation Using Data From The Bitmap46 		glBindTexture(GL_TEXTURE_2D, texture[0]);47 		// Generate The Texture48 		glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);49 		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);	// Linear Filtering50 		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);	// Linear Filtering51 	}52 53 	if (TextureImage[0])54 	{55 		if (TextureImage[0]->data)56 		{57 			free(TextureImage[0]->data);58 		}59 		free(TextureImage[0]);60 	}61 62 	GLvoid ReSizeGLScene(GLsizei width, GLsizei height)63 	{64 		if (height==0)65 		{66 			height=1;67 		}68 		return Status;						 		// Return The Status69 	}70 71 72 	glViewport(0, 0, width, height);					// Reset The Current Viewport73 	glMatrixMode(GL_PROJECTION);						// Select The Projection Matrix74 	glLoadIdentity();							// Reset The Projection Matrix75 76 	// Calculate The Aspect Ratio Of The Window77 	gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);78 79 	glMatrixMode(GL_MODELVIEW);					 	// Select The Modelview Matrix80 	glLoadIdentity();						 	// Reset The Modelview Matrix81 }

The error moves to line 62 and the problem is now clear. You have horibly mixed up the functions ReSizeGLScene and LoadGLTextures. Separate them and the errors are reduced to:
Error E2190 main.cpp 95: Unexpected }

Sort out the indentation again and you'll find the function looks like this:
int InitGL(GLvoid)								// All Setup For OpenGL Goes Here{	// some code}}

So get rid of the additional closing brace and everything should compile fine.
I got the code to compile but the compiler won't create the exe file. I included the following lib files , -lopengl32 -lglu32 -lglut32 but it still don't work. What am I doing wrong?
What error is the compiler/linker giving?

Enigma
This is what says Linker:
undefined reference to `auxDIBImageLoadA@4'
undefined reference to `ChoosePixelFormat@8'
undefined reference to `SetPixelFormat@12'
undefined reference to `SwapBuffers@4'

On your first post you said you were able to fix the probem. Can you mail me to source. My screenname is viperblaze01@yahoo.com
Advertisement
For the first of those see the post that lc_overlord linked to. For the other three try adding -lgdi32 to the linker options.

Enigma
I added -lgdi32 , -lglaux and it worked,

Thanks Enigma

This topic is closed to new replies.

Advertisement