Hey, at my camp, I made a random 3D maze gen off of OpenGL

So, I downloaded OpenGL 3.7, and I placed the glut.dll in the right place, the header file in the right place, the lib file in the right place etc.

But my conflict is that I used a different version of OpenGL at my camp because the header 3.7 header doesn't recognize some of the code.

So could someone tell me what version of OpenGL uses this header?

<GL/glut.h>

thank you.

And if you know the solution and can run the code, here is the whole code if you're curious.

// openGL stuff 

#include <list>
#include <time.h>
#include <windows.h>
#include <GL/glut.h>
#include <stdlib.h>
#include <cstdio>
#include <iostream>

#define MSIZE 5

using namespace std;

void init();
void display();
void keyboard();

class Character {
GLfloat x, y, z;

public:
	Character(GLfloat _cx, GLfloat _cy, GLfloat _cz)
	{
	x = _cx;
	y = _cy;
	z = _cz;
	}
	Character(const Character& b)
	{
	x = b.x;
	y = b.y;
	z = b.z;
	}

	void draw()
	{
	glShadeModel(GL_SMOOTH);
	glPushMatrix();
	//glRotatef(cspin, 0.0, 0.0, 1.0);
	//cspin ++;
	glTranslatef(0.0, 0.0, -.25);
	glColor4f(1.0, 0.0, 1.0, 0.0);
	glutSolidTeapot(5.0);
	glDisable(GL_LIGHTING);
	glPopMatrix();
	}
};

class Cell {

public:
	GLfloat x, y, z;
	GLfloat width, depth, height;
	GLfloat red, green, blue;

	Cell(){
		x = -1;
		y = -1;
		z = -1;
		red = ((float) rand()) / RAND_MAX;
		green = ((float) rand()) / RAND_MAX;
		blue = ((float) rand()) / RAND_MAX;
	}

	Cell(const Cell& cell){
		x=cell.x;
		y=cell.y;
		z=cell.z;
		red = cell.red;
		green = cell.green;
		blue = cell.blue;

	}

	bool adjacent(Cell& cell)
	{
		GLfloat dx = abs(x-cell.x);
		GLfloat dy = abs(y-cell.y);
		GLfloat dz = abs(z-cell.z);

		return (dx == 1 && dy == 0 && dz == 0) ||
			   (dy == 1 && dx == 0 && dz == 0) ||
			   (dz == 1 && dx == 0 && dy == 0);
	}

	bool equals (Cell& cell)
	{
		return(x==cell.x && y == cell.y && z == cell.z); 
	}

	void draw()              
	{
		/*glFrontFace(GL_CW);
		glBegin(GL_QUADS);
		glColor4f(0.0, 1.0, 1.0, 0.7);
		glVertex3f(x, y, z);
		glVertex3f(x + width, y, z);
		glVertex3f(x + width, y + height, z);
		glVertex3f(x, y + height, z);
		
		glColor4f(1.0, 0.0, 0.0, 0.7);
		glVertex3f(x, y, z);
		glVertex3f(x, y + height, z);
		glVertex3f(x, y + height, z + depth);
		glVertex3f(x, y, z + depth);
		
		glColor4f(1.0, 1.0, 0.0, 0.7);
		glVertex3f(x, y, z);
		glVertex3f(x, y, z + depth);
		glVertex3f(x + width, y, z + depth);
		glVertex3f(x + width, y, z);
		
		glColor4f(0.0, 1.0, 1.0, 0.7);
		glVertex3f(x + width, y + height, z + depth);
		glVertex3f(x + width, y, z + depth);
		glVertex3f(x, y, z + depth);
		glVertex3f(x, y + height, z + depth);
		
		glColor4f(1.0, 0.0, 0.0, 0.7);
		glVertex3f(x + width, y, z + depth);
		glVertex3f(x + width, y + height, z + depth);
		glVertex3f(x + width, y + height, z);
		glVertex3f(x + width, y, z);
		
		glColor4f(1.0, 1.0, 0.0, 0.7);
		glVertex3f(x + width, y + height, z);
		glVertex3f(x + width, y + height, z + depth);
		glVertex3f(x, y + height, z + depth);
		glVertex3f(x, y + height, z);
		
		glEnd();*/
		
	}
	
