Zigonnage et tests à saveur de Twin Peaks.
This commit is contained in:
parent
c34d0a0ef5
commit
2324ef071b
@ -13,32 +13,32 @@ Engine::~Engine()
|
||||
|
||||
void Engine::Init()
|
||||
{
|
||||
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
gluPerspective(45.0f, (float)Width() / (float)Height(), 0.0001f, 1000.0f);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
|
||||
glShadeModel(GL_SMOOTH);
|
||||
glEnable(GL_LIGHTING);
|
||||
glEnable(GL_LINE_SMOOTH);
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
gluPerspective(45.0f, (float)Width() / (float)Height(), 0.0001f, 1000.0f);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
|
||||
glShadeModel(GL_SMOOTH);
|
||||
glEnable(GL_LIGHTING);
|
||||
glEnable(GL_LINE_SMOOTH);
|
||||
|
||||
// Light
|
||||
GLfloat light0Pos[4] = { 0.0f, CHUNK_SIZE_Y, 0.0f, 1.0f };
|
||||
GLfloat light0Amb[4] = { 0.9f, 0.9f, 0.9f, 1.0f };
|
||||
GLfloat light0Diff[4] = { 1.0f, 1.0f, 1.0f, 1.0f };
|
||||
GLfloat light0Spec[4] = { 0.2f, 0.2f, 0.2f, 1.0f };
|
||||
// Light
|
||||
GLfloat light0Pos[4] = { 0.0f, CHUNK_SIZE_Y, 0.0f, 1.0f };
|
||||
GLfloat light0Amb[4] = { 0.9f, 0.9f, 0.9f, 1.0f };
|
||||
GLfloat light0Diff[4] = { 1.0f, 1.0f, 1.0f, 1.0f };
|
||||
GLfloat light0Spec[4] = { 0.2f, 0.2f, 0.2f, 1.0f };
|
||||
|
||||
glEnable(GL_LIGHT0);
|
||||
glLightfv(GL_LIGHT0, GL_POSITION, light0Pos);
|
||||
glLightfv(GL_LIGHT0, GL_AMBIENT, light0Amb);
|
||||
glLightfv(GL_LIGHT0, GL_DIFFUSE, light0Diff);
|
||||
glLightfv(GL_LIGHT0, GL_SPECULAR, light0Spec);
|
||||
glEnable(GL_LIGHT0);
|
||||
glLightfv(GL_LIGHT0, GL_POSITION, light0Pos);
|
||||
glLightfv(GL_LIGHT0, GL_AMBIENT, light0Amb);
|
||||
glLightfv(GL_LIGHT0, GL_DIFFUSE, light0Diff);
|
||||
glLightfv(GL_LIGHT0, GL_SPECULAR, light0Spec);
|
||||
|
||||
CenterMouse();
|
||||
HideCursor();
|
||||
CenterMouse();
|
||||
HideCursor();
|
||||
}
|
||||
|
||||
void Engine::DeInit()
|
||||
@ -47,7 +47,9 @@ void Engine::DeInit()
|
||||
|
||||
void Engine::LoadResource()
|
||||
{
|
||||
LoadTexture(m_textureFloor, TEXTURE_PATH "checker.png");
|
||||
LoadTexture(m_textureFloor, TEXTURE_PATH "floortile.png");
|
||||
LoadTexture(m_textureSkybox, TEXTURE_PATH "curtains.png");
|
||||
LoadTexture(m_textureCube, TEXTURE_PATH "kyle.png");
|
||||
}
|
||||
|
||||
void Engine::UnloadResource()
|
||||
@ -56,116 +58,220 @@ void Engine::UnloadResource()
|
||||
|
||||
void Engine::Render(float elapsedTime)
|
||||
{
|
||||
static float gameTime = elapsedTime;
|
||||
static float gameTime = elapsedTime;
|
||||
|
||||
gameTime += elapsedTime;
|
||||
gameTime += elapsedTime;
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
// Transformations initiales
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
// Transformations initiales
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
|
||||
// Plancher
|
||||
// Les vertex doivent etre affiches dans le sens anti-horaire (CCW)
|
||||
m_textureFloor.Bind();
|
||||
float nbRep = 50.f;
|
||||
glBegin(GL_QUADS);
|
||||
glNormal3f(0, 1, 0); // Normal vector
|
||||
glTexCoord2f(0, 0);
|
||||
glVertex3f(-100.f, -2.f, 100.f);
|
||||
glTexCoord2f(nbRep, 0);
|
||||
glVertex3f(100.f, -2.f, 100.f);
|
||||
glTexCoord2f(nbRep, nbRep);
|
||||
glVertex3f(100.f, -2.f, -100.f);
|
||||
glTexCoord2f(0, nbRep);
|
||||
glVertex3f(-100.f, -2.f, -100.f);
|
||||
glEnd();
|
||||
|
||||
// Skybox
|
||||
m_textureSkybox.Bind();
|
||||
glDepthFunc(GL_ALWAYS);
|
||||
glBegin(GL_QUADS);
|
||||
|
||||
glTexCoord2f(1, 0);
|
||||
glVertex3f(10.f, 10.f, 10.f);
|
||||
glTexCoord2f(0, 0);
|
||||
glVertex3f(-10.f, 10.f, 10.f);
|
||||
glTexCoord2f(0, 1);
|
||||
glVertex3f(-10.f, -10.f, 10.f);
|
||||
glTexCoord2f(1, 1);
|
||||
glVertex3f(10.f, -10.f, 10.f);
|
||||
|
||||
glTexCoord2f(1, 0);
|
||||
glVertex3f(10.f, -10.f, -10.f);
|
||||
glTexCoord2f(0, 0);
|
||||
glVertex3f(-10.f, -10.f, -10.f);
|
||||
glTexCoord2f(0, 1);
|
||||
glVertex3f(-10.f, 10.f, -10.f);
|
||||
glTexCoord2f(1, 1);
|
||||
glVertex3f(10.f, 10.f, -10.f);
|
||||
|
||||
glTexCoord2f(1, 0);
|
||||
glVertex3f(-10.f, 10.f, 10.f);
|
||||
glTexCoord2f(0, 0);
|
||||
glVertex3f(-10.f, 10.f, -10.f);
|
||||
glTexCoord2f(0, 1);
|
||||
glVertex3f(-10.f, -10.f, -10.f);
|
||||
glTexCoord2f(1, 1);
|
||||
glVertex3f(-10.f, -10.f, 10.f);
|
||||
|
||||
glTexCoord2f(1, 0);
|
||||
glVertex3f(10.f, 10.f, -10.f);
|
||||
glTexCoord2f(0, 0);
|
||||
glVertex3f(10.f, 10.f, 10.f);
|
||||
glTexCoord2f(0, 1);
|
||||
glVertex3f(10.f, -10.f, 10.f);
|
||||
glTexCoord2f(1, 1);
|
||||
glVertex3f(10.f, -10.f, -10.f);
|
||||
glEnd();
|
||||
|
||||
// Plancher
|
||||
// Les vertex doivent etre affiches dans le sens anti-horaire (CCW)
|
||||
m_textureFloor.Bind();
|
||||
float nbRep = 50.f;
|
||||
glBegin(GL_QUADS);
|
||||
glNormal3f(0, 1, 0); // Normal vector
|
||||
glTexCoord2f(0, 0);
|
||||
glVertex3f(-100.f, -2.f, 100.f);
|
||||
glTexCoord2f(nbRep, 0);
|
||||
glVertex3f(100.f, -2.f, 100.f);
|
||||
glTexCoord2f(nbRep, nbRep);
|
||||
glVertex3f(100.f, -2.f, -100.f);
|
||||
glTexCoord2f(0, nbRep);
|
||||
glVertex3f(-100.f, -2.f, -100.f);
|
||||
glEnd();
|
||||
|
||||
// Cube
|
||||
glTranslatef(0.f, 0.f, -7.f);
|
||||
m_textureCube.Bind();
|
||||
glBegin(GL_QUADS);
|
||||
glDepthFunc(GL_GREATER);
|
||||
|
||||
glTexCoord2f(1, 0);
|
||||
glVertex3f(1.f, 1.f, -1.f);
|
||||
glTexCoord2f(0, 0);
|
||||
glVertex3f(-1.f, 1.f, -1.f);
|
||||
glTexCoord2f(0, 1);
|
||||
glVertex3f(-1.f, 1.f, 1.f);
|
||||
glTexCoord2f(1, 1);
|
||||
glVertex3f(1.f, 1.f, 1.f);
|
||||
|
||||
glTexCoord2f(1, 0);
|
||||
glVertex3f(1.f, -1.f, 1.f);
|
||||
glTexCoord2f(0, 0);
|
||||
glVertex3f(-1.f, -1.f, 1.f);
|
||||
glTexCoord2f(0, 1);
|
||||
glVertex3f(-1.f, -1.f, -1.f);
|
||||
glTexCoord2f(1, 1);
|
||||
glVertex3f(1.f, -1.f, -1.f);
|
||||
|
||||
glTexCoord2f(1, 0);
|
||||
glVertex3f(1.f, 1.f, 1.f);
|
||||
glTexCoord2f(0, 0);
|
||||
glVertex3f(-1.f, 1.f, 1.f);
|
||||
glTexCoord2f(0, 1);
|
||||
glVertex3f(-1.f, -1.f, 1.f);
|
||||
glTexCoord2f(1, 1);
|
||||
glVertex3f(1.f, -1.f, 1.f);
|
||||
|
||||
glTexCoord2f(1, 0);
|
||||
glVertex3f(1.f, -1.f, -1.f);
|
||||
glTexCoord2f(0, 0);
|
||||
glVertex3f(-1.f, -1.f, -1.f);
|
||||
glTexCoord2f(0, 1);
|
||||
glVertex3f(-1.f, 1.f, -1.f);
|
||||
glTexCoord2f(1, 1);
|
||||
glVertex3f(1.f, 1.f, -1.f);
|
||||
|
||||
glTexCoord2f(1, 0);
|
||||
glVertex3f(-1.f, 1.f, 1.f);
|
||||
glTexCoord2f(0, 0);
|
||||
glVertex3f(-1.f, 1.f, -1.f);
|
||||
glTexCoord2f(0, 1);
|
||||
glVertex3f(-1.f, -1.f, -1.f);
|
||||
glTexCoord2f(1, 1);
|
||||
glVertex3f(-1.f, -1.f, 1.f);
|
||||
|
||||
glTexCoord2f(1, 0);
|
||||
glVertex3f(1.f, 1.f, -1.f);
|
||||
glTexCoord2f(0, 0);
|
||||
glVertex3f(1.f, 1.f, 1.f);
|
||||
glTexCoord2f(0, 1);
|
||||
glVertex3f(1.f, -1.f, 1.f);
|
||||
glTexCoord2f(1, 1);
|
||||
glVertex3f(1.f, -1.f, -1.f);
|
||||
glEnd();
|
||||
}
|
||||
|
||||
void Engine::KeyPressEvent(unsigned char key)
|
||||
{
|
||||
switch(key)
|
||||
{
|
||||
case 36: // ESC
|
||||
Stop();
|
||||
break;
|
||||
case 94: // F10
|
||||
SetFullscreen(!IsFullscreen());
|
||||
break;
|
||||
case 22: // W
|
||||
if (!m_keyW) {
|
||||
std::cout << "W " << std::endl;
|
||||
m_keyW = true;
|
||||
}
|
||||
break;
|
||||
case 0: // A
|
||||
if (!m_keyA) {
|
||||
std::cout << "A " << std::endl;
|
||||
m_keyA = true;
|
||||
}
|
||||
break;
|
||||
case 18: // S
|
||||
if (!m_keyS) {
|
||||
std::cout << "S " << std::endl;
|
||||
m_keyS = true;
|
||||
}
|
||||
break;
|
||||
case 3: // D
|
||||
if (!m_keyD) {
|
||||
std::cout << "D " << std::endl;
|
||||
m_keyD = true;
|
||||
}
|
||||
break;
|
||||
case 24: // Y - Ignorer
|
||||
case 255: // Fn - Ignorer
|
||||
break;
|
||||
default:
|
||||
std::cout << "Unhandled key: " << (int)key << std::endl;
|
||||
}
|
||||
switch (key)
|
||||
{
|
||||
case 36: // ESC
|
||||
Stop();
|
||||
break;
|
||||
case 94: // F10
|
||||
SetFullscreen(!IsFullscreen());
|
||||
break;
|
||||
case 22: // W
|
||||
if (!m_keyW) {
|
||||
std::cout << "W " << std::endl;
|
||||
m_keyW = true;
|
||||
}
|
||||
break;
|
||||
case 0: // A
|
||||
if (!m_keyA) {
|
||||
std::cout << "A " << std::endl;
|
||||
m_keyA = true;
|
||||
}
|
||||
break;
|
||||
case 18: // S
|
||||
if (!m_keyS) {
|
||||
std::cout << "S " << std::endl;
|
||||
m_keyS = true;
|
||||
}
|
||||
break;
|
||||
case 3: // D
|
||||
if (!m_keyD) {
|
||||
std::cout << "D " << std::endl;
|
||||
m_keyD = true;
|
||||
}
|
||||
break;
|
||||
case 24: // Y - Ignorer
|
||||
case 255: // Fn - Ignorer
|
||||
break;
|
||||
default:
|
||||
std::cout << "Unhandled key: " << (int)key << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void Engine::KeyReleaseEvent(unsigned char key)
|
||||
{
|
||||
switch(key)
|
||||
{
|
||||
case 24: // Y
|
||||
m_wireframe = !m_wireframe;
|
||||
if(m_wireframe)
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
||||
else
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||
break;
|
||||
case 22: // W
|
||||
std::cout << "rW " << std::endl;
|
||||
m_keyW = false;
|
||||
break;
|
||||
case 0: // A
|
||||
std::cout << "rA "<< std::endl;
|
||||
m_keyA = false;
|
||||
break;
|
||||
case 18: // S
|
||||
std::cout << "rS "<< std::endl;
|
||||
m_keyS = false;
|
||||
break;
|
||||
case 3: // D
|
||||
std::cout << "rD " << std::endl;
|
||||
m_keyD = false;
|
||||
break;
|
||||
}
|
||||
switch (key)
|
||||
{
|
||||
case 24: // Y
|
||||
m_wireframe = !m_wireframe;
|
||||
if (m_wireframe)
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
||||
else
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||
break;
|
||||
case 22: // W
|
||||
std::cout << "rW " << std::endl;
|
||||
m_keyW = false;
|
||||
break;
|
||||
case 0: // A
|
||||
std::cout << "rA " << std::endl;
|
||||
m_keyA = false;
|
||||
break;
|
||||
case 18: // S
|
||||
std::cout << "rS " << std::endl;
|
||||
m_keyS = false;
|
||||
break;
|
||||
case 3: // D
|
||||
std::cout << "rD " << std::endl;
|
||||
m_keyD = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Engine::MouseMoveEvent(int x, int y)
|
||||
{
|
||||
// Centrer la souris seulement si elle n'est pas déjà centrée
|
||||
// Il est nécessaire de faire la vérification pour éviter de tomber
|
||||
// dans une boucle infinie où l'appel à CenterMouse génère un
|
||||
// MouseMoveEvent, qui rapelle CenterMouse qui rapelle un autre
|
||||
// MouseMoveEvent, etc
|
||||
if(x == (Width() / 2) && y == (Height() / 2))
|
||||
return;
|
||||
// Centrer la souris seulement si elle n'est pas déjà centrée
|
||||
// Il est nécessaire de faire la vérification pour éviter de tomber
|
||||
// dans une boucle infinie où l'appel à CenterMouse génère un
|
||||
// MouseMoveEvent, qui rapelle CenterMouse qui rapelle un autre
|
||||
// MouseMoveEvent, etc
|
||||
if (x == (Width() / 2) && y == (Height() / 2))
|
||||
return;
|
||||
|
||||
CenterMouse();
|
||||
CenterMouse();
|
||||
}
|
||||
|
||||
void Engine::MousePressEvent(const MOUSE_BUTTON& button, int x, int y)
|
||||
@ -178,15 +284,15 @@ void Engine::MouseReleaseEvent(const MOUSE_BUTTON& button, int x, int y)
|
||||
|
||||
bool Engine::LoadTexture(Texture& texture, const std::string& filename, bool stopOnError)
|
||||
{
|
||||
texture.Load(filename);
|
||||
if(!texture.IsValid())
|
||||
{
|
||||
std::cerr << "Unable to load texture (" << filename << ")" << std::endl;
|
||||
if(stopOnError)
|
||||
Stop();
|
||||
texture.Load(filename);
|
||||
if (!texture.IsValid())
|
||||
{
|
||||
std::cerr << "Unable to load texture (" << filename << ")" << std::endl;
|
||||
if (stopOnError)
|
||||
Stop();
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include "define.h"
|
||||
#include "openglcontext.h"
|
||||
#include "texture.h"
|
||||
#include "transformation.h"
|
||||
|
||||
class Engine : public OpenglContext
|
||||
{
|
||||
@ -27,6 +28,8 @@ private:
|
||||
bool m_wireframe = false;
|
||||
|
||||
Texture m_textureFloor;
|
||||
Texture m_textureSkybox;
|
||||
Texture m_textureCube;
|
||||
|
||||
bool m_keyW = false;
|
||||
bool m_keyA = false;
|
||||
|
BIN
mcclone/media/textures/curtain.png
Normal file
BIN
mcclone/media/textures/curtain.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 38 KiB |
BIN
mcclone/media/textures/curtains.png
Normal file
BIN
mcclone/media/textures/curtains.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 660 KiB |
BIN
mcclone/media/textures/floortile.png
Normal file
BIN
mcclone/media/textures/floortile.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 25 KiB |
BIN
mcclone/media/textures/kyle.png
Normal file
BIN
mcclone/media/textures/kyle.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 313 KiB |
@ -152,7 +152,7 @@ void OpenglContext::ShowCrossCursor() const
|
||||
|
||||
void OpenglContext::InitWindow(int width, int height)
|
||||
{
|
||||
m_app.create(sf::VideoMode(width, height, 32), m_title.c_str(), m_fullscreen ? sf::Style::Fullscreen : (sf::Style::Resize|sf::Style::Close), sf::ContextSettings(32, 8, 0));
|
||||
m_app.create(sf::VideoMode(width, height, 32), m_title.c_str(), m_fullscreen ? sf::Style::Fullscreen : (sf::Style::Resize|sf::Style::Close), sf::ContextSettings(32, 8, 4));
|
||||
}
|
||||
|
||||
OpenglContext::MOUSE_BUTTON OpenglContext::ConvertMouseButton(sf::Mouse::Button button) const
|
||||
|
Loading…
Reference in New Issue
Block a user