OpenGL, Glew, FreeGlut, Mesa under windows 7

Help is really appreciated.

Using software:
Netbeans 7.2.1
Mingw , and it’s console

My settings:

I tried some of the online tutorials, but I still get errors like:
cannot find -iGL
cannot find freeglut.h

My questions:

  • What are the settings for Netbeans?
  • what is the way to compile openGL programs?
  • if possible : Is there a complete install tutorial for openGL,glew and freeglut, Mesa?

I have been trying for 2 days, nothing works. I only succeeded compiling it under Linux with the console. Netbeans does not compile.

I added this to my windows PATH: D:\freeglut-MinGW-2.8.0-1.ming package\include\GL

In the GL directory there ar the files:
freeglut.h
freeglut_ext.h
freeglut_std.h
glut.h

Anything else I can do? Or if there is a pdf book for sale that tells whow to do it step by step, that’s great.

I downloaded freeglut for Mingw,created D:\freeglut
copied freeglut folders include and lib to D:\freeglut

Copied freeglut.dll to :
C:\Windows\SysWOW64
C:\Windows\System32

Freeglut tells me to use in my program the one of following includes:
#include <GL/freeglut.h>
#include <GL/glut.h>

That means I have to change my windows PATH to:
D:\freeglut-MinGW-2.8.0-1.ming package\include

It tells me to compile my program (using mingW shell underwindows) with one of the following:

gcc -c -o test.o test.c -I"C:\Program Files\Common Files\MinGW\freeglut\include"
gcc -o test.exe test.o -L"C:\Program Files\Common Files\MinGW\freeglut\lib" -lfreeglut -lopengl32 -Wl,–subsystem,windows

I have to change the directory structure to:
$ g++ -o test.exe test.cpp -L"d:\freeglut\lib" -lfreeglut -lopengl32 -Wl,–subsystem,windows
$ gcc -o test.exe test.cpp -L"d:\freeglut\lib" -lfreeglut -lopengl32 -Wl,–subsystem,windows

But it cannot find freeglut.h

Found solution!

First, don’t use MinGW shell, don’t know if it’s possible to compile under the linux emulator kinda thing…
Soltion: make sure windows command prompt can find you g++ or gcc executable
if you installed minGW at c:\mingw, then add PATH to windows : c:\minGW\bin
Because in the bin directory is the compile program g++ and gcc.

Secondly:
with help of several forum posts I was able to compile successfully:

  1. www.transmissionzero.co.uk/computing/using-glut-with-mingw/
  2. www.gamedev.net/topic/320170-gluperspective--undefined-reference/

First website gave me the overal syntax, but I was missing a few switches. You have to specify where the library is with the -L switch.
And you need to specify where your header files are located, with the -I switch.
Lastly you need to add a third switch otherwise it will say undefined reference to gluperspective@32, solution for last is to add the switch -lglu32

Compiling a program with the command prompt has succeeded. Now I tried the C / C++ IDE called Codeblocks.
It has a complete package, which includes, Codeblocks + MingW. On top of that, it is supplied with OpenGL and Glut project categories.
Compiling works like a charm with basic opengl and Glut programs.

But I m stuck with the following source, which is from the OpenGL Superbible version 4.


// Block.cpp
// OpenGL SuperBible, Chapter 1
// Demonstrates an assortment of basic 3D concepts
// Program by Richard S. Wright Jr.

#include "GL/gltools.h"
#include "GL/math3d.h"
#include <math.h>

// Keep track of effects step
int nStep = 0;


// Lighting data
GLfloat lightAmbient[] = { 0.2f, 0.2f, 0.2f, 1.0f };
GLfloat lightDiffuse[] = { 0.7f, 0.7f, 0.7f, 1.0f };
GLfloat lightSpecular[] = { 0.9f, 0.9f, 0.9f };
GLfloat materialColor[] = { 0.8f, 0.0f, 0.0f };
GLfloat vLightPos[] = { -80.0f, 120.0f, 100.0f, 0.0f };
GLfloat ground[3][3] = { { 0.0f, -25.0f, 0.0f },
                        { 10.0f, -25.0f, 0.0f },
                        { 10.0f, -25.0f, -10.0f } };

