GLUT problem/an error on my part

Hi all :)

so for a while now Ive been having this problem, my code has been worked on a lot and yet I cant seem to get past this one error and I feel it may drive me mad if I dont fix it or at least get help with it, hence me being here

the problem in my code is that I have refactored a lot and while I have used GLUT before, Im not the most experienced in it, and my program just wont draw, Im sorry for my poor explanation, simply it wont draw but here is the relevant code:

the gameloop that just causes it to run constantly as with normal game loops:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#ifndef GAMELOOP_H
#define GAMELOOP_H

#include "Input.h"
#include "Controls.h"
#include "Window.h"
#include "Entities.h"

class GameLoop
{
private:
	static GameLoop* instance;
	GameLoop(){}

	Controls* controls;

	Window* window;

	static bool running;

public:
	static GameLoop* get()
	{
		if(instance == nullptr)
		{
			instance = new GameLoop();
		}
		return instance;
	}

	void init(Window* w, Controls* c)
	{
		window = w;
		controls = c;
	}

	void run()
	{
		bool running = true;

		while(running)
		{
			bool* keys = Input::get()->getKybdState();
			controls->useKybd(keys);

			Entities::get()->update(keys);
			window->redraw();
		}
	}

	static void end()
	{
		running = false;
	}
};

GameLoop* GameLoop::instance = nullptr;
bool GameLoop::running = true;

#endif 


The input class that checks for keyboard input:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#ifndef INPUT_H
#define INPUT_H

class Input
{
private:
	static Input* instance;
	Input(){}

	static bool * kybdState;

public:
	static Input* get()
	{
		if(instance == nullptr)
		{
			for(int i = 0; i < 256; i++)
			{
				kybdState[i] = false;
			}

			instance = new Input();
		}
		return instance;
	}

	static bool* getKybdState()
	{
		return kybdState;
	}

	static void keyPressed(unsigned char key)
	{
		kybdState[key] = true;
	}

	static void keyReleased(unsigned char key)
	{
		kybdState[key] = false;
	}

	virtual ~Input()
	{
		delete kybdState;
	}
};

Input* Input::instance = nullptr;
bool * Input::kybdState = new bool[256];

#endif 


The controls class that is used to check what to do depending on keyboard input is just if statements, right now, all I have is if(keys[27]) and to call GameLoop::end() when esc is pressed. When the code gets to here, even though esc hasnt been pressed, the position in the array is set to true which I dont understand, which is why I have the for loop attempting to set the entire array to false when its created.

The Entities update is a simple for loop through a list of all entities in game, that isnt causing any issues

and finally the window that is used to draw, where all of the glut stuff is:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#ifndef GLUTWINDOW_H
#define GLUTWINDOW_H

#include "glut.h"
#include "Window.h"
#include "GameLoop.h"
#include "Entities.h"

void draw(void);
void resize(int, int);
void kybdPressed(unsigned char, int, int);
void kybdReleased(unsigned char, int, int);

class GlutWindow : public Window
{
private:
	int window;
	static Entities* entities;
	static Input* input;

public:
	GlutWindow(int argc, char** argv, char* title, int w, int h)
	{
		glutInit(&argc, argv);
		glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
		glutInitWindowSize(w, h);
		glutInitWindowPosition(w/10, h/10);
		window = glutCreateWindow(title);

		glutDisplayFunc(draw);
		glutReshapeFunc(resize);
		glutKeyboardFunc(kybdPressed);
		glutKeyboardUpFunc(kybdReleased);

		//glutMainLoop();
	}

	static void draw()
	{
		glClearColor(0.0, 0.0, 0.0, 1.0);
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

		Entities::get()->draw();

		glutSolidTeapot(3.0);

		glFlush(); // Complete Pending Operations
		glutSwapBuffers(); //Switch Buffer (Double Buffering)
	}

	static void resize(int w, int h)
	{
		glViewport(0, 0, (GLsizei)w, (GLsizei)h);
		glMatrixMode(GL_PROJECTION);
		glLoadIdentity();
		gluPerspective(45, (GLfloat)w / (GLfloat)h, 1.0, 100.0);
		glMatrixMode(GL_MODELVIEW);
	}

	static void kybdPressed(unsigned char key, int x, int y)
	{
		input->keyPressed(key);
	}

	static void kybdReleased(unsigned char key, int x, int y)
	{
		input->keyReleased(key);
	}

	void redraw()
	{
		glutPostRedisplay();
	}

	virtual ~GlutWindow(){}
};

Entities* GlutWindow::entities = nullptr;
Input* GlutWindow::input = nullptr;

#endif 


oh and a basic main to allow you to attept to run it if you need to:
1
2
3
4
5
6
7
8
9
10
11
int main(int argc, char** argv)
{
	window = new GlutWindow(argc, argv, "EcoSphere", 800, 600);

	GameLoop::get()->init(window, new EcoSphereControls());
	GameLoop::get()->run();

	delete window;

	return 0;
};


I apologise for the mass of code, if someone is willing to help and need any further information, please say, and I will be most grateful :)
just wanted to bring this up the list of posts a bit, hope people dont mind
bringing it back up again, also, Im sorry there is so much code, Im not entirely sure what is relevant to my issue, just that it doesnt draw, it did used to make a window with a white background but I removed glutMainLoop() in the GlutWindow constructor and now the window doesnt appear
Topic archived. No new replies allowed.