undefined reference to help

undefined reference to

Page 1 of 1

3 Replies - 8992 Views - Last Post: 05 January 2010 - 03:55 PM Rate Topic: -----

#1 2ded12  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 23-November 09

undefined reference to help

Posted 04 January 2010 - 03:36 PM

I need help with my code:
#define GL_CLAMP_TO_EDGE 0x812F
#define GL_BGR		   0x813F
#define GL_BGRA		  0x814F
#include <windows.h>
#include <gl/gl.h>
#include <gl/glu.h>
#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include "MAIN.h"
#include "stgatexture.h"
#include "imageloader.h"
using namespace std;
namespace m_whiteViewPos{
		  int x;
		  int y;
		  int z;		 
}
namespace m_blackViewPos{
		  int x;
		  int y;
		  int z;
}
bool STGATexture::loadTGA(const char *filename, STGA& tgaFile)
{
	 FILE *file;
	 unsigned char type[4];
	 unsigned char info[6];
	 {
			 file = fopen(filename, "rb");

			 if (!file)
			 return false;
	}
	fread (&type, sizeof (char), 3, file);
	fseek (file, 12, SEEK_SET);
	fread (&info, sizeof (char), 6, file);
	//image type either 2 (color) or 3 (greyscale)
	if (type[1] != 0 || (type[2] != 2 && type[2] != 3))
	{
		fclose(file);
		return false;
	}
	tgaFile.width = info[0] + info[1] * 256;
	tgaFile.height = info[2] + info[3] * 256;
	tgaFile.byteCount = info[4] / 8;

	if (tgaFile.byteCount != 3 && tgaFile.byteCount != 4) {
		fclose(file);
		return false;
	}
	long imageSize = tgaFile.width * tgaFile.height * tgaFile.width * tgaFile.byteCount;
	//allocate memory for image data
	tgaFile.data = new unsigned char[imageSize];
	//read in image data
	fread(tgaFile.data, sizeof(unsigned char), imageSize, file);
	//close file
	fclose(file);
	return true;
}

STGATexture::STGATexture()
{
	texture = 0;
}

STGATexture::~STGATexture()
{
	destroy();
}


bool STGATexture::createTexture(const char *filename, int minFilter, int magFilter,
				   bool clampToEdge)
{
		
   STGA tgaFile;

 	destroy();

	if (loadTGA(filename,tgaFile))
	{
		glPixelStorei(GL_UNPACK_ALIGNMENT,1);

		glGenTextures(1,&texture);
		glBindTexture(GL_TEXTURE_2D,texture);

		if (clampToEdge)
		{
			glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE);
			glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE);
		} else {
			glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
			glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
		}

		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,minFilter);
		glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,magFilter);
		glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

		   	glTexImage2D(GL_TEXTURE_2D,0,tgaFile.byteCount,tgaFile.width,
				 tgaFile.width,0,(tgaFile.byteCount == 3 ? GL_BGR : GL_BGRA),
			GL_UNSIGNED_BYTE,tgaFile.data);

		return true;
	}

	return false;
}

bool STGATexture::createMipmap(const char *filename, int minFilter, int magFilter,
				   bool clampToEdge)
{
		STGA tgaFile;

		 destroy();

		if (loadTGA(filename,tgaFile))
		{
						glPixelStorei(GL_UNPACK_ALIGNMENT,1);

						glGenTextures(1,&texture);
						glBindTexture(GL_TEXTURE_2D,texture);

						if (clampToEdge)
						{
										glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE);
										glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE);
						} 
						else 
						{
							 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
							 glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
						}
						glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,minFilter);
						glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,magFilter);
						glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

						gluBuild2DMipmaps(GL_TEXTURE_2D,tgaFile.byteCount,tgaFile.width, tgaFile.height,(tgaFile.byteCount == 3 ? GL_BGR : GL_BGRA), GL_UNSIGNED_BYTE,tgaFile.data);			
			
			return true;
	}
   
	return false;
}