GLuint textures[4];





// Called to draw scene
void RenderScene(void)
	{
	M3DMatrix44f mCubeTransform;
	M3DVector4f pPlane;


	// Clear the window with current clearing color
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glShadeModel(GL_SMOOTH);
	glEnable(GL_NORMALIZE);

	glPushMatrix();

	// Draw plane that the cube rests on
	glDisable(GL_LIGHTING);
	if(nStep == 5)
		{
		glColor3ub(255,255,255);
		glEnable(GL_TEXTURE_2D);
		glBindTexture(GL_TEXTURE_2D, textures[0]);
		glBegin(GL_QUADS);
			glTexCoord2f(0.0f, 0.0f);
			glVertex3f(-100.0f, -25.3f, -100.0f);
			glTexCoord2f(0.0f, 1.0f);
			glVertex3f(-100.0f, -25.3f, 100.0f);
			glTexCoord2f(1.0f, 1.0f);
			glVertex3f(100.0f,  -25.3f, 100.0f);
			glTexCoord2f(1.0f, 0.0f);
			glVertex3f(100.0f,  -25.3f, -100.0f);
		glEnd();
		}
	else
		{
		glColor3f(0.0f, 0.0f, 0.90f); // Blue
		glBegin(GL_QUADS);
			glVertex3f(-100.0f, -25.3f, -100.0f);
			glVertex3f(-100.0f, -25.3f, 100.0f);
			glVertex3f(100.0f,  -25.3f, 100.0f);
			glVertex3f(100.0f,  -25.3f, -100.0f);
		glEnd();
		}


	// Set drawing color to Red
	glColor3f(1.0f, 0.0f, 0.0f);

	// Enable, disable lighting
	if(nStep > 2)
		{
		glEnable(GL_DEPTH_TEST);
		glDepthFunc(GL_LEQUAL);
		glEnable(GL_COLOR_MATERIAL);

		glLightfv(GL_LIGHT0, GL_AMBIENT, lightAmbient);
		glLightfv(GL_LIGHT0, GL_DIFFUSE, lightDiffuse);
		glLightfv(GL_LIGHT0, GL_SPECULAR, lightSpecular);
		glEnable(GL_LIGHTING);
		glEnable(GL_LIGHT0);
		glMaterialfv(GL_FRONT, GL_SPECULAR,lightSpecular);
		glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, materialColor);
		glMateriali(GL_FRONT, GL_SHININESS,128);
		}

	// Move the cube slightly forward and to the left
	glTranslatef(-10.0f, 0.0f, 10.0f);

	switch(nStep)
		{
		// Just draw the wire framed cube
		case 0:
			glutWireCube(50.0f);
			break;

		// Same wire cube with hidden line removal simulated
		case 1:
			// Front Face (before rotation)
			glBegin(GL_LINES);
				glVertex3f(25.0f,25.0f,25.0f);
				glVertex3f(25.0f,-25.0f,25.0f);

				glVertex3f(25.0f,-25.0f,25.0f);
				glVertex3f(-25.0f,-25.0f,25.0f);

				glVertex3f(-25.0f,-25.0f,25.0f);
				glVertex3f(-25.0f,25.0f,25.0f);

				glVertex3f(-25.0f,25.0f,25.0f);
				glVertex3f(25.0f,25.0f,25.0f);
			glEnd();

			// Top of cube
			glBegin(GL_LINES);
				// Front Face
				glVertex3f(25.0f,25.0f,25.0f);
				glVertex3f(25.0f,25.0f,-25.0f);

				glVertex3f(25.0f,25.0f,-25.0f);
				glVertex3f(-25.0f,25.0f,-25.0f);

				glVertex3f(-25.0f,25.0f,-25.0f);
				glVertex3f(-25.0f,25.0f,25.0f);

				glVertex3f(-25.0f,25.0f,25.0f);
				glVertex3f(25.0f,25.0f,25.0f);
			glEnd();

			// Last two segments for effect
			glBegin(GL_LINES);
				glVertex3f(25.0f,25.0f,-25.0f);
				glVertex3f(25.0f,-25.0f,-25.0f);

				glVertex3f(25.0f,-25.0f,-25.0f);
				glVertex3f(25.0f,-25.0f,25.0f);
			glEnd();

			break;

		// Uniform colored surface, looks 2D and goofey
		case 2:
			glutSolidCube(50.0f);
			break;

		case 3:
			glutSolidCube(50.0f);
			break;

		// Draw a shadow with some lighting
		case 4:
			glGetFloatv(GL_MODELVIEW_MATRIX, mCubeTransform);
			glutSolidCube(50.0f);
			glPopMatrix();

			// Disable lighting, we'll just draw the shadow as black
			glDisable(GL_LIGHTING);

			glPushMatrix();

			m3dGetPlaneEquation(pPlane, ground[0], ground[1], ground[2]);
			m3dMakePlanarShadowMatrix(mCubeTransform, pPlane, vLightPos);
			//MakeShadowMatrix(ground, lightpos, cubeXform);
			glMultMatrixf(mCubeTransform);

			glTranslatef(-10.0f, 0.0f, 10.0f);

			// Set drawing color to Black
			glColor3f(0.0f, 0.0f, 0.0f);

			glutSolidCube(50.0f);
			break;

		case 5:
			glColor3ub(255,255,255);
			glGetFloatv(GL_MODELVIEW_MATRIX, mCubeTransform);

			// Front Face (before rotation)
			glBindTexture(GL_TEXTURE_2D, textures[1]);
			glBegin(GL_QUADS);
				glTexCoord2f(1.0f, 1.0f);
				glVertex3f(25.0f,25.0f,25.0f);
				glTexCoord2f(1.0f, 0.0f);
				glVertex3f(25.0f,-25.0f,25.0f);
				glTexCoord2f(0.0f, 0.0f);
				glVertex3f(-25.0f,-25.0f,25.0f);
				glTexCoord2f(0.0f, 1.0f);
				glVertex3f(-25.0f,25.0f,25.0f);
			glEnd();

			// Top of cube
			glBindTexture(GL_TEXTURE_2D, textures[2]);
			glBegin(GL_QUADS);
				// Front Face
				glTexCoord2f(0.0f, 0.0f);
				glVertex3f(25.0f,25.0f,25.0f);
				glTexCoord2f(1.0f, 0.0f);
				glVertex3f(25.0f,25.0f,-25.0f);
				glTexCoord2f(1.0f, 1.0f);
				glVertex3f(-25.0f,25.0f,-25.0f);
				glTexCoord2f(0.0f, 1.0f);
				glVertex3f(-25.0f,25.0f,25.0f);
			glEnd();

			// Last two segments for effect
			glBindTexture(GL_TEXTURE_2D, textures[3]);
			glBegin(GL_QUADS);
				glTexCoord2f(1.0f, 1.0f);
				glVertex3f(25.0f,25.0f,-25.0f);
				glTexCoord2f(1.0f, 0.0f);
				glVertex3f(25.0f,-25.0f,-25.0f);
				glTexCoord2f(0.0f, 0.0f);
				glVertex3f(25.0f,-25.0f,25.0f);
				glTexCoord2f(0.0f, 1.0f);
				glVertex3f(25.0f,25.0f,25.0f);
			glEnd();


			glPopMatrix();

			// Disable lighting, we'll just draw the shadow as black
			glDisable(GL_LIGHTING);
			glDisable(GL_TEXTURE_2D);

			glPushMatrix();

			m3dGetPlaneEquation(pPlane, ground[0], ground[1], ground[2]);
			m3dMakePlanarShadowMatrix(mCubeTransform, pPlane, vLightPos);
			glMultMatrixf(mCubeTransform);

			glTranslatef(-10.0f, 0.0f, 10.0f);

			// Set drawing color to Black
			glColor3f(0.0f, 0.0f, 0.0f);
			glutSolidCube(50.0f);
			break;

		}

	glPopMatrix();

	// Flush drawing commands
	glutSwapBuffers();
	}

