2019-09-24 09:34:53 +02:00
|
|
|
#include "GL/glut.h"
|
2019-09-25 00:36:57 +02:00
|
|
|
#include "GL/gl.h"
|
2019-09-24 09:34:53 +02:00
|
|
|
|
2019-09-24 11:34:40 +02:00
|
|
|
#include "displayers.h"
|
2019-09-30 16:52:04 +02:00
|
|
|
#include "DataHandling/Texture.h"
|
|
|
|
#include "DataHandling/Model3D.h"
|
2019-10-07 18:46:35 +02:00
|
|
|
#include "KeyStateManager.h"
|
2019-09-24 09:34:53 +02:00
|
|
|
|
|
|
|
volatile unsigned long long int timer_ticks = 0;
|
2019-09-25 00:36:57 +02:00
|
|
|
static Texture tree_texture;
|
2019-09-30 16:52:04 +02:00
|
|
|
static Model3D raptor;
|
2019-09-30 19:20:10 +02:00
|
|
|
static Texture raptor_texture;
|
2019-09-24 09:34:53 +02:00
|
|
|
|
2019-10-07 18:46:35 +02:00
|
|
|
void manage_inputs()
|
|
|
|
{
|
2019-10-14 21:48:49 +02:00
|
|
|
if (KeyStateManager::is_mouse_button_pressed(GLUT_LEFT_BUTTON))
|
|
|
|
{
|
|
|
|
glClearColor(0,0,0.5,1);
|
|
|
|
}
|
|
|
|
else if (KeyStateManager::is_key_pressed(' '))
|
2019-10-07 18:46:35 +02:00
|
|
|
{
|
|
|
|
glClearColor(0.5,0,0,1);
|
|
|
|
}
|
2019-10-19 04:24:08 +02:00
|
|
|
else if (KeyStateManager::is_key_pressed(0x1B))
|
|
|
|
{
|
|
|
|
glutDestroyWindow(glutGetWindow());
|
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
}
|
2019-10-07 18:46:35 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
glClearColor(0,0,0,1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (KeyStateManager::is_special_key_pressed(GLUT_KEY_RIGHT))
|
|
|
|
{
|
|
|
|
timer_ticks += 5;
|
|
|
|
}
|
|
|
|
if (KeyStateManager::is_special_key_pressed(GLUT_KEY_LEFT))
|
|
|
|
{
|
|
|
|
timer_ticks -= 5;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-24 09:34:53 +02:00
|
|
|
void display()
|
|
|
|
{
|
2019-10-07 18:46:35 +02:00
|
|
|
manage_inputs();
|
|
|
|
|
2019-09-24 09:34:53 +02:00
|
|
|
float angleY = 1*timer_ticks;
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
|
|
|
|
|
|
|
glMatrixMode(GL_PROJECTION);
|
|
|
|
// Prepare view
|
|
|
|
glLoadIdentity();
|
|
|
|
gluPerspective(60,(double)glutGet(GLUT_WINDOW_WIDTH)/(double)glutGet(GLUT_WINDOW_HEIGHT),10,30000);
|
|
|
|
|
|
|
|
glMatrixMode(GL_MODELVIEW);
|
|
|
|
glLoadIdentity();
|
2019-10-14 21:48:49 +02:00
|
|
|
gluLookAt(10, 7.5, 10,
|
2019-09-24 09:34:53 +02:00
|
|
|
0, 0, 1,
|
|
|
|
0, 1, 0);
|
|
|
|
|
|
|
|
|
2019-09-24 11:34:40 +02:00
|
|
|
display_rotating_pyramid(-5,-2,-5,2,4,angleY);
|
|
|
|
display_rotating_pyramid(5,-2,0,1,5,angleY);
|
2019-09-24 09:34:53 +02:00
|
|
|
display_rotating_pyramid(-2,-2,4,3,2,angleY);
|
|
|
|
|
2019-09-25 00:36:57 +02:00
|
|
|
display_tree(0,-5,0,3,5,tree_texture);
|
|
|
|
|
2019-09-30 19:20:10 +02:00
|
|
|
glPushMatrix();
|
|
|
|
glRotatef(angleY,0,-1,0);
|
2019-09-30 16:52:04 +02:00
|
|
|
raptor.draw_model();
|
2019-09-30 19:20:10 +02:00
|
|
|
glPopMatrix();
|
2019-09-30 16:52:04 +02:00
|
|
|
|
2019-09-24 09:34:53 +02:00
|
|
|
glutSwapBuffers();
|
|
|
|
}
|
|
|
|
|
|
|
|
void update_angle(int value)
|
|
|
|
{
|
|
|
|
timer_ticks++;
|
|
|
|
glutTimerFunc(50,update_angle,0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char** argv)
|
|
|
|
{
|
|
|
|
glutInit(&argc,argv);
|
|
|
|
// Generate window with GLUT
|
|
|
|
glutInitDisplayMode(GLUT_RGB| GLUT_DEPTH | GLUT_DOUBLE);
|
|
|
|
glutCreateWindow("Hello");
|
2019-10-07 18:46:35 +02:00
|
|
|
glutIgnoreKeyRepeat(true);
|
2019-09-24 09:34:53 +02:00
|
|
|
|
|
|
|
// Init OpenGL
|
|
|
|
glClearColor(0,0,0,1);
|
|
|
|
glClearDepth(1.0);
|
|
|
|
// glEnable(GL_LIGHTING);
|
|
|
|
// glEnable(GL_LIGHT0);
|
|
|
|
glEnable(GL_DEPTH_TEST);
|
|
|
|
|
2019-09-25 00:36:57 +02:00
|
|
|
// Setup OPenGL to use textures
|
|
|
|
glEnable(GL_TEXTURE_2D);
|
|
|
|
glAlphaFunc(GL_GREATER, 0.5);
|
|
|
|
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_NEAREST);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT/GL_CLAMP);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT/GL_CLAMP);
|
|
|
|
glTexEnvi(GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
|
|
|
|
|
|
|
// Load and generate tree texture
|
2019-09-25 13:02:24 +02:00
|
|
|
tree_texture.load_rgba_tga("resources/arbre.tga","resources/arbre_masque.tga");
|
2019-09-25 00:36:57 +02:00
|
|
|
glGenTextures(1,tree_texture.opengl_id);
|
2019-09-30 16:52:04 +02:00
|
|
|
// TODO : Put in the Texture class
|
2019-09-25 00:36:57 +02:00
|
|
|
glBindTexture(GL_TEXTURE_2D,tree_texture.opengl_id[0]);
|
2019-09-25 13:02:24 +02:00
|
|
|
gluBuild2DMipmaps(GL_TEXTURE_2D,GL_RGBA8,tree_texture.width,tree_texture.height,GL_RGBA,GL_UNSIGNED_BYTE,tree_texture.image_data);
|
2019-09-25 00:36:57 +02:00
|
|
|
|
2019-09-30 19:20:10 +02:00
|
|
|
// Load and generate raptor texture
|
|
|
|
raptor_texture.load_rgb_tga("resources/RAPTOR.tga");
|
|
|
|
glGenTextures(1, raptor_texture.opengl_id);
|
|
|
|
// TODO : Put in the Texture class
|
|
|
|
glBindTexture(GL_TEXTURE_2D, raptor_texture.opengl_id[0]);
|
|
|
|
gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB8, raptor_texture.width, raptor_texture.height, GL_RGB, GL_UNSIGNED_BYTE, raptor_texture.image_data);
|
|
|
|
|
|
|
|
|
2019-09-30 16:52:04 +02:00
|
|
|
raptor.load_ascii_off_file("resources/RAPTOR.off");
|
2019-09-30 19:20:10 +02:00
|
|
|
raptor.assign_texture(raptor_texture);
|
2019-09-30 16:52:04 +02:00
|
|
|
raptor.set_scaling(0.01,0.01,0.01);
|
|
|
|
raptor.set_rotation(-90,1,0,0);
|
|
|
|
|
2019-09-24 09:34:53 +02:00
|
|
|
glViewport(0,0,glutGet(GLUT_WINDOW_WIDTH),glutGet(GLUT_WINDOW_HEIGHT));
|
|
|
|
|
2019-10-12 15:01:38 +02:00
|
|
|
glutDisplayFunc(display);
|
2019-09-24 09:34:53 +02:00
|
|
|
glutIdleFunc(display);
|
|
|
|
glutTimerFunc(50,update_angle,0);
|
2019-10-07 18:46:35 +02:00
|
|
|
KeyStateManager::register_glut_callbacks();
|
2019-09-24 09:34:53 +02:00
|
|
|
|
|
|
|
// Enters main loop, managed by GLUT
|
|
|
|
glutMainLoop();
|
|
|
|
return 0;
|
|
|
|
}
|