GLuint STGATexture::getGLTexture()
{
	return texture;
}

void STGATexture::select()
{
	glBindTexture(GL_TEXTURE_2D,texture);
}

void STGATexture::destroy()
{
	if (texture)
	{
		glDeleteTextures(1,&texture);
		texture = 0;
		}
}
void CGfxOpenGL::CHi()
{
			glClearColor (0.0f, 0.0f, 0.0f, 0.0f);
			glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
			glLoadIdentity();	   

			BYTE* data;
			FILE* file;
			STGA tgaFile;
			STGA loadTGA;
			CTextuMgr releaseTexture;
			CTextuMgr glStencil0p;
			
			file = fopen(filename, "textures.dat");
			if (file == NULL) return;
			
			width = 256;
			height = 256;
			data = (BYTE*)malloc( width * height * 3 );
			
			_model = MD2Model::load("that_model.md2");
			if (_model != NULL) {
			_model->setAnimation(wrap);
		   
		 
			fread(data, width * height * 3, 1, file);
			fclose(file);
			glGenTextures( 1, &texture );
			glBindTexture( GL_TEXTURE_2D, texture );
			glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
			glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST );
  
			glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
			
			glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap ? GL_REPEAT : GL_CLAMP );
			glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap ? GL_REPEAT : GL_CLAMP );
			gluBuild2DMipmaps(GL_TEXTURE_2D,tgaFile.byteCount,tgaFile.width, tgaFile.height,(tgaFile.byteCount == 3 ? GL_BGR : GL_BGRA), GL_UNSIGNED_BYTE,tgaFile.data);
			
			free( data );


			glEnable(GL_TEXTURE_2D);		  
			m_whiteViewPos == CVector(x, y, z);
			m_blackViewPos == CVector(x, y, z);
			m_currentView == WHITE;

			releaseTexture;
						
			glDetelelist*(m_panlesDL, 1);
			
			return;
			
			if(m_currentView == WHITE){
							  gluLookAt(m_whiteViewPos::x, m_whiteViewPos::y,
							  m_whiteViewPos::z, 4.0, 0.0, 4.0, 0.0, 1.0, 0.0);
			}
			else
			{
				gluLookAt(m_blackViewPos::x, m_blackViewPos::y,
				m_blackViewPos::z, 4.0, 0.0, 4.0, 0.0, 1.0, 0.0);
			}
			glDisable(GL_DEPTH_TEST);
			RenderTable();
			glEnable(GL_DEPTH_TEST);
			glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
			glDepthMask(GL_FALSE);
			
			glEnable(GL_STENCIL_TEST);
			glStencilFunc(GL_ALWAYS, 1, 0xFFFFFFF);
			glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
			RenderChessBoard();
			
			glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
			glDepthMask(GL_TRUE);	
			glStencilFunc(GL_EQUAL, 1, 0xFFFFFFF);
			glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
			
			glPushMatrix();
				glScalef(1.0, -1.0, 1.0);
				RenderPieces();
			glPopMatrix();
			
			glEnable(GL_BLEND);
				RenderSelections();
				glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_DST_ALPHA);
				RenderChessBoard();
			glDisable(GL_BLEND);
			
			glDisable(GL_STENCIL_TEST);
			
			int glColoer3f;
			glPushMatrix();
				glColor3f(1.0, 1.0, 1.0);
				RenderPieces();
			glPopMatrix();
			glEnd ();
	
			SwapBuffers (hDC);

			theta += 1.0f;
			Sleep (1);
		}
		return;	
}