// This function does any needed initialization on the rendering
// context.
void SetupRC()
	{
        GLbyte *pBytes;
        GLint nWidth, nHeight, nComponents;
        GLenum format;

	// Black background
	glClearColor(0.0f, 0.0f, 0.0f, 1.0f );

        glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE, GL_MODULATE);
        glGenTextures(4, textures);

	// Load the texture objects
        pBytes = gltLoadTGA("floor.tga", &nWidth, &nHeight, &nComponents, &format);
        glBindTexture(GL_TEXTURE_2D, textures[0]);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
	glTexImage2D(GL_TEXTURE_2D,0,nComponents,nWidth, nHeight, 0,
		format, GL_UNSIGNED_BYTE, pBytes);
	free(pBytes);

	pBytes = gltLoadTGA("Block4.tga", &nWidth, &nHeight, &nComponents, &format);
        glBindTexture(GL_TEXTURE_2D, textures[1]);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
	glTexImage2D(GL_TEXTURE_2D,0,nComponents,nWidth, nHeight, 0,
		format, GL_UNSIGNED_BYTE, pBytes);
	free(pBytes);

	pBytes = gltLoadTGA("block5.tga", &nWidth, &nHeight, &nComponents, &format);
        glBindTexture(GL_TEXTURE_2D, textures[2]);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
	glTexImage2D(GL_TEXTURE_2D,0,nComponents,nWidth, nHeight, 0,
		format, GL_UNSIGNED_BYTE, pBytes);
	free(pBytes);

	pBytes = gltLoadTGA("block6.tga", &nWidth, &nHeight, &nComponents, &format);
        glBindTexture(GL_TEXTURE_2D, textures[3]);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
	glTexImage2D(GL_TEXTURE_2D,0,nComponents,nWidth, nHeight, 0,
		format, GL_UNSIGNED_BYTE, pBytes);
	free(pBytes);
        }

