-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.cpp
More file actions
91 lines (80 loc) · 1.98 KB
/
main.cpp
File metadata and controls
91 lines (80 loc) · 1.98 KB
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
82
83
84
85
86
87
88
89
90
91
#include <stdlib.h>
#include "GL/glut.h"
#include <iostream>
#pragma comment(lib, "glut32.lib")
#define WINDOW_TITLE "Project"
using namespace std;
const float ANGLE = 45.f;
const float FOV = 70.f;
const float NCP = 0.001f;
const float FCP = 40.f;
int m_iWidth = 800; //width of the viewport
int m_iHeight = 600; //height of the viewport
///
/// Function designed to be use in the glutKeyboardFunc
/// @param key represents the key pressed in the keyboard
///
void keyboardDown(unsigned char key, int x, int y)
{
switch(key) {
case 'Q':
case 'q':
case 27: // ESC
exit(0);
}
}
/// Function invoked on idle time of program
void idle(void)
{
glutPostRedisplay();
}
/// All the drawing code here
void draw()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(0.6,0.6,0.6,1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
//begin - rendering a simple triangle (testing)
glBegin(GL_TRIANGLES);
glColor3f(1,0,0);
glVertex3f(-0.5,0,-1);
glColor3f(0.5,0.5,0);
glVertex3f(0.5,0,-1);
glColor3f(0,0.5,0.5);
glVertex3f(0,0.5,-1);
glEnd();
//begin - rendering a simple triangle
glutSwapBuffers();
}
/// Is invoked when window is resized, modifying the projection matrix and viewport
void reshape(int width, int height)
{
glViewport (0, 0, (GLsizei) width, (GLsizei) height);
glMatrixMode (GL_PROJECTION);
glLoadIdentity();
float ratio = (height == 0)?1:(GLfloat) width/(GLfloat) height;
gluPerspective(FOV, ratio, NCP, FCP);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
/// Insert all your initialization objects and OpenGL status
bool initialize()
{
glEnable(GL_DEPTH_TEST);
return true;
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
glutInitWindowSize(m_iWidth, m_iHeight);
glutCreateWindow(WINDOW_TITLE);
if(!initialize()) return 1;
glutDisplayFunc(draw);
glutIdleFunc(idle);
glutReshapeFunc(reshape);
glutKeyboardFunc(keyboardDown);
glutMainLoop();
return 0;
}