void EnableOpenGL (HWND hWnd, HDC *hDC, HGLRC *hRC)
{
	PIXELFORMATDESCRIPTOR pfd;
	int iFormat;

	/* get the device context (DC) */
	*hDC = GetDC (hWnd);

	/* set the pixel format for the DC */
	ZeroMemory (&pfd, sizeof (pfd));
	pfd.nSize = sizeof (pfd);
	pfd.nVersion = 1;
	pfd.dwFlags = PFD_DRAW_TO_WINDOW | 
	  PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
	pfd.iPixelType = PFD_TYPE_RGBA;
	pfd.cColorBits = 24;
	pfd.cDepthBits = 16;
	pfd.iLayerType = PFD_MAIN_PLANE;
	iFormat = ChoosePixelFormat (*hDC, &pfd);
	SetPixelFormat (*hDC, iFormat, &pfd);

	/* create and enable the render context (RC) */
	*hRC = wglCreateContext( *hDC );
	wglMakeCurrent( *hDC, *hRC );

}

				  
void DisableOpenGL (HWND hWnd, HDC hDC, HGLRC hRC)
{
	wglMakeCurrent (NULL, NULL);
	wglDeleteContext (hRC);
	ReleaseDC (hWnd, hDC);
}

I keep geting this
Compiler: Default compiler
Building Makefile: "L:\Makefile.win"
Executing  make...
make.exe -f "L:\Makefile.win" all
g++.exe hi.o md2model.o imageloader.o vec3f.o windoes.o  -o "game.exe" -L"C:/Dev-Cpp/lib" -L"C:/Dev-Cpp/dreamcast" -L"C:/Dev-Cpp/lib/gcc" -mwindows -lopengl32 

hi.o(.text+0x7f4):hi.cpp: undefined reference to `[email protected]'
hi.o(.text+0xbff):hi.cpp: undefined reference to `[email protected]'
hi.o(.text+0xc45):hi.cpp: undefined reference to `CGfxOpenGL::CVector(float, float, float)'
hi.o(.text+0xc6e):hi.cpp: undefined reference to `CGfxOpenGL::CVector(float, float, float)'
windoes.o(.text+0x1d8):windoes.cpp: undefined reference to `SetupPixelFormat(HDC__*)'
collect2: ld returned 1 exit status

make.exe: *** [game.exe] Error 1

Execution terminated

please help

Is This A Good Question/Topic? 0
  • +

Replies To: undefined reference to help

#2 Paul-  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 61
  • View blog
  • Posts: 260
  • Joined: 11-December 09

Re: undefined reference to help

Posted 04 January 2010 - 04:39 PM

This is a linking problem. The undefined reference to [email protected] indicates that the linker cannot find the glu library. How to solve this depends on your particular development environment. The command below
g++.exe hi.o md2model.o imageloader.o vec3f.o windoes.o  -o "game.exe" -L"C:/Dev-Cpp/lib" -L"C:/Dev-Cpp/dreamcast" -L"C:/Dev-Cpp/lib/gcc" -mwindows -lopengl32 

should have the glu library specified. For example, if the library file is "C:\Windows\System32\glu32.dll", the command should include the file path given as
-L"C:/Windows/System32"
and the library name as
-lglu32
.
Was This Post Helpful? 0
  • +
  • -

#3 2ded12  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 23-November 09

Re: undefined reference to help

Posted 05 January 2010 - 03:41 PM

thanks but now it saying "
L:\Makefile.win [Build Error]  [game.exe] Error 1
"please help.

This post has been edited by 2ded12: 05 January 2010 - 03:48 PM

Was This Post Helpful? 0
  • +
  • -

#4 Paul-  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 61
  • View blog
  • Posts: 260
  • Joined: 11-December 09

Re: undefined reference to help

Posted 05 January 2010 - 03:55 PM

View Post2ded12, on 5 Jan, 2010 - 02:41 PM, said:

thanks but now it saying "
L:\Makefile.win [Build Error]  [game.exe] Error 1
"please help.


Hm, this is rather cryptic. Is there more to the error message? What development environment are you using? Can you look at the L:\Makefile.win file to see the line where the error happens?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1