void KeyPressFunc(unsigned char key, int x, int y)
	{
	if(key == 32)
		{
		nStep++;

		if(nStep > 5)
			nStep = 0;
		}

	// Refresh the Window
	glutPostRedisplay();
	}


void ChangeSize(int w, int h)
	{
	// Calculate new clipping volume
	GLfloat windowWidth;
	GLfloat windowHeight;

	// Prevent a divide by zero, when window is too short
	// (you cant make a window of zero width).
	if(h == 0)
		h = 1;

	// Keep the square square
	if (w <= h)
		{
		windowHeight = 100.0f*(GLfloat)h/(GLfloat)w;
		windowWidth = 100.0f;
		}
    else
		{
		windowWidth = 100.0f*(GLfloat)w/(GLfloat)h;
		windowHeight = 100.0f;
		}

        // Set the viewport to be the entire window
        glViewport(0, 0, w, h);

        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();

	// Set the clipping volume
	glOrtho(-100.0f, windowWidth, -100.0f, windowHeight, -200.0f, 200.0f);

        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();

	glLightfv(GL_LIGHT0,GL_POSITION, vLightPos);

	glRotatef(30.0f, 1.0f, 0.0f, 0.0f);
	glRotatef(330.0f, 0.0f, 1.0f, 0.0f);
	}

int main(int argc, char* argv[])
	{
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
	glutInitWindowSize(800, 600);
	glutCreateWindow("3D Effects Demo");
	glutReshapeFunc(ChangeSize);
	glutKeyboardFunc(KeyPressFunc);
	glutDisplayFunc(RenderScene);

	SetupRC();

	glutMainLoop();
	glDeleteTextures(4,textures);
	return 0;
	}