	//int operator<(Cell& );
};


typedef list<Cell> CLIST;

class CellSet{
	//CLIST set;

public: 
	CLIST set;

	CellSet(){}
	CellSet(Cell cell) {
		set.push_front(cell);
	}
	CellSet(const CellSet& set2){
		set.assign(set2.set.begin(),set2.set.end());
	}
	
	bool member(Cell& cell){
		for(CLIST::iterator i=set.begin();i!=set.end();++i) {
			if (cell.equals(*i)){
				return true;
			}
		}
		return false;
	}

	CellSet& merge(CellSet& set2)
	{
		//se
		for(CLIST::iterator i=set2.set.begin();i!=set2.set.end();++i) {
			CLIST::iterator j=set.begin();
			if (!member(*i))
			{
				set.push_front(*i);
			}
		}
		return *this;
	}
	CellSet& difference(CellSet& set2)
	{
		for(CLIST::iterator i=set2.set.begin();i!=set2.set.end();++i) {
			CLIST::iterator j=set.begin();
			while (j!=set.end()&& !(*i).equals(*j)) {
				++j;
			}
			if(j!=set.end())
			{
				set.erase(j);
			}
		}
		return *this;
	}
	bool empty(){
		return set.empty();
	}
	CellSet& intersect(CellSet& set2){
		for(CLIST::iterator i=set.begin();i!=set.end();++i) {
			CLIST::iterator j=set2.set.begin();
			while (j!=set2.set.end()&& !(*i).equals(*j)) {
				++j; 
			}
			if(j==set2.set.end())
			{
				set.erase(i);
			}
		}
		return *this;
	}
	bool subset(CellSet& set2){
		CLIST::iterator i;
		for(i=set.begin();i!=set.end();++i) {
			if (! set2.member(*i)){
				return false;
			}
		}
		return true;
	}
	bool equals(CellSet& set2){
		CLIST::iterator i;
		return (subset(set2) && set2.subset(*this));
	}


	CLIST::iterator get(int index){
		CLIST::iterator i;
		for (i=set.begin();index > 0 && i != set.end();++i, --index);
		return i;
	}
};

typedef list<CellSet> CSLIST;

class CSSet {
	//CSLIST set;

public: 
	CSLIST set;

	CSSet(){}
	CSSet(CellSet cell) {
		set.push_front(cell);
	}
	CSSet(const CSSet& set2){
		set.assign(set2.set.begin(),set2.set.end());
	}
	
	bool member(CellSet& cell){
		for(CSLIST::iterator i=set.begin();i!=set.end();++i) {
			if (cell.equals(*i)){
				return true;
			}
		}
		return false;
	}

	CSSet& merge(CSSet& set2)
	{
		//se
		for(CSLIST::iterator i=set2.set.begin();i!=set2.set.end();++i) {
			CSLIST::iterator j=set.begin();
			if (!member(*i))
			{
				set.push_front(*i);
			}
		}
		return *this;
	}
	CSSet& difference(CSSet& set2)
	{
		for(CSLIST::iterator i=set2.set.begin();i!=set2.set.end();++i) {
			CSLIST::iterator j=set.begin();
			while (j!=set.end()&& !(*i).equals(*j)) {
				++j;
			}
			if(j!=set.end())
			{
				set.erase(j);
			}
		}
		return *this;
	}
	bool empty(){
		return set.empty();
	}
	CSSet& intersect(CSSet& set2){
		for(CSLIST::iterator i=set.begin();i!=set.end();++i) {
			CSLIST::iterator j=set2.set.begin();
			while (j!=set2.set.end()&& !(*i).equals(*j)) {
				++j; 
			}
			if(j==set2.set.end())
			{
				set.erase(i);
			}
		}
		return *this;
	}

