wrong way to do it?

EDIT: OK, start again, knew i'd done something wrong, atm all i want to do is when i press the key down i want the screen to change colour, I've just tryed implemented the code simply, and doesn't seem to work, the outcome of this code is that the screen is always yellow, when i press the i or v button, the screen should change to yellow, and when i press it again it should change to red.

Currently the buttons do nothing and the screen is always yellow.

heres the code.

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
 //main.cpp
#include <GL/glew.h>

#define GLUT_DISABLE_ATEXIT_HACK 
#include <GL/glut.h>
#include <iostream>
#include "ScreenOpenGL.h"
#include "keyboard.h"

bool Login = false;
bool * Keys = new bool [256];
bool InvOpen = false;

void Display ()
{
	Screen Screen;
	// Creating the variable Screen as an instance (Screen is now an object/an instance of the class Screen)
	Screen.Title(&InvOpen);
	Key Key;
	Key.Pressed(&Keys[256], &InvOpen);
}
void ResizeWind(int width, int height)
{

	Screen Screen;
		Screen.Resize(width, height);
}
void KeyPress(unsigned char key, int x, int y)
{
	Keys[key] = true;
}

int main(int argc, char **argv)
{
//Starting glut up
	glutInit(&argc, argv);
//Setting up glut buffer mode, this time its a single buffer.
	glutInitDisplayMode( GLUT_SINGLE);
//Setting up the window then last line creates it and gives it a name
	glutInitWindowSize (600,600);
	glutInitWindowPosition (100,100);
	glutCreateWindow ("Learn OpenGL");
//Telling glut where it will find the function to display things.
	glutKeyboardFunc(KeyPress);
	glutDisplayFunc(Display);
	glutReshapeFunc(ResizeWind);

	glutMainLoop(); 
	return 0;
}


1
2
3
4
5
6
7
8
9
10
11
12
13
//Keyboard.cpp
#include "Keyboard.h"
//passed the address of InvOpen into InvOpen variable
void Key::Pressed(bool Keys[256], bool InvOpen)
{
	if (Keys['i'] || Keys['v']) //Invetory keys
	{
		if (InvOpen = false)
			InvOpen = true;
		else
			InvOpen = false;
	}
}


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
//ScreenOpenGL.cpp
#include "ScreenOpenGL.h"

void Screen::Draw()
{
}

int Screen::Title(bool InvOpen)
{
	if (bool InvOpen = true)
	glClearColor(5.f, 5.f, 0.f, 1.f);
	else
	glClearColor(1.f, 0.f, 0.f, 1.f);
	glClear (GL_COLOR_BUFFER_BIT); //Clear the colour buffer (more buffers later on)  
	glLoadIdentity();  // Load the Identity Matrix to reset our drawing locations  
//Draw everything we've done on the screen (for single buffer mode)	
	glFlush();
	return 0;
}
//passing the width and height into the function when it is called
void Screen::Resize(int width, int height)
{
//setting to resize the window
	glViewport (0,0, (GLsizei)width, (GLsizei)height);
	
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
// Set the Field of view angle (in degrees), the aspect ratio of our window, and the new and far planes  
	gluPerspective(60, (GLfloat)width / (GLfloat)height, 1.0, 100.0);
// Switch back to the model view matrix, so that we can start drawing shapes correctly  
	glMatrixMode(GL_MODELVIEW);
}
Last edited on
Topic archived. No new replies allowed.