176 lines
5.1 KiB
C++
176 lines
5.1 KiB
C++
#include "Render.h"
|
|
#include "Global.h"
|
|
#include "Utils.h"
|
|
#include "Physics.h"
|
|
#include "teksturowane.hpp"
|
|
#include "fabula.hpp"
|
|
#include "GL/wglew.h"
|
|
#include "Logger.hpp"
|
|
|
|
// Zmienne do monitorowania rozmiaru
|
|
static GLsizei lastHeight;
|
|
static GLsizei lastWidth;
|
|
|
|
void ChangeSize(GLsizei w, GLsizei h) {
|
|
if (h == 0) h = 1;
|
|
lastWidth = w;
|
|
lastHeight = h;
|
|
GLfloat fAspect = (GLfloat)w / (GLfloat)h;
|
|
glViewport(0, 0, w, h);
|
|
glMatrixMode(GL_PROJECTION);
|
|
glLoadIdentity();
|
|
gluPerspective(45.0f, fAspect, 1.0f, 2000.0f);
|
|
glMatrixMode(GL_MODELVIEW);
|
|
glLoadIdentity();
|
|
}
|
|
|
|
void SetupRC() {
|
|
// Podstawowa konfiguracja OpenGL
|
|
glEnable(GL_DEPTH_TEST);
|
|
glFrontFace(GL_CCW);
|
|
glDepthFunc(GL_LESS);
|
|
glEnable(GL_MULTISAMPLE);
|
|
glEnable(GL_LINE_SMOOTH);
|
|
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
|
|
glEnable(GL_NORMALIZE);
|
|
|
|
// Oświetlenie
|
|
GLfloat ambientLight[] = { 0.4f, 0.4f, 0.4f, 1.0f };
|
|
GLfloat diffuseLight[] = { 0.9f, 0.9f, 0.8f, 1.0f };
|
|
GLfloat specular[] = { 0.5f, 0.5f, 0.5f, 1.0f };
|
|
GLfloat sunPos[] = { 100.0f, 150.0f, 100.0f, 0.0f };
|
|
GLfloat fillPos[] = { -100.0f, 50.0f, -100.0f, 0.0f };
|
|
GLfloat fillDiffuse[] = { 0.3f, 0.3f, 0.4f, 1.0f };
|
|
|
|
glEnable(GL_LIGHTING);
|
|
glLightfv(GL_LIGHT0, GL_AMBIENT, ambientLight);
|
|
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseLight);
|
|
glLightfv(GL_LIGHT0, GL_SPECULAR, specular);
|
|
glLightfv(GL_LIGHT0, GL_POSITION, sunPos);
|
|
glEnable(GL_LIGHT0);
|
|
|
|
glLightfv(GL_LIGHT1, GL_AMBIENT, ambientLight);
|
|
glLightfv(GL_LIGHT1, GL_DIFFUSE, fillDiffuse);
|
|
glLightfv(GL_LIGHT1, GL_POSITION, fillPos);
|
|
glEnable(GL_LIGHT1);
|
|
|
|
glEnable(GL_COLOR_MATERIAL);
|
|
glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
|
|
|
|
GLfloat specref2[] = { 0.1f, 0.1f, 0.1f, 1.0f };
|
|
glMaterialfv(GL_FRONT, GL_SPECULAR, specref2);
|
|
glMateriali(GL_FRONT, GL_SHININESS, 10);
|
|
glClearColor(0.53f, 0.81f, 0.92f, 1.0f);
|
|
|
|
// Inicjalizacja GLEW
|
|
glewExperimental = true;
|
|
if (glewInit() != GLEW_OK) {
|
|
GAME_LOG("Failed to initialize GLEW");
|
|
return;
|
|
}
|
|
|
|
if (wglewIsSupported("WGL_EXT_swap_control")) wglSwapIntervalEXT(0);
|
|
if (!glfwInit()) GAME_LOG("Failed to initialize GLFW");
|
|
|
|
user.loadModel();
|
|
mapa.loadModel();
|
|
glfwSwapInterval(0);
|
|
}
|
|
|
|
void RenderScene() {
|
|
glEnable(GL_MULTISAMPLE);
|
|
glEnable(GL_NORMALIZE);
|
|
glLoadIdentity();
|
|
|
|
switch (polygonmode) {
|
|
case 1: glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); break;
|
|
default: glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
|
}
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
|
dayNight.apply();
|
|
|
|
// Kamera
|
|
float rad = Rotation * GL_PI / 180.0f;
|
|
if (panoramic_view) {
|
|
gluLookAt(Foward, 400.0f, Sides, Foward, 0.0f, Sides, 1.0f, 0.0f, 0.0f);
|
|
}
|
|
else if (fpv_view) {
|
|
float lookAtX = Foward - 10.0f * sin(rad);
|
|
float lookAtZ = Sides - 10.0f * cos(rad);
|
|
gluLookAt(Foward, 15.0f, Sides, lookAtX, 15.0f, lookAtZ, 0.0f, 1.0f, 0.0f);
|
|
}
|
|
else {
|
|
float camX = Foward + CameraHeight * sin(rad);
|
|
float camZ = Sides + CameraHeight * cos(rad);
|
|
gluLookAt(camX, CameraHeight * 0.4f, camZ, Foward, 10.0f, Sides, 0.0f, 1.0f, 0.0f);
|
|
}
|
|
|
|
glRotatef(xRot, 1.0f, 0.0f, 0.0f);
|
|
glRotatef(yRot, 0.0f, 1.0f, 0.0f);
|
|
glRotatef(zRot, 0.0f, 0.0f, 1.0f);
|
|
|
|
// Rysowanie podstawy
|
|
glPushMatrix();
|
|
glColor3d(0.031, 0.51, 0.094);
|
|
platforma(450.0f, 0.0f, -45.0f, 450.0f, 45.0f);
|
|
glPopMatrix();
|
|
|
|
short grid_x, grid_z;
|
|
ustalPozycjeGracza(Foward, Sides, grid_x, grid_z);
|
|
ustawSiatkeNaWzorNieNadpisujacPostepu();
|
|
aktualizujBiezacaKratke(grid_x, grid_z);
|
|
tworzKratkiZSiatki();
|
|
|
|
// Rysowanie Cieni
|
|
{
|
|
GLfloat lightPos[] = { 100.0f, 150.0f, 100.0f, 0.0f };
|
|
GLfloat groundPlane[] = { 0.0f, 1.0f, 0.0f, 0.15f }; // Lekko podniesiony
|
|
GLfloat shadowMatrix[16];
|
|
MakeShadowMatrix(shadowMatrix, groundPlane, lightPos);
|
|
|
|
glPushMatrix();
|
|
glMultMatrixf(shadowMatrix);
|
|
glDisable(GL_LIGHTING);
|
|
glDisable(GL_TEXTURE_2D);
|
|
glDisable(GL_DEPTH_TEST);
|
|
glEnable(GL_BLEND);
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
glColor4f(0.0f, 0.0f, 0.0f, 0.5f); // Półprzezroczysty
|
|
|
|
glPushMatrix();
|
|
glTranslatef(Foward, 0.0f, Sides);
|
|
glRotatef(Rotation, 0.0f, 1.0f, 0.0f);
|
|
user.draw();
|
|
glPopMatrix();
|
|
|
|
glDisable(GL_BLEND);
|
|
glEnable(GL_DEPTH_TEST);
|
|
glEnable(GL_TEXTURE_2D);
|
|
glEnable(GL_LIGHTING);
|
|
glPopMatrix();
|
|
}
|
|
|
|
// Rysowanie Łazika
|
|
glPushMatrix();
|
|
glTranslatef(Foward, 0.0f, Sides);
|
|
glRotatef(Rotation, 0.0f, 1.0f, 0.0f);
|
|
glColor3f(1.0f, 1.0f, 1.0f);
|
|
user.draw();
|
|
UpdateRover(fences);
|
|
fpsCounter.update();
|
|
glPopMatrix();
|
|
|
|
// Inne obiekty
|
|
stodola(45.0f, 0.0f, -45.0f, 70.0f);
|
|
plot(450.0f, 3.0f, -90.0f, 900.0f, 4.0f, 1);
|
|
plot(0.0f, 3.0f, 405.0f, 990.0f, 4.0f, 0);
|
|
plot(450.0f, 3.0f, 10 * 90.0f, 900.0f, 4.0f, 1);
|
|
plot(10 * 90.0f, 3.0f, 405.0f, 990.0f, 4.0f, 0);
|
|
|
|
// Deszcz
|
|
rainSystem.update(deltaTime, Foward, Sides);
|
|
rainSystem.draw();
|
|
|
|
glFlush();
|
|
} |