	bool subset(CSSet& set2){
		CSLIST::iterator i;
		for(i=set.begin();i!=set.end();++i) {
			if (! set2.member(*i)){
				return false;
			}
		}
		return true;
	}
	bool equals(CSSet& set2){
		CSLIST::iterator i;
		return (subset(set2) && set2.subset(*this));
	}

	CSLIST::iterator get(int index){
		CSLIST::iterator i;
		for (i=set.begin();index > 0 && i != set.end();++i, --index);
		return i;
	}
};

/*int operator<(Cell& cell1, Cell& cell2) {
	return cell1.getID() < cell2.getID();
}*/

//typedef list<CSET> CSSET;

CSSet walls; 
GLfloat cspin = 0.0;
GLfloat x = 0.25, y = 0.25, z = 0.25;
GLfloat xspin = 0.0, yspin = 0.0, zspin = 0.0; 

CellSet maze;
//Cell cells[MSIZE][MSIZE][MSIZE];
bool intersectWall(CellSet wall) {
Cell cell1 = *(wall.get(0));
	Cell cell2 = *(wall.get(1));
	GLfloat cx = cell1.x, cy = cell1.y, cz = cell1.z;
	// 
	GLfloat dx = 1, dy = 1, dz = 1;
	if (cell1.x != cell2.x){
		dx=0;
		cx += (cell1.x < cell2.x ? 1 : 0);
	}		
	if (cell1.y != cell2.y){
		dy=0;
		cy += (cell1.y < cell2.y ? 1 : 0);
	}
	if (cell1.z != cell2.z){
		dz=0;
		cz += (cell1.z < cell2.z ? 1 : 0);
	}
	//
	GLfloat px = x - 0.05, py = y - 0.05, pz = z - 0.05;
	GLfloat pw = 0.1, ph = 0.1, pd = 0.1;

	// x1 = cx, y1 = cy, z1 = cz, width1 = dx, height1 = dy, depth1 = dz
	// x2 = px, y2 = cy, z2 = cz, width2 = pw, height2 = ph, depth2 = pz

	return !(cx>px+pw || cx + dx<px)&&
	!(cy>py+ph || cy + dy<py)&&
	!(cz>pz+pd || cz + dz<pz);

	//glFrontFace(GL_CW);
	//cout << cx << endl; 
	
	//glBegin(GL_QUADS);
		//glColor3f(1.0, 1.0, 1.0);
	/*if (dz == 0 || dy == 0) {
		glVertex3f(cx, cy, cz);
		glVertex3f(cx + dx, cy, cz);
		glVertex3f(cx + dx, cy + dy, cz + dz);
		glVertex3f(cx, cy + dy, cz + dz);
	}
	
	if (dx == 0) {
		glVertex3f(cx, cy, cz);
		glVertex3f(cx + dx, cy + dy, cz);
		glVertex3f(cx + dx, cy + dy, cz + dz);
		glVertex3f(cx, cy, cz + dz);
	}*/
	//glEnd();
}