When I try to compile it, the IDE shows this error message:
obj\Debug\main.o||In function Z11RenderScenev':| D:\Codeblock C files\Test_OpenGL\main.cpp|102|undefined reference toglutWireCube’|
D:\Codeblock C files\Test_OpenGL\main.cpp|151|undefined reference to glutSolidCube'| D:\Codeblock C files\Test_OpenGL\main.cpp|155|undefined reference toglutSolidCube’|
D:\Codeblock C files\Test_OpenGL\main.cpp|161|undefined reference to glutSolidCube'| D:\Codeblock C files\Test_OpenGL\main.cpp|169|undefined reference tom3dGetPlaneEquation(float*, float const*, float const*, float const*)’|
D:\Codeblock C files\Test_OpenGL\main.cpp|170|undefined reference to m3dMakePlanarShadowMatrix(float*, float const*, float const*)'| D:\Codeblock C files\Test_OpenGL\main.cpp|179|undefined reference toglutSolidCube’|
D:\Codeblock C files\Test_OpenGL\main.cpp|235|undefined reference to m3dGetPlaneEquation(float*, float const*, float const*, float const*)'| D:\Codeblock C files\Test_OpenGL\main.cpp|236|undefined reference tom3dMakePlanarShadowMatrix(float*, float const*, float const*)’|
D:\Codeblock C files\Test_OpenGL\main.cpp|243|undefined reference to glutSolidCube'| D:\Codeblock C files\Test_OpenGL\main.cpp|251|undefined reference toglutSwapBuffers’|
obj\Debug\main.o||In function Z7SetupRCv':| D:\Codeblock C files\Test_OpenGL\main.cpp|269|undefined reference togltLoadTGA(char const*, int*, int*, int*, unsigned int*)’|
D:\Codeblock C files\Test_OpenGL\main.cpp|279|undefined reference to gltLoadTGA(char const*, int*, int*, int*, unsigned int*)'| D:\Codeblock C files\Test_OpenGL\main.cpp|289|undefined reference togltLoadTGA(char const*, int*, int*, int*, unsigned int*)’|
D:\Codeblock C files\Test_OpenGL\main.cpp|299|undefined reference to gltLoadTGA(char const*, int*, int*, int*, unsigned int*)'| obj\Debug\main.o||In functionZ12KeyPressFunchii’:expressionless:
D:\Codeblock C files\Test_OpenGL\main.cpp|321|undefined reference to glutPostRedisplay'| obj\Debug\main.o||In functionmain’:expressionless:
D:\Codeblock C files\Test_OpenGL\main.cpp|368|undefined reference to glutInit'| D:\Codeblock C files\Test_OpenGL\main.cpp|369|undefined reference toglutInitDisplayMode’|
D:\Codeblock C files\Test_OpenGL\main.cpp|370|undefined reference to glutInitWindowSize'| D:\Codeblock C files\Test_OpenGL\main.cpp|371|undefined reference toglutCreateWindow’|
D:\Codeblock C files\Test_OpenGL\main.cpp|372|undefined reference to glutReshapeFunc'| D:\Codeblock C files\Test_OpenGL\main.cpp|373|undefined reference toglutKeyboardFunc’|
D:\Codeblock C files\Test_OpenGL\main.cpp|374|undefined reference to glutDisplayFunc'| D:\Codeblock C files\Test_OpenGL\main.cpp|378|undefined reference toglutMainLoop’|
||=== Build finished: 24 errors, 0 warnings (0 minutes, 2 seconds) ===|

The functions must come from somewhere , but I really have no clue where…
I remember that Glut has functions that start with glut…
So I tried including glut.h or freeglut.h as well, but I get the same errors…

You are missing a lot of includes
glut… are in GL/glut.h ; gltLoadTGA is from the SuperBible; I don’t know what m3d… is

[QUOTE=tonyo_au;1250687]You are missing a lot of includes
glut… are in GL/glut.h ; gltLoadTGA is from the SuperBible; I don’t know what m3d… is[/QUOTE]

Thanks. I tried for several hours, in this thread: http://www.cplusplus.com/forum/general/101665/
The last errors I get are:

C:\MinGW\lib\gltools.lib|2|error: stray ‘`’ in program|
C:\MinGW\lib\gltools.lib|3|warning: null character(s) ignored [enabled by default]|
C:\MinGW\lib\gltools.lib|3|error: stray ‘\24’ in program|
C:\MinGW\lib\gltools.lib|3|warning: null character(s) ignored [enabled by default]|
C:\MinGW\lib\gltools.lib|3|error: stray ‘\6’ in program|
C:\MinGW\lib\gltools.lib|3|error: stray ‘\344’ in program|
… list truncated…
||More errors follow but not being shown.|
||Edit the max errors limit in compiler options…|
||=== Build finished: 50 errors, 25 warnings (0 minutes, 26 seconds) ===|

Is it possible that a library file is very specific for one C/C++ IDE? That I have the wrong compiled Library?
I used a library which was contained for Visual studio 2010… and I use Code blocks 12.11 now…

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.