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
| |