void drawWall(CellSet wall) {
	Cell cell1 = *(wall.get(0));
	Cell cell2 = *(wall.get(1));
	GLfloat cx = cell1.x, cy = cell1.y, cz = cell1.z;
	// 
	GLfloat dx = 1, dy = 1, dz = 1;
	if (cell1.x != cell2.x){
		dx=0;
		cx += (cell1.x < cell2.x ? 1 : 0);
	}		
	if (cell1.y != cell2.y){
		dy=0;
		cy += (cell1.y < cell2.y ? 1 : 0);
	}
	if (cell1.z != cell2.z){
		dz=0;
		cz += (cell1.z < cell2.z ? 1 : 0);
	}

	//glFrontFace(GL_CW);
	//cout << cx << endl; 
	glColor3f((cell1.red + cell2.red) / 2,(cell1.green + cell2.green) / 2, (cell1.blue + cell2.blue) / 2);
	/*glBegin(GL_QUADS);
		glVertex3f(-1.0, -1.0, -1.0);
		glVertex3f(-1.0, 1.0, -1.0);
		glVertex3f(1.0, 1.0, -1.0);
		glVertex3f(-1.0, 1.0, -1.0);
	glEnd();*/
	glBegin(GL_QUADS);
		//glColor3f(1.0, 1.0, 1.0);
	if (dz == 0 || dy == 0) {
		glVertex3f(cx, cy, cz);
		glVertex3f(cx + dx, cy, cz);
		glVertex3f(cx + dx, cy + dy, cz + dz);
		glVertex3f(cx, cy + dy, cz + dz);
	}
	
	if (dx == 0) {
		glVertex3f(cx, cy, cz);
		glVertex3f(cx, cy + dy, cz);
		glVertex3f(cx, cy + dy, cz + dz);
		glVertex3f(cx, cy, cz + dz);
	}
	glEnd();

}



/*	W		x,y,z	W
	0,1,1	1,1,1	1,1,1

	xy walls
	xz walls
	yz walls
*/



GLfloat tx = 0.0, ty = 0.0, tz = 0.0;
GLfloat cx = 0.0, cy = 0.0, cz = -10.0; 
/*typedef list<Building> BLIST;

BLIST bl;*/

/*void draw()
{
	glShadeModel(GL_SMOOTH);
	glPushMatrix();
	glRotatef(cspin, 0.0, 0.0, 1.0);
	cspin ++;
	glColor3f(1.0, 1.0, 0.0);
	glutSolidCube(5.0);
	glutSolidTorus(1.0, 2.0, 2.0, 20);
	glDisable(GL_LIGHTING);
	glPopMatrix();
}*/

bool intersectWalls()
{
	for(CSLIST::iterator i = walls.set.begin(); i != walls.set.end(); ++i)
	{
		if (intersectWall(*i)) return true;
	}
	return false;
}

