Johan is love, Johan is life
This commit is contained in:
@@ -1,142 +1,17 @@
|
||||
#include "Header.h"
|
||||
#include "Model.h"
|
||||
#include "Player.h"
|
||||
#include "StateHandler.h"
|
||||
#include "State.h"
|
||||
#include <GL/freeglut.h>
|
||||
|
||||
//Prototypes
|
||||
void bindFuncOpenGL(void);
|
||||
void configureOpenGL(void);
|
||||
void loadModels(void);
|
||||
#include "CrystalJohan.h"
|
||||
#include <stdio.h>
|
||||
#include "vector.h"
|
||||
|
||||
static int Width;
|
||||
static int Height;
|
||||
CrystalJohan* app;
|
||||
|
||||
float lastFrameTime = 0;
|
||||
bool keys[255];
|
||||
|
||||
//vector<Model*> models;
|
||||
//int currentModel = 0;
|
||||
|
||||
|
||||
StateHandler *statehandler;
|
||||
|
||||
void display()
|
||||
{
|
||||
glClearColor(0.6f, 0.6f, 1, 1);
|
||||
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
gluPerspective(60.0f, (float)Width / Height, 0.5, 300);
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
|
||||
/*glRotatef(player.eyes.rotX, 1, 0, 0);
|
||||
glRotatef(player.eyes.rotY, 0, 1, 0);
|
||||
glTranslatef(player.eyes.posX, player.eyes.posY, player.eyes.posZ);
|
||||
|
||||
glPushMatrix();
|
||||
glScalef(0.5f, 0.5f, 0.5f);
|
||||
glRotatef(180, 1, 0, 0);
|
||||
glRotatef(45, 0, 0, 1);
|
||||
glRotatef(90, 0, 1, 0);
|
||||
models[currentModel]->draw();
|
||||
glPopMatrix();*/
|
||||
|
||||
//Draw here
|
||||
|
||||
statehandler->GetCurrentState()->Display();
|
||||
|
||||
//player->Display();
|
||||
|
||||
//glutSolidCube(10.0);
|
||||
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
glutSwapBuffers();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void idle()
|
||||
{
|
||||
float frameTime = glutGet(GLUT_ELAPSED_TIME) / 1000.0f;
|
||||
float deltaTime = frameTime - lastFrameTime;
|
||||
lastFrameTime = frameTime;
|
||||
|
||||
statehandler->GetCurrentState()->Keyboard(keys,deltaTime);
|
||||
statehandler->GetCurrentState()->Idle(deltaTime);
|
||||
|
||||
glutPostRedisplay();
|
||||
}
|
||||
|
||||
void mousemotion(int x, int y)
|
||||
{
|
||||
int dx = x - Width / 2;
|
||||
int dy = y - Height / 2;
|
||||
if ((dx != 0 || dy != 0) && abs(dx) < 400 && abs(dy) < 400)
|
||||
{
|
||||
statehandler->GetCurrentState()->MouseMove(x, y, dx, dy);
|
||||
glutWarpPointer(Width / 2, Height / 2);
|
||||
}
|
||||
}
|
||||
|
||||
void mouse(int button, int type, int x, int y)
|
||||
{
|
||||
statehandler->GetCurrentState()->MouseClick(button, type, x, y);
|
||||
}
|
||||
|
||||
void keyboard(unsigned char key, int, int)
|
||||
{
|
||||
if (key == 27)
|
||||
exit(0);
|
||||
//std::cout << key << std::endl;
|
||||
keys[key] = true;
|
||||
}
|
||||
|
||||
void keyboardup(unsigned char key, int, int)
|
||||
{
|
||||
keys[key] = false;
|
||||
}
|
||||
bool justMoved = false;
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
//Init GLUT
|
||||
app = new CrystalJohan();
|
||||
glutInit(&argc, argv);
|
||||
|
||||
//Configre OpenGL and FreeGLut
|
||||
configureOpenGL();
|
||||
|
||||
//Bind functions
|
||||
bindFuncOpenGL();
|
||||
|
||||
//Init models
|
||||
loadModels();
|
||||
|
||||
//Start the main loop
|
||||
glutMainLoop();
|
||||
return 0;
|
||||
}
|
||||
|
||||
void bindFuncOpenGL()
|
||||
{
|
||||
glutDisplayFunc(display);
|
||||
glutIdleFunc(idle);
|
||||
glutReshapeFunc([](int w, int h) { Width = w; Height= h; glViewport(0, 0, w, h); });
|
||||
|
||||
//Keyboard
|
||||
glutKeyboardFunc(keyboard);
|
||||
glutKeyboardUpFunc(keyboardup);
|
||||
|
||||
//Mouse
|
||||
glutMouseFunc(mouse);
|
||||
glutPassiveMotionFunc(mousemotion);
|
||||
|
||||
}
|
||||
|
||||
void configureOpenGL()
|
||||
{
|
||||
//Init window and glut display mode
|
||||
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
|
||||
glutInitWindowSize(800, 600);
|
||||
@@ -144,44 +19,37 @@ void configureOpenGL()
|
||||
glutFullScreen();
|
||||
//glutPositionWindow((glutGet(GLUT_SCREEN_WIDTH) / 2) - (glutGet(GLUT_WINDOW_WIDTH) / 2), (glutGet(GLUT_SCREEN_HEIGHT) / 2) - (glutGet(GLUT_WINDOW_HEIGHT) / 2));
|
||||
|
||||
//Depth testing
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
app->init();
|
||||
|
||||
//Alpha blending
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
//Alpha testing
|
||||
glEnable(GL_ALPHA_TEST);
|
||||
glAlphaFunc(GL_GREATER, 0.01f);
|
||||
glutDisplayFunc([]() { app->draw(); } );
|
||||
glutIdleFunc([]() { app->update(); } );
|
||||
glutReshapeFunc([](int w, int h) { app->width = w; app->height = h; glViewport(0, 0, w, h); });
|
||||
|
||||
//Lighting
|
||||
GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
|
||||
GLfloat mat_shininess[] = { 20.0 };
|
||||
GLfloat light_position[] = { 30.0, 30.0, 30.0, 1.0 };
|
||||
GLfloat light_diffuse[] = { 2.0, 2.0, 2.0, 1.0 };
|
||||
GLfloat light_ambient[] = { 2.0, 2.0, 2.0, 1.0 };
|
||||
glClearColor(0.0, 0.0, 0.0, 0.0);
|
||||
glShadeModel(GL_SMOOTH);
|
||||
//Keyboard
|
||||
glutKeyboardFunc([](unsigned char c, int, int) { app->keyboardState.keys[c] = true; });
|
||||
glutKeyboardUpFunc([](unsigned char c, int, int) { app->keyboardState.keys[c] = false; });
|
||||
|
||||
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
|
||||
glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
|
||||
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
|
||||
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
|
||||
glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
|
||||
//Mouse
|
||||
// glutMouseFunc(mouse);
|
||||
glutPassiveMotionFunc([](int x, int y)
|
||||
{
|
||||
if (justMoved)
|
||||
{
|
||||
justMoved = false;
|
||||
return;
|
||||
}
|
||||
int dx = x - app->width / 2;
|
||||
int dy = y - app->height / 2;
|
||||
if ((dx != 0 || dy != 0) && abs(dx) < 400 && abs(dy) < 400)
|
||||
{
|
||||
app->mouseOffset = app->mouseOffset + Vec2f(dx,dy);
|
||||
glutWarpPointer(app->width / 2, app->height / 2);
|
||||
justMoved = true;
|
||||
}
|
||||
});
|
||||
|
||||
glEnable(GL_LIGHTING);
|
||||
glEnable(GL_LIGHT0);
|
||||
glutMainLoop();
|
||||
|
||||
//Cursor
|
||||
glutWarpPointer(Width / 2, Height / 2);
|
||||
glutSetCursor(GLUT_CURSOR_CROSSHAIR);
|
||||
}
|
||||
|
||||
void loadModels()
|
||||
{
|
||||
statehandler = new StateHandler();
|
||||
|
||||
statehandler->Navigate(statehandler->WORLD_STATE);
|
||||
//models.push_back(new Model("models/weapons/ZwaardMetTextures/TextureZwaard.obj"));
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user