void display()
{
	glClear(GL_COLOR_BUFFER_BIT);
	glClear(GL_DEPTH_BUFFER_BIT);
	
	glMatrixMode(GL_PROJECTION);
	//glLoadIdentity();
	glPushMatrix();
	//glTranslatef(x, y, z);
	//glTranslatef(-x, -y, -z);
	glRotatef(xspin, 1.0, 0.0, 0.0);
	glRotatef(yspin, 0.0, 1.0, 0.0);
	glRotatef(zspin, 0.0, 0.0, 1.0);
	glTranslatef(-x, -y, -z);
	//glTranslatef(-x, -y, -z);
	/*glRotatef(xspin, 1.0, 0.0, 0.0);
	glRotatef(yspin, 0.0, 1.0, 0.0);
	glRotatef(zspin, 0.0, 0.0, 1.0);*/
	//gluPerspective(30.0, 4.0 / 3.0 , 0.5, MSIZE + 1);
	//glTranslatef(0, 0, -1.5);
	//glRotatef(cspin, 0.0, 1.0, 0.0);
	glColor4f(1.0, 1.0, 1.0, 0.0);
	//cspin += 0.5;
		
	
	glMatrixMode(GL_MODELVIEW);
	glPushMatrix();
	glTranslatef(x, y, z); // - 1.5);
	glRotatef(-xspin, 1.0, 0.0, 0.0);
	glRotatef(-yspin, 0.0, 1.0, 0.0);
	glRotatef(-zspin, 0.0, 0.0, 1.0);
	glTranslatef(0, 0, -1.5);
	//glRotatef(xspin, 0.0, 1.0, 0.0);
	//glRotatef(cspin, 0.0, -4.0, 0.0);
	//glRotatef(cspin, 0.0, 0.0, -4.0);
	
	glutSolidTeapot(0.1);

	glPopMatrix();
	
	//Character player(cx, cy, cz);
	//player.draw();
	
	CSLIST::iterator i;
	
	for(i = walls.set.begin(); i != walls.set.end(); ++i)
	{
		drawWall((*i));
	}
	
	//glPopMatrix();
	glMatrixMode(GL_PROJECTION);

	glPopMatrix();
	
	//glMatrixMode(GL_MODELVIEW);
	
	glFlush();
	
	glutPostRedisplay();
}
void keyboard() {
	if (GetAsyncKeyState(0x57) & 0x8000)
	{
		y += 0.01;
		if(intersectWalls()) y -= 0.01;
		else cout << y << endl;
		//cout << z << endl;
		//yspin = 90;
		//xspin = 0;
		//yspin = 0;
		//zspin = 0;
	}
	if (GetAsyncKeyState(0x41) & 0x8000)
	{
		x -= 0.01;
		if(intersectWalls()) x += 0.01;
		//yspin = 270;
		//xspin = 0;
		//xspin = 0;
		//yspin = 0;
		//zspin = 0;
	}
	if (GetAsyncKeyState(0x44) & 0x8000)
	{
		x += 0.01;
		if(intersectWalls()) x -= 0.01;
		//xspin = 0;
		//yspin = 0;
		//zspin = 0;
	}
	if (GetAsyncKeyState(0x53) & 0x8000)
	{
		y-= 0.01;
		if(intersectWalls()) y += 0.01;
		//cout << z << endl;
		//xspin = 0;
		//yspin = 0;
		//zspin = 0;
		
	}
	if (GetAsyncKeyState(0x20) & 0x8000)
	{
		tx = cx;
		ty = cy;
		tz = cz + 20;
	}
	if (GetAsyncKeyState(0x26) & 0x8000)
	{
		z -= 0.01;
		//xspin = 180; //++;//; = 180;
		//yspin = 0;
		//zspin = 180;
		//zspin = 180;
		if(intersectWalls()) z += 0.01;
		//xspin = 180;

	}
	if (GetAsyncKeyState(0x28) & 0x8000)
	{
		z += 0.01;
		if(intersectWalls()) z -= 0.01;
		//xspin = 0;
		//yspin = 0;
		//zspin = 0;
	}
}

void init() {
	glEnable(GL_DEPTH_TEST);
	//glEnable(GL_BLEND);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	//glOrtho(-0.5, 0.5, -0.5, 0.5, -5, 5);
	gluPerspective(30.0, 4.0 / 3.0 , 0.5, MSIZE + 1);
	glMatrixMode(GL_MODELVIEW);
	//glOrtho(-10.0, 10.0, -10.0, 10.0, -10.0, 10.0);
	glLoadIdentity();
	//makedense(-500.0, -500.0, -500.0, 1000.0, 1000.0, 1000.0,
	//	      -500.0, -500.0, -500.0, 1000.0, 1000.0, 1000.0);

	glEnable(GL_FOG);
	{
		GLint fogMode;
		GLfloat fogColor[4] = {0.0, 0.0, 0.0, 1.0};

		fogMode = GL_EXP;
		glFogi(GL_FOG_MODE, fogMode);
		glFogfv(GL_FOG_COLOR, fogColor);
		glFogf(GL_FOG_DENSITY, 0.5);
		glHint(GL_FOG_HINT, GL_DONT_CARE);
		glFogf(GL_FOG_START, 1.0);
		glFogf(GL_FOG_END, 10.0);
	}
	glClearColor(0.0, 0.0, 0.0, 1.0);
}

/*int main(int argc, char **argv)
{
	//srand(time(NULL));
	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
	glutInitWindowSize(800, 600);
	glutInitWindowPosition(100, 100);
	glutCreateWindow("Paul is so awesome you are freaking out");
	init();
	glutDisplayFunc(display);
	glutIdleFunc(keyboard);
	//glutMouseFunc(mouse);
	glutMainLoop();
	return 0; 
}*/

int main(int argc, char *argv[])
{

	CSSet conn;

	srand(time(NULL));
	
	for(int x=0;x<MSIZE;x++)
	{
		for(int y=0;y<MSIZE;++y)
		{
			for(int z=0;z<MSIZE;++z)
			{
				Cell cell;
				cell.x = x;
				cell.y = y;
				cell.z = z;
				if (cell.x == 0){
					CellSet edge;
					Cell cell2 = cell;
					cell2.x = -1;
					edge.merge(CellSet(cell)); 
					edge.merge(CellSet(cell2));
					walls.merge(CSSet(edge));
				}
				else if (cell.x == MSIZE-1){
					CellSet edge;
					Cell cell2 = cell;
					cell2.x = MSIZE;
					edge.merge(CellSet(cell)); 
					edge.merge(CellSet(cell2));
					walls.merge(CSSet(edge));
				}
				if (cell.y == 0){
					CellSet edge;
					Cell cell2 = cell;
					cell2.y = -1;
					edge.merge(CellSet(cell)); 
					edge.merge(CellSet(cell2));
					walls.merge(CSSet(edge));
				}
				else if (cell.y == MSIZE-1){
					CellSet edge;
					Cell cell2 = cell;
					cell2.y = MSIZE;
					edge.merge(CellSet(cell)); 
					edge.merge(CellSet(cell2));
					walls.merge(CSSet(edge));
				}
				if (cell.z == 0){
					CellSet edge;
					Cell cell2 = cell;
					cell2.z = -1;
					edge.merge(CellSet(cell)); 
					edge.merge(CellSet(cell2));
					walls.merge(CSSet(edge));
				}
				else if (cell.z == MSIZE-1){
					CellSet edge;
					Cell cell2 = cell;
					cell2.z = MSIZE;
					edge.merge(CellSet(cell)); 
					edge.merge(CellSet(cell2));
					walls.merge(CSSet(edge));
				}
				//if (cell.x) 
				maze.merge(CellSet(cell));
				CellSet initial(cell);
				conn.merge(CSSet(initial));
			}
		}
	}
	
	for(CLIST::iterator i = maze.set.begin();i!=maze.set.end(); ++i)
	{
		for(CLIST::iterator j =maze.set.begin(); j!=maze.set.end(); ++j)
		{
			if((*i).adjacent(*j)) {
				CellSet edge;
				edge.merge(CellSet(*i));
				edge.merge(CellSet(*j));
				walls.merge(CSSet(edge));
			}
		}
	}

	while(conn.set.size()>1)
	{
		int _size = conn.set.size();
		int i = rand()%walls.set.size();
		CSSet wallset;
		CSLIST::iterator wall = walls.get(i);
		CSLIST::iterator cset = conn.set.begin();

		while(cset!=conn.set.end()) {
			for (CLIST::iterator j=(*wall).set.begin(); j !=(*wall).set.end(); ++j)
			{
				if( (*cset).member(*j)) {
					wallset.merge(CSSet(*cset));
				}
			}
			++cset;
		}
		if (wallset.set.size() > 1) {
			conn.difference(wallset);
			CellSet merged;
			for (CSLIST::iterator j=wallset.set.begin(); j != wallset.set.end(); ++j)
			{
				merged.merge(*j);
			}
			conn.merge(CSSet(merged));
		
			walls.difference(CSSet(*wall));
		}
		if (conn.set.size() != _size) { cout << conn.set.size() << endl;}
	
	}

	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
	glutInitWindowSize(800, 600);
	glutInitWindowPosition(100, 100);
	glutCreateWindow("Paul is so awesome you are freaking out");
	init();
	glutDisplayFunc(display);
	glutIdleFunc(keyboard);
	//glutMouseFunc(mouse);
	glutMainLoop();
	return 0; 
}

Recommended Answers

All 4 Replies

All it does is draw a teapot?! so whats the point here?

No, I have a question.

Read the post it says I want to know what version of OpenGL uses that header.

Don't jump to conclusions.

I didn't jump to conclusions. I read the 1 line about your question and then answered it. Then I saw your 800 lines of code and thought that it belonged in the code snippets section.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.