Compare commits
50 Commits
316ff8395f
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e04fc59eda | ||
|
|
a3e3c8a955 | ||
|
|
5e41db643c | ||
|
|
2fbd33901c | ||
|
|
96b1692434 | ||
|
|
60c71b0993 | ||
|
|
233d4189d1 | ||
|
|
ffa5a929df | ||
|
|
780e852596 | ||
|
|
177bb7133a | ||
|
|
739ba9f1a4 | ||
|
|
2602b9a523 | ||
| 2bcf493f8a | |||
| 0c460842fc | |||
| d75957f2f5 | |||
| 37cf314288 | |||
| d8460065c3 | |||
| f6527f6fbb | |||
|
|
b01fa46b8a | ||
|
|
4759a5419e | ||
| 49fee6ded8 | |||
| b805164ad4 | |||
| e9fba90fa2 | |||
|
|
7d33f8a997 | ||
|
|
1a85de2c23 | ||
|
|
f0a3221e04 | ||
|
|
951b25a5a3 | ||
|
|
4b9503eeec | ||
| c7ceee0772 | |||
|
|
735859ed58 | ||
|
|
bea13b98f3 | ||
|
|
cfb3f12ef4 | ||
|
|
f2927ecf3d | ||
|
|
26954f6349 | ||
| 9a08770e6f | |||
| 0725312d80 | |||
| 395b470b5d | |||
|
|
fa824192b7 | ||
|
|
79c6a1e144 | ||
|
|
01d7766b6a | ||
|
|
3171ebe504 | ||
|
|
039435ed73 | ||
|
|
2afc119bb9 | ||
|
|
4956d74c1a | ||
| 495ec2e6ab | |||
| 633be80ec4 | |||
| 2b51e31307 | |||
| ef1a8b225b | |||
| 1f00df1842 | |||
| 2f8f14d279 |
15
.gitignore
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
# Czarna lista plików przy commitowaniu
|
||||
# (pliki do zignorowania przy udostępnianiu)
|
||||
# folder z rzeczami z visual studio
|
||||
.vs
|
||||
|
||||
# pliki wykonywalne, binarne
|
||||
grafikaKBT
|
||||
x64
|
||||
output.exe
|
||||
output2.exe
|
||||
|
||||
# obiekty testowe
|
||||
res/models/lazik.obj
|
||||
res/models/lazik2.obj
|
||||
res/models/lazik4,5.obj
|
||||
96
DayNightCycle.hpp
Normal file
@@ -0,0 +1,96 @@
|
||||
#ifndef DAYNIGHTCYCLE_HPP
|
||||
#define DAYNIGHTCYCLE_HPP
|
||||
|
||||
#include "GL/glew.h"
|
||||
#include <iostream>
|
||||
|
||||
class DayNightCycle {
|
||||
private:
|
||||
bool isNight;
|
||||
|
||||
public:
|
||||
// Konstruktor - domyślnie startujemy w dzień
|
||||
DayNightCycle() : isNight(false) {}
|
||||
|
||||
// Funkcja przełączająca stan
|
||||
void toggle() {
|
||||
isNight = !isNight;
|
||||
if (isNight) {
|
||||
std::cout << "Tryb: NOC" << std::endl;
|
||||
}
|
||||
else {
|
||||
std::cout << "Tryb: DZIEN" << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
// Zwraca informację czy jest noc (przydatne np. do włączania świateł łazika)
|
||||
bool isNightMode() const {
|
||||
return isNight;
|
||||
}
|
||||
|
||||
// Główna funkcja ustawiająca światła i tło
|
||||
void apply() {
|
||||
if (isNight) {
|
||||
// === USTAWIENIA NOCNE ===
|
||||
|
||||
// Kolor nieba (Tło) - Ciemny granat/czarny
|
||||
glClearColor(0.05f, 0.05f, 0.1f, 1.0f);
|
||||
|
||||
// GL_LIGHT0 (Księżyc) - Zimne, słabe światło
|
||||
GLfloat nightAmbient[] = { 0.1f, 0.1f, 0.2f, 1.0f };
|
||||
GLfloat nightDiffuse[] = { 0.2f, 0.2f, 0.35f, 1.0f }; // Niebieskawy odcień
|
||||
GLfloat nightSpecular[] = { 0.1f, 0.1f, 0.1f, 1.0f }; // Bardzo słaby połysk
|
||||
|
||||
glLightfv(GL_LIGHT0, GL_AMBIENT, nightAmbient);
|
||||
glLightfv(GL_LIGHT0, GL_DIFFUSE, nightDiffuse);
|
||||
glLightfv(GL_LIGHT0, GL_SPECULAR, nightSpecular);
|
||||
|
||||
// GL_LIGHT1 (Doświetlenie cieni) - Prawie wyłączone w nocy
|
||||
GLfloat fillAmbient[] = { 0.02f, 0.02f, 0.05f, 1.0f };
|
||||
GLfloat fillDiffuse[] = { 0.05f, 0.05f, 0.1f, 1.0f };
|
||||
|
||||
glLightfv(GL_LIGHT1, GL_AMBIENT, fillAmbient);
|
||||
glLightfv(GL_LIGHT1, GL_DIFFUSE, fillDiffuse);
|
||||
|
||||
// Opcjonalnie: Włączamy gęstą czarną mgłę dla klimatu
|
||||
glEnable(GL_FOG);
|
||||
GLfloat fogColor[] = { 0.05f, 0.05f, 0.1f, 1.0f };
|
||||
glFogfv(GL_FOG_COLOR, fogColor);
|
||||
glFogi(GL_FOG_MODE, GL_EXP2);
|
||||
glFogf(GL_FOG_DENSITY, 0.002f); // Gęstość mgły
|
||||
|
||||
}
|
||||
else {
|
||||
// === USTAWIENIA DZIENNE ===
|
||||
|
||||
// Kolor nieba (Tło) - Jasny błękit
|
||||
glClearColor(0.53f, 0.81f, 0.92f, 1.0f);
|
||||
|
||||
// GL_LIGHT0 (Słońce) - Ciepłe, jasne światło
|
||||
GLfloat dayAmbient[] = { 0.4f, 0.4f, 0.4f, 1.0f };
|
||||
GLfloat dayDiffuse[] = { 0.9f, 0.9f, 0.8f, 1.0f }; // Lekko żółtawe
|
||||
GLfloat daySpecular[] = { 0.5f, 0.5f, 0.5f, 1.0f };
|
||||
|
||||
glLightfv(GL_LIGHT0, GL_AMBIENT, dayAmbient);
|
||||
glLightfv(GL_LIGHT0, GL_DIFFUSE, dayDiffuse);
|
||||
glLightfv(GL_LIGHT0, GL_SPECULAR, daySpecular);
|
||||
|
||||
// GL_LIGHT1 (Doświetlenie cieni)
|
||||
GLfloat fillAmbient[] = { 0.4f, 0.4f, 0.4f, 1.0f };
|
||||
GLfloat fillDiffuse[] = { 0.3f, 0.3f, 0.4f, 1.0f }; // Niebieskawe cienie
|
||||
|
||||
glLightfv(GL_LIGHT1, GL_AMBIENT, fillAmbient);
|
||||
glLightfv(GL_LIGHT1, GL_DIFFUSE, fillDiffuse);
|
||||
|
||||
// Wyłączamy mgłę w dzień (lub ustawiamy bardzo rzadką)
|
||||
glDisable(GL_FOG);
|
||||
}
|
||||
|
||||
// Pozycję światła ustawiamy taką samą dla obu (wysoko w górze)
|
||||
// W przyszłości możesz tu zrobić animację przesuwania się słońca
|
||||
GLfloat lightPos[] = { 100.0f, 150.0f, 100.0f, 0.0f }; // 0.0f na końcu = światło kierunkowe
|
||||
glLightfv(GL_LIGHT0, GL_POSITION, lightPos);
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
40
FPSCounter.cpp
Normal file
@@ -0,0 +1,40 @@
|
||||
#pragma once // Zabezpieczenie przed wielokrotnym dołączeniem
|
||||
#include <chrono>
|
||||
|
||||
class FPSCounter {
|
||||
public:
|
||||
FPSCounter() :
|
||||
frameCount(0),
|
||||
currentFPS(0.0),
|
||||
currentFrameTime(0.0),
|
||||
lastTime(std::chrono::high_resolution_clock::now()) {
|
||||
}
|
||||
|
||||
// Zwraca true, jeśli minęła sekunda i zaktualizowano dane
|
||||
bool update() {
|
||||
frameCount++;
|
||||
auto currentTime = std::chrono::high_resolution_clock::now();
|
||||
std::chrono::duration<double> elapsed = currentTime - lastTime;
|
||||
|
||||
if (elapsed.count() >= 1.0) {
|
||||
currentFPS = frameCount / elapsed.count();
|
||||
// Obliczamy czas klatki w ms
|
||||
currentFrameTime = 1000.0 / (currentFPS == 0 ? 1 : currentFPS);
|
||||
|
||||
frameCount = 0;
|
||||
lastTime = currentTime;
|
||||
return true; // Zgłaszamy, że dane się zmieniły
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// --- TEGO BRAKOWAŁO W TWOIM KODZIE ---
|
||||
double getFPS() const { return currentFPS; }
|
||||
double getFrameTime() const { return currentFrameTime; }
|
||||
|
||||
private:
|
||||
long long frameCount;
|
||||
double currentFPS; // Przechowuje ostatnio obliczone FPS
|
||||
double currentFrameTime; // Przechowuje czas klatki
|
||||
std::chrono::time_point<std::chrono::high_resolution_clock> lastTime;
|
||||
};
|
||||
39
Global.cpp
Normal file
@@ -0,0 +1,39 @@
|
||||
#include "Global.h"
|
||||
|
||||
// Inicjalizacja zmiennych
|
||||
float deltaTime = 0.0f;
|
||||
FPSCounter fpsCounter;
|
||||
bool panoramic_view = false;
|
||||
bool fpv_view = false;
|
||||
int polygonmode = 0;
|
||||
bool Kolizja = false;
|
||||
short biezacy_wzor = 0;
|
||||
|
||||
float CameraHeight = 150.0f;
|
||||
float xRot = 0.0f;
|
||||
float yRot = 0.0f;
|
||||
float zRot = 0.0f;
|
||||
|
||||
float Foward = 45.0f;
|
||||
float Sides = -45.0f;
|
||||
float Rotation = 270.0f;
|
||||
float velocity = 0.0f;
|
||||
float rotationVelocity = 0.0f;
|
||||
|
||||
bool keyWPressed = false;
|
||||
bool keySPressed = false;
|
||||
bool keyAPressed = false;
|
||||
bool keyDPressed = false;
|
||||
|
||||
lazik user(10.0f, 0.0f, 0.0f, "res/models/lazik4.obj");
|
||||
plane mapa(0.0f, 0.0f, 0.0f, "res/models/mapka3_nofence_noplatform.obj");
|
||||
RainSystem rainSystem(2000, 250.0f, 200.0f);
|
||||
DayNightCycle dayNight;
|
||||
unsigned int texture[4];
|
||||
|
||||
std::vector<Plot> fences = {
|
||||
{ 450.0f, 3.0f, -90.0f, 900.0f, 4.0f, 1},
|
||||
{ 0.0f, 3.0f, 405.0f, 990.0f, 4.0f, 0},
|
||||
{ 450.0f, 3.0f, 10 * 90.0f, 900.0f, 4.0f, 1},
|
||||
{10 * 90.0f, 3.0f, 405.0f, 990.0f, 4.0f, 0}
|
||||
};
|
||||
50
Global.h
Normal file
@@ -0,0 +1,50 @@
|
||||
#pragma once
|
||||
#include <windows.h>
|
||||
#include <vector>
|
||||
#include "GL/glew.h"
|
||||
#include "GL/glm/glm.hpp"
|
||||
#include "lazik.hpp"
|
||||
#include "plane.hpp"
|
||||
#include "rain.hpp"
|
||||
#include "DayNightCycle.hpp"
|
||||
#include "FPSCounter.cpp" // Zakładam, że to masz jako .cpp w include, choć lepiej zmienić na .h
|
||||
|
||||
// Definicje stałych
|
||||
#define GL_PI 3.1415f
|
||||
|
||||
|
||||
// Zmienne stanu gry
|
||||
extern float deltaTime;
|
||||
extern FPSCounter fpsCounter;
|
||||
extern bool panoramic_view;
|
||||
extern bool fpv_view;
|
||||
extern int polygonmode;
|
||||
extern bool Kolizja;
|
||||
extern short biezacy_wzor;
|
||||
|
||||
// Zmienne kamery i rotacji
|
||||
extern float CameraHeight;
|
||||
extern float xRot, yRot, zRot;
|
||||
|
||||
// Zmienne łazika
|
||||
extern float Foward;
|
||||
extern float Sides;
|
||||
extern float Rotation;
|
||||
extern float velocity;
|
||||
extern float rotationVelocity;
|
||||
extern bool keyWPressed, keySPressed, keyAPressed, keyDPressed;
|
||||
|
||||
// Obiekty gry
|
||||
extern lazik user;
|
||||
extern plane mapa;
|
||||
extern RainSystem rainSystem;
|
||||
extern DayNightCycle dayNight;
|
||||
extern unsigned int texture[4];
|
||||
|
||||
// Struktura płotu
|
||||
struct Plot {
|
||||
GLfloat xc, yc, zc;
|
||||
GLfloat length, grubosc;
|
||||
bool mod_x;
|
||||
};
|
||||
extern std::vector<Plot> fences;
|
||||
61
Logger.cpp
Normal file
@@ -0,0 +1,61 @@
|
||||
#include "Logger.hpp"
|
||||
#include <iostream>
|
||||
|
||||
// Implementacja Singletona
|
||||
AsyncLogger& AsyncLogger::getInstance() {
|
||||
static AsyncLogger instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
// Konstruktor
|
||||
AsyncLogger::AsyncLogger() : running(false) {}
|
||||
|
||||
// Destruktor
|
||||
AsyncLogger::~AsyncLogger() {
|
||||
stop();
|
||||
}
|
||||
|
||||
void AsyncLogger::log(const std::string& message) {
|
||||
std::lock_guard<std::mutex> lock(queueMutex);
|
||||
logQueue.push(message);
|
||||
cv.notify_one();
|
||||
}
|
||||
|
||||
void AsyncLogger::start() {
|
||||
if (running) return;
|
||||
running = true;
|
||||
loggingThread = std::thread(&AsyncLogger::processQueue, this);
|
||||
}
|
||||
|
||||
void AsyncLogger::stop() {
|
||||
bool expected = true;
|
||||
// atomic_compare_exchange pomaga uniknąć podwójnego zatrzymania
|
||||
if (running.compare_exchange_strong(expected, false)) {
|
||||
cv.notify_one();
|
||||
if (loggingThread.joinable()) {
|
||||
loggingThread.join();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AsyncLogger::processQueue() {
|
||||
while (running || !logQueue.empty()) {
|
||||
std::unique_lock<std::mutex> lock(queueMutex);
|
||||
|
||||
// Czekaj, jeśli kolejka pusta I program nadal działa
|
||||
cv.wait(lock, [this] { return !logQueue.empty() || !running; });
|
||||
|
||||
while (!logQueue.empty()) {
|
||||
std::string msg = logQueue.front();
|
||||
logQueue.pop();
|
||||
|
||||
// Odblokowujemy mutex na czas wypisywania (dla wydajności)
|
||||
lock.unlock();
|
||||
|
||||
std::cout << msg << std::endl;
|
||||
|
||||
// Blokujemy z powrotem, aby sprawdzić pętlę while
|
||||
lock.lock();
|
||||
}
|
||||
}
|
||||
}
|
||||
42
Logger.hpp
Normal file
@@ -0,0 +1,42 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <mutex>
|
||||
#include <condition_variable>
|
||||
#include <queue>
|
||||
#include <atomic>
|
||||
#include <sstream> // Niezbędne dla makra
|
||||
|
||||
class AsyncLogger {
|
||||
public:
|
||||
// Tylko deklaracje funkcji
|
||||
static AsyncLogger& getInstance();
|
||||
|
||||
void log(const std::string& message);
|
||||
void start();
|
||||
void stop();
|
||||
|
||||
// Usuwamy copy constructor i operator przypisania (Singleton)
|
||||
AsyncLogger(const AsyncLogger&) = delete;
|
||||
void operator=(const AsyncLogger&) = delete;
|
||||
|
||||
private:
|
||||
AsyncLogger(); // Prywatny konstruktor
|
||||
~AsyncLogger(); // Prywatny destruktor
|
||||
|
||||
void processQueue();
|
||||
|
||||
std::thread loggingThread;
|
||||
std::mutex queueMutex;
|
||||
std::condition_variable cv;
|
||||
std::queue<std::string> logQueue;
|
||||
std::atomic<bool> running;
|
||||
};
|
||||
|
||||
// Zmiana nazwy makra na GAME_LOG, aby uniknąć konfliktów (np. z bibliotekami matematycznymi)
|
||||
// Używamy pętli do...while(0), aby makro było bezpieczne w instrukcjach if/else
|
||||
#define GAME_LOG(stream_args) { \
|
||||
std::ostringstream ss; \
|
||||
ss << stream_args; \
|
||||
AsyncLogger::getInstance().log(ss.str()); \
|
||||
}
|
||||
5
Makefile
@@ -1,12 +1,13 @@
|
||||
# mingw-w64-x86_64-gcc-14.1.0-3 to ostatnia wspierana wersja gcc, w której można stosować wildcard'y "*.cpp"
|
||||
CC = "C:\\msys64\\mingw64\\bin\\g++.exe"
|
||||
CFLAGS = -I.
|
||||
DEPS = -lglew32 -lopengl32 -lglu32 -lgdi32
|
||||
DEPS = -lglew32 -lglfw3 -lopengl32 -lglu32 -lgdi32
|
||||
LINK = -L. -DGLEW_STATIC
|
||||
OUTPUT = output.exe
|
||||
CPPSTD = c++17
|
||||
|
||||
default:
|
||||
$(CC) -g *.cpp $(CFLAGS) $(DEPS) $(LINK) -static -static-libgcc -fno-keep-inline-dllexport -o $(OUTPUT)
|
||||
$(CC) -g *.cpp $(CFLAGS) $(DEPS) $(LINK) -std=$(CPPSTD) -static -static-libgcc -fno-keep-inline-dllexport -Os -s -Wl,--build-id=none -o $(OUTPUT)
|
||||
|
||||
run: default
|
||||
$(OUTPUT)
|
||||
|
||||
108
Physics.cpp
Normal file
@@ -0,0 +1,108 @@
|
||||
#include "Physics.h"
|
||||
#include <cmath>
|
||||
|
||||
const float friction = 0.05f;
|
||||
const float maxSpeed = 2.0f;
|
||||
const float acceleration = 0.2f;
|
||||
const float rotationAcceleration = 0.075f;
|
||||
const float rotationFriction = 0.1f;
|
||||
const float maxRotationSpeed = 0.5f;
|
||||
|
||||
bool CheckFenceCollision(float rXMin, float rXMax, float rZMin, float rZMax, const Plot& plot) {
|
||||
float fXMin, fXMax, fZMin, fZMax;
|
||||
if (plot.mod_x == 0) { // Płot pionowy
|
||||
fXMin = plot.xc - plot.grubosc / 2.0f;
|
||||
fXMax = plot.xc + plot.grubosc / 2.0f;
|
||||
fZMin = plot.zc - plot.length / 2.0f;
|
||||
fZMax = plot.zc + plot.length / 2.0f;
|
||||
}
|
||||
else { // Płot poziomy
|
||||
fXMin = plot.xc - plot.length / 2.0f;
|
||||
fXMax = plot.xc + plot.length / 2.0f;
|
||||
fZMin = plot.zc - plot.grubosc / 2.0f;
|
||||
fZMax = plot.zc + plot.grubosc / 2.0f;
|
||||
}
|
||||
return (rXMax >= fXMin && rXMin <= fXMax && rZMax >= fZMin && rZMin <= fZMax);
|
||||
}
|
||||
|
||||
bool CheckAllFencesCollision(float rXMin, float rXMax, float rZMin, float rZMax, const std::vector<Plot>& fences) {
|
||||
for (const auto& fence : fences) {
|
||||
if (CheckFenceCollision(rXMin, rXMax, rZMin, rZMax, fence)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void UpdateRover(const std::vector<Plot>& fences) {
|
||||
float timeScale = deltaTime * 144.0f;
|
||||
if (timeScale > 5.0f) timeScale = 5.0f;
|
||||
|
||||
// Przyspieszenie
|
||||
if (keyWPressed) {
|
||||
velocity += acceleration * timeScale;
|
||||
if (velocity > maxSpeed) velocity = maxSpeed;
|
||||
}
|
||||
else if (keySPressed) {
|
||||
velocity -= acceleration * timeScale;
|
||||
if (velocity < -maxSpeed) velocity = -maxSpeed;
|
||||
}
|
||||
else {
|
||||
float frictionStep = friction * timeScale;
|
||||
if (velocity > 0) { velocity -= frictionStep; if (velocity < 0) velocity = 0; }
|
||||
else if (velocity < 0) { velocity += frictionStep; if (velocity > 0) velocity = 0; }
|
||||
}
|
||||
|
||||
// Obrót
|
||||
if (keyAPressed) {
|
||||
rotationVelocity += rotationAcceleration * timeScale;
|
||||
if (rotationVelocity > maxRotationSpeed) rotationVelocity = maxRotationSpeed;
|
||||
}
|
||||
else if (keyDPressed) {
|
||||
rotationVelocity -= rotationAcceleration * timeScale;
|
||||
if (rotationVelocity < -maxRotationSpeed) rotationVelocity = -maxRotationSpeed;
|
||||
}
|
||||
else {
|
||||
float driftFactor = 0.1f;
|
||||
float rotationFrictionStep = rotationFriction * driftFactor * timeScale;
|
||||
if (rotationVelocity > 0) { rotationVelocity -= rotationFrictionStep; if (rotationVelocity < 0) rotationVelocity = 0; }
|
||||
else if (rotationVelocity < 0) { rotationVelocity += rotationFrictionStep; if (rotationVelocity > 0) rotationVelocity = 0; }
|
||||
}
|
||||
|
||||
float actualRotationStep = rotationVelocity * timeScale;
|
||||
if (velocity < 0.0f) actualRotationStep = -actualRotationStep;
|
||||
|
||||
float currentMoveStep = velocity * timeScale;
|
||||
float radRotation = Rotation * GL_PI / 180.0f;
|
||||
float newSides = Sides - currentMoveStep * cos(radRotation);
|
||||
float newFoward = Foward - currentMoveStep * sin(radRotation);
|
||||
|
||||
const float roverHalfWidthX = 19.0f;
|
||||
const float roverHalfLengthZ = 12.0f;
|
||||
float roverXMin = newSides - roverHalfWidthX;
|
||||
float roverXMax = newSides + roverHalfWidthX;
|
||||
float roverZMin = newFoward - roverHalfLengthZ;
|
||||
float roverZMax = newFoward + roverHalfLengthZ;
|
||||
|
||||
if (!Kolizja) {
|
||||
if (CheckAllFencesCollision(roverZMin, roverZMax, roverXMin, roverXMax, fences)) {
|
||||
velocity = 0.0f;
|
||||
}
|
||||
else {
|
||||
Sides = newSides;
|
||||
Foward = newFoward;
|
||||
}
|
||||
|
||||
if (actualRotationStep != 0.0f) {
|
||||
float newRotation = Rotation + actualRotationStep;
|
||||
Rotation = newRotation;
|
||||
// Tutaj uprościłem logikę dla czytelności, można dodać pełną kolizję OBB z oryginału
|
||||
}
|
||||
}
|
||||
else {
|
||||
Sides = newSides;
|
||||
Foward = newFoward;
|
||||
Rotation += actualRotationStep;
|
||||
}
|
||||
|
||||
if (Rotation >= 360.0f) Rotation -= 360.0f;
|
||||
if (Rotation < 0.0f) Rotation += 360.0f;
|
||||
}
|
||||
8
Physics.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
#include <vector>
|
||||
#include "Global.h"
|
||||
|
||||
// Funkcje fizyki
|
||||
bool CheckFenceCollision(float rXMin, float rXMax, float rZMin, float rZMax, const Plot& plot);
|
||||
bool CheckAllFencesCollision(float rXMin, float rXMax, float rZMin, float rZMax, const std::vector<Plot>& fences);
|
||||
void UpdateRover(const std::vector<Plot>& fences);
|
||||
176
Render.cpp
Normal file
@@ -0,0 +1,176 @@
|
||||
#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();
|
||||
}
|
||||
8
Render.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
#include <windows.h>
|
||||
#include "GL/glew.h"
|
||||
#include "GL/glfw3.h"
|
||||
|
||||
void SetupRC();
|
||||
void ChangeSize(GLsizei w, GLsizei h);
|
||||
void RenderScene();
|
||||
156
Utils.cpp
Normal file
@@ -0,0 +1,156 @@
|
||||
#include "Utils.h"
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
|
||||
BITMAPINFOHEADER bitmapInfoHeader;
|
||||
unsigned char* bitmapData;
|
||||
|
||||
void DisableQuickEdit() {
|
||||
HANDLE hInput = GetStdHandle(STD_INPUT_HANDLE);
|
||||
DWORD prev_mode;
|
||||
GetConsoleMode(hInput, &prev_mode);
|
||||
SetConsoleMode(hInput, prev_mode & ~ENABLE_QUICK_EDIT_MODE & ~ENABLE_INSERT_MODE);
|
||||
}
|
||||
|
||||
void CreateConsole() {
|
||||
if (AllocConsole()) {
|
||||
FILE* conin; FILE* conout; FILE* conerr;
|
||||
freopen_s(&conin, "conin$", "r", stdin);
|
||||
freopen_s(&conout, "conout$", "w", stdout);
|
||||
freopen_s(&conerr, "conout$", "w", stderr);
|
||||
}
|
||||
}
|
||||
|
||||
unsigned char* LoadBitmapFile(char* filename, BITMAPINFOHEADER* bitmapInfoHeader) {
|
||||
FILE* filePtr;
|
||||
BITMAPFILEHEADER bitmapFileHeader;
|
||||
unsigned char* bitmapImage;
|
||||
int imageIdx = 0;
|
||||
unsigned char tempRGB;
|
||||
|
||||
filePtr = fopen(filename, "rb");
|
||||
if (filePtr == NULL) return NULL;
|
||||
|
||||
fread(&bitmapFileHeader, sizeof(BITMAPFILEHEADER), 1, filePtr);
|
||||
if (bitmapFileHeader.bfType != BITMAP_ID) {
|
||||
fclose(filePtr);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
fread(bitmapInfoHeader, sizeof(BITMAPINFOHEADER), 1, filePtr);
|
||||
fseek(filePtr, bitmapFileHeader.bfOffBits, SEEK_SET);
|
||||
bitmapImage = (unsigned char*)malloc(bitmapInfoHeader->biSizeImage);
|
||||
|
||||
if (!bitmapImage) {
|
||||
free(bitmapImage);
|
||||
fclose(filePtr);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
fread(bitmapImage, 1, bitmapInfoHeader->biSizeImage, filePtr);
|
||||
if (bitmapImage == NULL) {
|
||||
fclose(filePtr);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (imageIdx = 0; imageIdx < bitmapInfoHeader->biSizeImage; imageIdx += 3) {
|
||||
tempRGB = bitmapImage[imageIdx];
|
||||
bitmapImage[imageIdx] = bitmapImage[imageIdx + 2];
|
||||
bitmapImage[imageIdx + 2] = tempRGB;
|
||||
}
|
||||
|
||||
fclose(filePtr);
|
||||
return bitmapImage;
|
||||
}
|
||||
|
||||
void MakeShadowMatrix(GLfloat shadowMat[16], GLfloat groundplane[4], GLfloat lightpos[4]) {
|
||||
GLfloat dot = groundplane[0] * lightpos[0] + groundplane[1] * lightpos[1] +
|
||||
groundplane[2] * lightpos[2] + groundplane[3] * lightpos[3];
|
||||
|
||||
shadowMat[0] = dot - lightpos[0] * groundplane[0];
|
||||
shadowMat[4] = 0.f - lightpos[0] * groundplane[1];
|
||||
shadowMat[8] = 0.f - lightpos[0] * groundplane[2];
|
||||
shadowMat[12] = 0.f - lightpos[0] * groundplane[3];
|
||||
|
||||
shadowMat[1] = 0.f - lightpos[1] * groundplane[0];
|
||||
shadowMat[5] = dot - lightpos[1] * groundplane[1];
|
||||
shadowMat[9] = 0.f - lightpos[1] * groundplane[2];
|
||||
shadowMat[13] = 0.f - lightpos[1] * groundplane[3];
|
||||
|
||||
shadowMat[2] = 0.f - lightpos[2] * groundplane[0];
|
||||
shadowMat[6] = 0.f - lightpos[2] * groundplane[1];
|
||||
shadowMat[10] = dot - lightpos[2] * groundplane[2];
|
||||
shadowMat[14] = 0.f - lightpos[2] * groundplane[3];
|
||||
|
||||
shadowMat[3] = 0.f - lightpos[3] * groundplane[0];
|
||||
shadowMat[7] = 0.f - lightpos[3] * groundplane[1];
|
||||
shadowMat[11] = 0.f - lightpos[3] * groundplane[2];
|
||||
shadowMat[15] = dot - lightpos[3] * groundplane[3];
|
||||
}
|
||||
|
||||
void LimitFPS(int targetFPS) {
|
||||
static auto lastTime = std::chrono::high_resolution_clock::now();
|
||||
double targetFrameDuration = 1.0 / targetFPS;
|
||||
auto currentTime = std::chrono::high_resolution_clock::now();
|
||||
std::chrono::duration<double> elapsed = currentTime - lastTime;
|
||||
|
||||
while (elapsed.count() < targetFrameDuration) {
|
||||
currentTime = std::chrono::high_resolution_clock::now();
|
||||
elapsed = currentTime - lastTime;
|
||||
}
|
||||
lastTime = std::chrono::high_resolution_clock::now();
|
||||
}
|
||||
|
||||
void SetDCPixelFormat(HDC hDC) {
|
||||
int nPixelFormat;
|
||||
static PIXELFORMATDESCRIPTOR pfd = {
|
||||
sizeof(PIXELFORMATDESCRIPTOR), 1,
|
||||
PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
|
||||
PFD_TYPE_RGBA, 24,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
32, 0, 0, PFD_MAIN_PLANE, 0, 0, 0, 0
|
||||
};
|
||||
nPixelFormat = ChoosePixelFormat(hDC, &pfd);
|
||||
SetPixelFormat(hDC, nPixelFormat, &pfd);
|
||||
}
|
||||
|
||||
HPALETTE GetOpenGLPalette(HDC hDC) {
|
||||
HPALETTE hRetPal = NULL;
|
||||
PIXELFORMATDESCRIPTOR pfd;
|
||||
LOGPALETTE* pPal;
|
||||
int nPixelFormat;
|
||||
int nColors;
|
||||
int i;
|
||||
BYTE RedRange, GreenRange, BlueRange;
|
||||
|
||||
nPixelFormat = GetPixelFormat(hDC);
|
||||
DescribePixelFormat(hDC, nPixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &pfd);
|
||||
|
||||
if (!(pfd.dwFlags & PFD_NEED_PALETTE)) return NULL;
|
||||
|
||||
nColors = 1 << pfd.cColorBits;
|
||||
pPal = (LOGPALETTE*)malloc(sizeof(LOGPALETTE) + nColors * sizeof(PALETTEENTRY));
|
||||
|
||||
pPal->palVersion = 0x300;
|
||||
pPal->palNumEntries = nColors;
|
||||
|
||||
RedRange = (1 << pfd.cRedBits) - 1;
|
||||
GreenRange = (1 << pfd.cGreenBits) - 1;
|
||||
BlueRange = (1 << pfd.cBlueBits) - 1;
|
||||
|
||||
for (i = 0; i < nColors; i++) {
|
||||
pPal->palPalEntry[i].peRed = (i >> pfd.cRedShift) & RedRange;
|
||||
pPal->palPalEntry[i].peRed = (unsigned char)((double)pPal->palPalEntry[i].peRed * 255.0 / RedRange);
|
||||
pPal->palPalEntry[i].peGreen = (i >> pfd.cGreenShift) & GreenRange;
|
||||
pPal->palPalEntry[i].peGreen = (unsigned char)((double)pPal->palPalEntry[i].peGreen * 255.0 / GreenRange);
|
||||
pPal->palPalEntry[i].peBlue = (i >> pfd.cBlueShift) & BlueRange;
|
||||
pPal->palPalEntry[i].peBlue = (unsigned char)((double)pPal->palPalEntry[i].peBlue * 255.0 / BlueRange);
|
||||
pPal->palPalEntry[i].peFlags = 0;
|
||||
}
|
||||
|
||||
hRetPal = CreatePalette(pPal);
|
||||
SelectPalette(hDC, hRetPal, FALSE);
|
||||
RealizePalette(hDC);
|
||||
free(pPal);
|
||||
return hRetPal;
|
||||
}
|
||||
22
Utils.h
Normal file
@@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
#include <windows.h>
|
||||
#include <stdio.h>
|
||||
#include <iostream>
|
||||
#include "GL/glew.h"
|
||||
|
||||
// --- DODAJ TO TUTAJ ---
|
||||
#define BITMAP_ID 0x4D42
|
||||
// ---------------------
|
||||
|
||||
// Struktury do obsługi BMP
|
||||
extern BITMAPINFOHEADER bitmapInfoHeader;
|
||||
extern unsigned char* bitmapData;
|
||||
|
||||
void DisableQuickEdit();
|
||||
void CreateConsole();
|
||||
unsigned char* LoadBitmapFile(char* filename, BITMAPINFOHEADER* bitmapInfoHeader);
|
||||
void MakeShadowMatrix(GLfloat shadowMat[16], GLfloat groundplane[4], GLfloat lightpos[4]);
|
||||
void LimitFPS(int targetFPS);
|
||||
void SetDCPixelFormat(HDC hDC);
|
||||
HPALETTE GetOpenGLPalette(HDC hDC);
|
||||
235
fabula.cpp
Normal file
@@ -0,0 +1,235 @@
|
||||
#include "fabula.hpp"
|
||||
|
||||
|
||||
std::vector<std::vector<bool>> wzory = {
|
||||
|
||||
// GK
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 1, 1, 1, 0, 1, 0, 0, 1, 0,
|
||||
0, 1, 0, 0, 0, 1, 0, 1, 1, 0,
|
||||
1, 1, 0, 0, 0, 1, 1, 1, 0, 0,
|
||||
1, 0, 0, 0, 0, 1, 1, 0, 0, 0,
|
||||
1, 0, 1, 1, 0, 1, 1, 0, 0, 0,
|
||||
1, 0, 0, 1, 1, 1, 1, 1, 0, 0,
|
||||
1, 1, 0, 0, 1, 1, 0, 1, 1, 0,
|
||||
0, 1, 1, 1, 1, 1, 0, 0, 1, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 1, 1},
|
||||
|
||||
// Ślimak
|
||||
{0, 0, 0, 0, 0, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 0, 0, 0, 0,
|
||||
1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
1, 0, 0, 1, 1, 1, 1, 1, 1, 0,
|
||||
1, 0, 1, 1, 0, 0, 0, 0, 1, 0,
|
||||
1, 0, 1, 0, 1, 0, 0, 0, 1, 0,
|
||||
1, 0, 1, 1, 1, 0, 0, 0, 1, 0,
|
||||
1, 0, 0, 0, 0, 1, 1, 1, 1, 0,
|
||||
1, 1, 1, 1, 1, 1, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
|
||||
|
||||
// Sygnał TTL
|
||||
{0, 0, 0, 0, 0, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 0, 0, 0, 0,
|
||||
1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
1, 1, 1, 1, 1, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 1, 1, 1, 1, 1, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 1, 0,
|
||||
0, 0, 0, 0, 1, 1, 1, 1, 1, 0,
|
||||
1, 1, 1, 1, 1, 0, 0, 0, 0, 0,
|
||||
1, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
|
||||
|
||||
// Okrąg
|
||||
{0, 0, 1, 1, 1, 1, 1, 0, 0, 0,
|
||||
0, 1, 1, 0, 0, 0, 1, 1, 1, 0,
|
||||
0, 1, 0, 0, 0, 0, 0, 0, 1, 0,
|
||||
1, 1, 0, 0, 0, 0, 0, 0, 1, 1,
|
||||
1, 0, 0, 0, 0, 0, 0, 0, 0, 1,
|
||||
1, 1, 0, 0, 0, 0, 0, 0, 1, 1,
|
||||
0, 1, 0, 0, 0, 0, 0, 0, 1, 0,
|
||||
0, 1, 1, 0, 0, 0, 0, 1, 1, 0,
|
||||
0, 0, 1, 1, 1, 0, 0, 1, 0, 0,
|
||||
0, 0, 0, 0, 1, 1, 1, 1, 1, 1},
|
||||
|
||||
// Kwadrat
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 0, 0,
|
||||
1, 0, 0, 0, 0, 0, 0, 1, 0, 0,
|
||||
1, 0, 0, 0, 0, 0, 0, 1, 0, 0,
|
||||
1, 0, 0, 0, 0, 0, 0, 1, 1, 1,
|
||||
1, 0, 0, 0, 0, 0, 0, 1, 1, 1,
|
||||
1, 0, 0, 0, 0, 0, 0, 1, 0, 0,
|
||||
1, 0, 0, 0, 0, 0, 0, 1, 0, 0,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
|
||||
|
||||
// ABACABA
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 1, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 1, 0, 0,
|
||||
0, 0, 0, 1, 0, 0, 0, 1, 0, 0,
|
||||
0, 0, 0, 1, 0, 0, 0, 1, 0, 0,
|
||||
0, 1, 0, 1, 0, 1, 0, 1, 0, 1,
|
||||
0, 1, 0, 1, 0, 1, 0, 1, 0, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
||||
1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
|
||||
|
||||
// Paski
|
||||
{1, 1, 1, 0, 1, 0, 1, 0, 1, 0,
|
||||
1, 0, 1, 1, 1, 0, 1, 0, 1, 0,
|
||||
1, 0, 1, 0, 1, 1, 1, 0, 1, 0,
|
||||
1, 0, 1, 0, 1, 0, 1, 1, 1, 0,
|
||||
1, 0, 1, 0, 1, 0, 1, 0, 1, 1,
|
||||
1, 0, 1, 0, 1, 0, 1, 0, 1, 1,
|
||||
1, 0, 1, 0, 1, 0, 1, 1, 1, 0,
|
||||
1, 0, 1, 0, 1, 1, 1, 0, 1, 0,
|
||||
1, 0, 1, 1, 1, 0, 1, 0, 1, 0,
|
||||
1, 1, 1, 0, 1, 0, 1, 0, 1, 0},
|
||||
|
||||
// Puste pole
|
||||
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
|
||||
|
||||
};
|
||||
|
||||
std::vector<unsigned short> siatka = {
|
||||
|
||||
// Możliwe stany pól siatki:
|
||||
// - 0 - niezamalowana, nie do zamalowania (zielony)
|
||||
// - 1 - niezamalowana, do zamalowania (złoty)
|
||||
// - 2 - zamalowana, nie do zamalowania (czerwony)
|
||||
// - 3 - zamalowana, do zamalowania (jasnozielony)
|
||||
|
||||
// 1. bit mówi o tym, czy jest do zamalowania
|
||||
// 2. bit mówi o tym, czy jest zamalowana
|
||||
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
||||
|
||||
};
|
||||
|
||||
void sprawdzPostepGry() {
|
||||
unsigned short zgodne_pola = 0;
|
||||
for (int i = 0; i < 10; i++) {
|
||||
for (int j = 0; j < 10; j++) {
|
||||
// std::cout << "zgp: " << zgodne_pola << "\n";
|
||||
unsigned short pole_w_siatce = siatka[10*i + (9 - j)];
|
||||
bool pole_we_wzorach = wzory[biezacy_wzor][10*i + (9 - j)];
|
||||
if (pole_w_siatce == 0 && pole_we_wzorach == 0) zgodne_pola++;
|
||||
else if (pole_w_siatce == 3 && pole_we_wzorach == 1) zgodne_pola++;
|
||||
else {
|
||||
// std::cout << "dla i=" << i << " j=" << j << " otrzymano p_w_s " << pole_w_siatce << " a spodziewano sie p_w_w: " << pole_we_wzorach << "\n";
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (zgodne_pola == 100) {
|
||||
biezacy_wzor = (biezacy_wzor + 1) % (wzory.size() + 1);
|
||||
Foward = 45.0f;
|
||||
Sides = -45.0f;
|
||||
Rotation = 270.0f;
|
||||
nadpiszNowaSiatke(biezacy_wzor);
|
||||
} else {
|
||||
// std::cout << "zgodne_pola: " << zgodne_pola << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
void ustalPozycjeGracza(GLfloat gracz_x, GLfloat gracz_z, short &grid_x, short &grid_z) {
|
||||
grid_x = static_cast<int>(gracz_x) / 90;
|
||||
grid_z = static_cast<int>(gracz_z) / 90;
|
||||
|
||||
// zapobiega rysowaniu ze "spawna"
|
||||
if (gracz_x < 0 && gracz_x > -90) grid_x = -1; // ten przypadek dotyczy tylko noclipa
|
||||
if (gracz_z < 0 && gracz_z > -90) grid_z = -1;
|
||||
}
|
||||
|
||||
void ustawSiatkeNaWzorNieNadpisujacPostepu() {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
for (int j = 0; j < 10; j++) {
|
||||
bool ma_byc_zamalowana = wzory[biezacy_wzor][10*i + (9 - j)];
|
||||
if (ma_byc_zamalowana) siatka[10*i + (9 - j)] |= 1;
|
||||
else siatka[10*i + (9 - j)] = siatka[10*i + (9 - j)] - siatka[10*i + (9 - j)] % 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void nadpiszNowaSiatke(short nowy_wzor) {
|
||||
biezacy_wzor = nowy_wzor;
|
||||
for (int i = 0; i < 10; i++) {
|
||||
for (int j = 0; j < 10; j++) {
|
||||
siatka[10*i + (9 - j)] = static_cast<unsigned short>(wzory[biezacy_wzor][10*i + (9 - j)]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void tworzKratke(unsigned int grid_x, unsigned int grid_z, unsigned short grid_value) {
|
||||
|
||||
// https://rgbcolorpicker.com/0-1
|
||||
switch (grid_value) {
|
||||
|
||||
case 0:
|
||||
// niezamalowana, nie do zamalowania (zielony)
|
||||
glColor3d(0.031, 0.51, 0.094);
|
||||
break;
|
||||
|
||||
case 1:
|
||||
// niezamalowana, do zamalowania (złoty)
|
||||
glColor3d(0.7, 0.5, 0.259);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
// zamalowana, nie do zamalowania (czerwony)
|
||||
glColor3d(1, 0.122, 0);
|
||||
break;
|
||||
|
||||
case 3:
|
||||
// zamalowana, do zamalowania (biały)
|
||||
glColor3d(1, 1, 1);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
platforma(45.0f + grid_x * 90.0f, 0.0f, 45.0f + grid_z * 90.0f, 45.0f, 45.0f);
|
||||
|
||||
}
|
||||
|
||||
void tworzKratkiZSiatki() {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
// Aby nie musieć rysować wzorów w odbiciu
|
||||
// lustrzanym, musimy tutaj przyjąć inną sekwencję
|
||||
// (dlatego rysujemy od prawej do lewej (9 do 0))
|
||||
for (int j = 0; j < 10; j++) {
|
||||
tworzKratke(i, j, siatka[10*i + (9 - j)]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void aktualizujBiezacaKratke(short grid_x, short grid_z) {
|
||||
if (grid_x < 0 || grid_z < 0) return;
|
||||
|
||||
unsigned short poprzednia_wartosc = siatka[10*grid_x + (9 - grid_z)];
|
||||
siatka[10*grid_x + (9 - grid_z)] |= 2; // zaznacz pole jako zamalowane
|
||||
unsigned short nowa_wartosc = siatka[10*grid_x + (9 - grid_z)];
|
||||
|
||||
// Jeżeli któreś z pól zostało zaktualizowane, sprawdź postęp gry
|
||||
if (poprzednia_wartosc != nowa_wartosc) {
|
||||
sprawdzPostepGry();
|
||||
}
|
||||
}
|
||||
18
fabula.hpp
Normal file
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
#include <iostream>
|
||||
#include "GL/glew.h"
|
||||
#include <vector>
|
||||
|
||||
extern short biezacy_wzor;
|
||||
extern float Foward;
|
||||
extern float Sides;
|
||||
extern float Rotation;
|
||||
extern void platforma(GLfloat xc, GLfloat yc, GLfloat zc, GLfloat xlen, GLfloat zlen);
|
||||
|
||||
void sprawdzPostepGry();
|
||||
void ustalPozycjeGracza(GLfloat gracz_x, GLfloat gracz_z, short &grid_x, short &grid_z);
|
||||
void ustawSiatkeNaWzorNieNadpisujacPostepu();
|
||||
void nadpiszNowaSiatke(short nowy_wzor);
|
||||
void tworzKratke(unsigned int grid_x, unsigned int grid_z, unsigned short grid_value);
|
||||
void tworzKratkiZSiatki();
|
||||
void aktualizujBiezacaKratke(short grid_x, short grid_z);
|
||||
@@ -92,6 +92,7 @@
|
||||
<Link>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<AdditionalDependencies>glfw3.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
@@ -116,18 +117,48 @@
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<AdditionalDependencies>glfw3.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="fabula.cpp" />
|
||||
<ClCompile Include="FPSCounter.cpp" />
|
||||
<ClCompile Include="glew.c" />
|
||||
<ClCompile Include="Global.cpp" />
|
||||
<ClCompile Include="Logger.cpp" />
|
||||
<ClCompile Include="Physics.cpp" />
|
||||
<ClCompile Include="Render.cpp" />
|
||||
<ClCompile Include="Rover.cpp" />
|
||||
<ClCompile Include="lazik.cpp" />
|
||||
<ClCompile Include="loadOBJ.cpp" />
|
||||
<ClCompile Include="main.cpp" />
|
||||
<ClCompile Include="szescian.cpp" />
|
||||
<ClCompile Include="plane.cpp" />
|
||||
<ClCompile Include="shader.cpp" />
|
||||
<ClCompile Include="teksturowane.cpp" />
|
||||
<ClCompile Include="texture.cpp" />
|
||||
<ClCompile Include="timeh.cpp" />
|
||||
<ClCompile Include="Utils.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="DayNightCycle.hpp" />
|
||||
<ClInclude Include="fabula.hpp" />
|
||||
<ClInclude Include="Global.h" />
|
||||
<ClInclude Include="lazik.hpp" />
|
||||
<ClInclude Include="loadOBJ.h" />
|
||||
<ClInclude Include="Logger.hpp" />
|
||||
<ClInclude Include="Physics.h" />
|
||||
<ClInclude Include="plane.hpp" />
|
||||
<ClInclude Include="rain.hpp" />
|
||||
<ClInclude Include="Render.h" />
|
||||
<ClInclude Include="RESOURCE.H" />
|
||||
<ClInclude Include="szescian.h" />
|
||||
<ClInclude Include="shader.hpp" />
|
||||
<ClInclude Include="teksturowane.hpp" />
|
||||
<ClInclude Include="texture.hpp" />
|
||||
<ClInclude Include="timeh.hpp" />
|
||||
<ClInclude Include="Utils.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="glfw3.dll" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
|
||||
@@ -21,7 +21,49 @@
|
||||
<ClCompile Include="main.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="szescian.cpp">
|
||||
<ClCompile Include="glew.c">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="lazik.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="timeh.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="plane.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="FPSCounter.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="shader.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="texture.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Rover.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="fabula.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="teksturowane.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Global.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Utils.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Physics.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Render.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Logger.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
@@ -32,8 +74,52 @@
|
||||
<ClInclude Include="RESOURCE.H">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="szescian.h">
|
||||
<ClInclude Include="plane.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="lazik.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="timeh.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="shader.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="texture.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="fabula.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="teksturowane.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Logger.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="rain.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="DayNightCycle.hpp">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Global.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Utils.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Physics.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="Render.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="glfw3.dll">
|
||||
<Filter>Source Files</Filter>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
107
lazik.cpp
Normal file
@@ -0,0 +1,107 @@
|
||||
#include "lazik.hpp"
|
||||
|
||||
//lazik::lazik(float x, float y, float z, const char* modelpath, const char* texturepath) {
|
||||
lazik::lazik(float x, float y, float z, const char* modelpath) {
|
||||
|
||||
this->c_x = x;
|
||||
this->c_y = y;
|
||||
this->c_z = z;
|
||||
this->modelpath = modelpath;
|
||||
// this->texturepath = texturepath;
|
||||
timestampedCout("lazik.cpp: Zaladowano dane w konstruktorze.")
|
||||
|
||||
}
|
||||
|
||||
// void lazik::passProgramID(GLuint programID) {
|
||||
// this->programID = programID;
|
||||
// }
|
||||
|
||||
void lazik::loadModel() {
|
||||
|
||||
timestampedCout("lazik.cpp:");
|
||||
std::cout << " Ladowanie modelu ze sciezki " << this->modelpath << "...\n";
|
||||
bool res = loadOBJ(this->modelpath, this->vertices, this->uvs, this->normals);
|
||||
if (res) timestampedCout("Pomyslnie zaladowano model lazika.")
|
||||
else timestampedCout("Nie udalo sie zaladowac modelu lazika.");
|
||||
|
||||
//this->Texture = loadDDS(this->texturepath);
|
||||
//timestampedCout("lazik.cpp: this->Texture = " << this->Texture);
|
||||
//this->TextureID = glGetUniformLocation(this->programID, "myTextureSampler");
|
||||
//timestampedCout("lazik.cpp: this->TextureID = " << this->TextureID);
|
||||
|
||||
glGenBuffers(1, &vertexbuffer);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, this->vertexbuffer);
|
||||
glBufferData(GL_ARRAY_BUFFER, this->vertices.size() * sizeof(glm::vec3), &vertices[0], GL_STATIC_DRAW);
|
||||
|
||||
glGenBuffers(1, &uvbuffer);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, this->uvbuffer);
|
||||
glBufferData(GL_ARRAY_BUFFER, this->uvs.size() * sizeof(glm::vec2), &uvs[0], GL_STATIC_DRAW);
|
||||
|
||||
}
|
||||
|
||||
void lazik::draw() {
|
||||
|
||||
// glEnable(GL_TEXTURE_2D);
|
||||
// // Bind our texture in Texture Unit 0
|
||||
// glActiveTexture(GL_TEXTURE0);
|
||||
// glBindTexture(GL_TEXTURE_2D, Texture);
|
||||
// // Set our "myTextureSampler" sampler to use Texture Unit 0
|
||||
// glUniform1i(TextureID, 0);
|
||||
|
||||
// 1st attribute buffer: vertices
|
||||
glEnableVertexAttribArray(0);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, this->vertexbuffer);
|
||||
glVertexAttribPointer(
|
||||
0, // attribute
|
||||
3, // size
|
||||
GL_FLOAT, // type
|
||||
GL_FALSE, // normalized?
|
||||
0, // stride
|
||||
(void*)0 // array buffer offset
|
||||
);
|
||||
|
||||
// 2nd attribute buffer: UVs
|
||||
glEnableVertexAttribArray(1);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, this->uvbuffer);
|
||||
glVertexAttribPointer(
|
||||
1, // attribute
|
||||
2, // size
|
||||
GL_FLOAT, // type
|
||||
GL_FALSE, // normalized?
|
||||
0, // stride
|
||||
(void*)0 // array buffer offset
|
||||
);
|
||||
|
||||
// Draw vertices
|
||||
glDrawArrays(GL_TRIANGLES, 0, this->vertices.size());
|
||||
|
||||
// glDisable(GL_TEXTURE_2D);
|
||||
|
||||
glDisableVertexAttribArray(0);
|
||||
glDisableVertexAttribArray(1);
|
||||
|
||||
}
|
||||
|
||||
void lazik::unload(){
|
||||
glDeleteBuffers(1, &this->vertexbuffer);
|
||||
glDeleteBuffers(1, &this->uvbuffer);
|
||||
// glDeleteTextures(1, &this->Texture);
|
||||
}
|
||||
|
||||
void lazik::moveX(float x){
|
||||
// TODO: dodać timer do poniższych funkcji, aby czas przejścia z punktu A do B był uniezależniony od FPSów
|
||||
timestampedCout("dummy moveX");
|
||||
}
|
||||
|
||||
void lazik::moveY(float y){
|
||||
timestampedCout("dummy moveY");
|
||||
}
|
||||
|
||||
void lazik::moveZ(float z){
|
||||
timestampedCout("dummy moveZ");
|
||||
}
|
||||
|
||||
void lazik::moveXYZ(float x, float y, float z){
|
||||
// TODO: modyfikować wektor z koordynatami oraz c_x, c_y, c_z
|
||||
timestampedCout("dummy moveXYZ");
|
||||
}
|
||||
43
lazik.hpp
Normal file
@@ -0,0 +1,43 @@
|
||||
#pragma once
|
||||
#include <windows.h>
|
||||
#include "GL/glew.h"
|
||||
#include <gl/gl.h>
|
||||
#include <gl/glu.h>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include "timeh.hpp"
|
||||
#include "GL/glm/glm.hpp"
|
||||
#include "loadOBJ.h"
|
||||
#include "texture.hpp"
|
||||
#include "shader.hpp"
|
||||
|
||||
class lazik {
|
||||
private:
|
||||
float c_x{0};
|
||||
float c_y{0};
|
||||
float c_z{0};
|
||||
float rot_x{0};
|
||||
float rot_y{0};
|
||||
float rot_z{0};
|
||||
std::vector <glm::vec3> vertices;
|
||||
std::vector <glm::vec2> uvs;
|
||||
std::vector <glm::vec3> normals; // Won't be used at the moment.
|
||||
GLuint vertexbuffer;
|
||||
GLuint uvbuffer;
|
||||
const char* modelpath;
|
||||
//GLuint programID;
|
||||
//GLuint Texture;
|
||||
//GLuint TextureID;
|
||||
//const char* texturepath;
|
||||
public:
|
||||
// lazik(float x, float y, float z, const char* modelpath, const char* texturepath);
|
||||
lazik(float x, float y, float z, const char* modelpath);
|
||||
//void passProgramID(GLuint programID);
|
||||
void loadModel();
|
||||
void draw();
|
||||
void unload();
|
||||
void moveX(float x);
|
||||
void moveY(float y);
|
||||
void moveZ(float z);
|
||||
void moveXYZ(float x, float y, float z);
|
||||
};
|
||||
19
loadOBJ.cpp
@@ -15,11 +15,15 @@ bool loadOBJ(const char* path, std::vector <glm::vec3>& out_vertices, std::vecto
|
||||
return false;
|
||||
}
|
||||
|
||||
int line = 0;
|
||||
unsigned int line = 0;
|
||||
unsigned int vs = 0;
|
||||
unsigned int vts = 0;
|
||||
unsigned int vns = 0;
|
||||
unsigned int fs = 0;
|
||||
char lineHeader[128];
|
||||
|
||||
while (1) {
|
||||
|
||||
char lineHeader[128];
|
||||
// read the first word of the line
|
||||
int res = fscanf(file, "%s", lineHeader);
|
||||
if (res == EOF) break; // EOF = End Of File. Quit the loop.
|
||||
@@ -30,23 +34,27 @@ bool loadOBJ(const char* path, std::vector <glm::vec3>& out_vertices, std::vecto
|
||||
glm::vec3 vertex;
|
||||
fscanf(file, "%f %f %f\n", &vertex.x, &vertex.y, &vertex.z);
|
||||
temp_vertices.push_back(vertex);
|
||||
vs++;
|
||||
|
||||
} else if (strcmp(lineHeader, "vt") == 0) {
|
||||
|
||||
glm::vec2 uv;
|
||||
fscanf(file, "%f %f\n", &uv.x, &uv.y);
|
||||
temp_uvs.push_back(uv);
|
||||
vts++;
|
||||
|
||||
} else if (strcmp(lineHeader, "vn") == 0) {
|
||||
|
||||
glm::vec3 normal;
|
||||
fscanf(file, "%f %f %f\n", &normal.x, &normal.y, &normal.z);
|
||||
temp_normals.push_back(normal);
|
||||
vns++;
|
||||
|
||||
} else if (strcmp(lineHeader, "f") == 0) {
|
||||
|
||||
unsigned int vertexIndex[3], uvIndex[3], normalIndex[3];
|
||||
int matches = fscanf(file, "%d/%d/%d %d/%d/%d %d/%d/%d\n", &vertexIndex[0], &uvIndex[0], &normalIndex[0], &vertexIndex[1], &uvIndex[1], &normalIndex[1], &vertexIndex[2], &uvIndex[2], &normalIndex[2]);
|
||||
fs++;
|
||||
|
||||
if (matches != 9){
|
||||
printf("File can't be read by our simple parser. Try exporting with other options (%d matches on line %d)\n", matches, line);
|
||||
@@ -64,6 +72,9 @@ bool loadOBJ(const char* path, std::vector <glm::vec3>& out_vertices, std::vecto
|
||||
normalIndices.push_back(normalIndex[2]);
|
||||
}
|
||||
|
||||
line++;
|
||||
}
|
||||
|
||||
// For each vertex of each triangle
|
||||
for (unsigned int i = 0; i < vertexIndices.size(); i++) {
|
||||
unsigned int vertexIndex = vertexIndices[i];
|
||||
@@ -79,9 +90,9 @@ bool loadOBJ(const char* path, std::vector <glm::vec3>& out_vertices, std::vecto
|
||||
out_normals.push_back(vertex3);
|
||||
}
|
||||
|
||||
line++;
|
||||
fclose(file);
|
||||
|
||||
}
|
||||
printf("(loadOBJ.cpp) Loaded file with %d v, %d vt, %d vn, %d f. %d lines total.\n", vs, vts, vns, fs, line);
|
||||
|
||||
return true;
|
||||
}
|
||||
860
main.cpp
@@ -1,812 +1,218 @@
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
#ifdef _MSC_VER // Check if MS Visual C compiler
|
||||
# pragma comment(lib, "opengl32.lib") // Compiler-specific directive to avoid manually configuration
|
||||
# pragma comment(lib, "glu32.lib") // Link libraries
|
||||
#endif
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
|
||||
#ifdef _MSC_VER
|
||||
# ifndef _MBCS
|
||||
# define _MBCS
|
||||
#pragma comment(lib, "opengl32.lib")
|
||||
#pragma comment(lib, "glu32.lib")
|
||||
#endif
|
||||
# ifdef _UNICODE
|
||||
# undef _UNICODE
|
||||
# endif
|
||||
# ifdef UNICODE
|
||||
# undef UNICODE
|
||||
# endif
|
||||
#endif
|
||||
// #define GLEW_STATIC
|
||||
#include <windows.h> // Window defines
|
||||
#include "GL/glew.h" // Dołączony jako pliki glew.c i glew.h
|
||||
//#include <gl/gl.h> // OpenGL
|
||||
#include <gl/glu.h> // biblioteka GLU; program kompiluje się bez niej, ale w celu uniknięcia w przyszłości niespodzianek to została dołączona
|
||||
#include <math.h> // Define for sqrt
|
||||
//#include <stdio.h>
|
||||
#include <iostream>
|
||||
#include "RESOURCE.H" // About box resource identifiers.
|
||||
#include "szescian.h"
|
||||
#include "loadOBJ.h"
|
||||
//#include <vector>
|
||||
#include "GL/glm/glm.hpp"
|
||||
//#include "GL/glfw3.h"
|
||||
#include <ctime>
|
||||
|
||||
using namespace glm;
|
||||
|
||||
#define glRGB(x, y, z) glColor3ub((GLubyte)x, (GLubyte)y, (GLubyte)z)
|
||||
#define BITMAP_ID 0x4D42 // identyfikator formatu BMP
|
||||
#define GL_PI 3.1415
|
||||
#define getTime lastTime = std::time(nullptr);
|
||||
#define timestampedCout(msg) {getTime; std::cout << "( " << lastTime << ") " << msg << "\n";}
|
||||
|
||||
//using namespace std;
|
||||
|
||||
HPALETTE hPalette = NULL;
|
||||
|
||||
// Application name and instance storeage
|
||||
static LPCTSTR lpszAppName = "grafikaKBT";
|
||||
static HINSTANCE hInstance;
|
||||
|
||||
// Rotation amounts
|
||||
static GLfloat xRot = 0.0f;
|
||||
static GLfloat yRot = 0.0f;
|
||||
static GLfloat zRot = 0.0f;
|
||||
|
||||
|
||||
static GLsizei lastHeight;
|
||||
static GLsizei lastWidth;
|
||||
|
||||
// Opis tekstury
|
||||
BITMAPINFOHEADER bitmapInfoHeader; // nagłówek obrazu
|
||||
unsigned char* bitmapData; // dane tekstury
|
||||
unsigned int texture[2]; // obiekt tekstury
|
||||
#include "Global.h"
|
||||
#include "Utils.h"
|
||||
#include "Render.h"
|
||||
#include "Physics.h"
|
||||
#include "RESOURCE.H"
|
||||
#include "Logger.hpp"
|
||||
#include "fabula.hpp"
|
||||
|
||||
// Deklaracje funkcji lokalnych w Main
|
||||
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
|
||||
|
||||
BOOL APIENTRY AboutDlgProc(HWND hDlg, UINT message, UINT wParam, LONG lParam);
|
||||
|
||||
void SetDCPixelFormat(HDC hDC);
|
||||
|
||||
int polygonmode = 0;
|
||||
char loadCount = 0;
|
||||
|
||||
// Change viewing volume and viewport. Called when window is resized
|
||||
void ChangeSize(GLsizei w, GLsizei h) {
|
||||
GLfloat nRange = 100.0f;
|
||||
GLfloat fAspect;
|
||||
// Prevent a divide by zero
|
||||
if (h == 0) h = 1;
|
||||
|
||||
lastWidth = w;
|
||||
lastHeight = h;
|
||||
|
||||
fAspect = (GLfloat)w / (GLfloat)h;
|
||||
// Set Viewport to window dimensions
|
||||
glViewport(0, 0, w, h);
|
||||
|
||||
// Reset coordinate system
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
|
||||
// Establish clipping volume (left, right, bottom, top, near, far)
|
||||
if (w <= h) glOrtho(-nRange, nRange, -nRange * h / w, nRange * h / w, -nRange, nRange);
|
||||
else glOrtho(-nRange * w / h, nRange * w / h, -nRange, nRange, -nRange, nRange);
|
||||
|
||||
// Establish perspective:
|
||||
/*
|
||||
gluPerspective(60.0f, fAspect, 1.0, 400);
|
||||
*/
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
}
|
||||
|
||||
void SetupRC() {
|
||||
// Light values and coordinates
|
||||
//GLfloat ambientLight[] = { 0.3f, 0.3f, 0.3f, 1.0f };
|
||||
//GLfloat diffuseLight[] = { 0.7f, 0.7f, 0.7f, 1.0f };
|
||||
//GLfloat specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
|
||||
//GLfloat lightPos[] = { 0.0f, 150.0f, 150.0f, 1.0f };
|
||||
//GLfloat specref[] = { 1.0f, 1.0f, 1.0f, 1.0f };
|
||||
|
||||
|
||||
glEnable(GL_DEPTH_TEST); // Hidden surface removal
|
||||
glFrontFace(GL_CCW); // Counter clock-wise polygons face out
|
||||
//glEnable(GL_CULL_FACE); // Do not calculate inside of jet
|
||||
|
||||
// Enable lighting
|
||||
//glEnable(GL_LIGHTING);
|
||||
|
||||
// Setup and enable light 0
|
||||
//glLightfv(GL_LIGHT0, GL_AMBIENT, ambientLight);
|
||||
//glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseLight);
|
||||
//glLightfv(GL_LIGHT0, GL_SPECULAR, specular);
|
||||
//glLightfv(GL_LIGHT0, GL_POSITION, lightPos);
|
||||
//glEnable(GL_LIGHT0);
|
||||
|
||||
// Enable color tracking
|
||||
//glEnable(GL_COLOR_MATERIAL);
|
||||
|
||||
// Set Material properties to follow glColor values
|
||||
//glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
|
||||
|
||||
// All materials hereafter have full specular reflectivity
|
||||
// with a high shine
|
||||
//glMaterialfv(GL_FRONT, GL_SPECULAR, specref);
|
||||
//glMateriali(GL_FRONT, GL_SHININESS, 128);
|
||||
|
||||
|
||||
// White background
|
||||
glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
// Black brush
|
||||
glColor3f(0.0, 0.0, 0.0);
|
||||
}
|
||||
|
||||
// LoadBitmapFile
|
||||
// opis: ładuje mapę bitową z pliku i zwraca jej adres.
|
||||
// Wypełnia strukturę nagłówka.
|
||||
// Nie obsługuje map 8-bitowych.
|
||||
unsigned char* LoadBitmapFile(char* filename, BITMAPINFOHEADER* bitmapInfoHeader) {
|
||||
FILE* filePtr; // wskaźnik pozycji pliku
|
||||
BITMAPFILEHEADER bitmapFileHeader; // nagłówek pliku
|
||||
unsigned char* bitmapImage; // dane obrazu
|
||||
int imageIdx = 0; // licznik pikseli
|
||||
unsigned char tempRGB; // zmienna zamiany składowych
|
||||
|
||||
// otwiera plik w trybie "read binary"
|
||||
filePtr = fopen(filename, "rb");
|
||||
if (filePtr == NULL)
|
||||
return NULL;
|
||||
|
||||
// wczytuje nagłówek pliku
|
||||
fread(&bitmapFileHeader, sizeof(BITMAPFILEHEADER), 1, filePtr);
|
||||
|
||||
// sprawdza, czy jest to plik formatu BMP
|
||||
if (bitmapFileHeader.bfType != BITMAP_ID)
|
||||
{
|
||||
fclose(filePtr);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// wczytuje nagłówek obrazu
|
||||
fread(bitmapInfoHeader, sizeof(BITMAPINFOHEADER), 1, filePtr);
|
||||
|
||||
// ustawia wskaźnik pozycji pliku na początku danych obrazu
|
||||
fseek(filePtr, bitmapFileHeader.bfOffBits, SEEK_SET);
|
||||
|
||||
// przydziela pamięć buforowi obrazu
|
||||
bitmapImage = (unsigned char*)malloc(bitmapInfoHeader->biSizeImage);
|
||||
|
||||
// sprawdza, czy udało się przydzielić pamięć
|
||||
if (!bitmapImage) {
|
||||
free(bitmapImage);
|
||||
fclose(filePtr);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// wczytuje dane obrazu
|
||||
fread(bitmapImage, 1, bitmapInfoHeader->biSizeImage, filePtr);
|
||||
|
||||
// sprawdza, czy dane zostały wczytane
|
||||
if (bitmapImage == NULL) {
|
||||
fclose(filePtr);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// zamienia miejscami składowe R i B
|
||||
for (imageIdx = 0; imageIdx < bitmapInfoHeader->biSizeImage; imageIdx += 3) {
|
||||
tempRGB = bitmapImage[imageIdx];
|
||||
bitmapImage[imageIdx] = bitmapImage[imageIdx + 2];
|
||||
bitmapImage[imageIdx + 2] = tempRGB;
|
||||
}
|
||||
|
||||
// zamyka plik i zwraca wskaźnik bufora zawierającego wczytany obraz
|
||||
fclose(filePtr);
|
||||
return bitmapImage;
|
||||
}
|
||||
|
||||
void SetDCPixelFormat(HDC hDC) {
|
||||
int nPixelFormat;
|
||||
|
||||
static PIXELFORMATDESCRIPTOR pfd = {
|
||||
sizeof(PIXELFORMATDESCRIPTOR), // Size of this structure
|
||||
1, // Version of this structure
|
||||
PFD_DRAW_TO_WINDOW | // Draw to Window (not to bitmap)
|
||||
PFD_SUPPORT_OPENGL | // Support OpenGL calls in window
|
||||
PFD_DOUBLEBUFFER, // Double buffered
|
||||
PFD_TYPE_RGBA, // RGBA Color mode
|
||||
24, // Want 24bit color
|
||||
0,0,0,0,0,0, // Not used to select mode
|
||||
0,0, // Not used to select mode
|
||||
0,0,0,0,0, // Not used to select mode
|
||||
32, // Size of depth buffer
|
||||
0, // Not used to select mode
|
||||
0, // Not used to select mode
|
||||
PFD_MAIN_PLANE, // Draw in main plane
|
||||
0, // Not used to select mode
|
||||
0,0,0 }; // Not used to select mode
|
||||
|
||||
// Choose a pixel format that best matches that described in pfd
|
||||
nPixelFormat = ChoosePixelFormat(hDC, &pfd);
|
||||
|
||||
// Set the pixel format for the device context
|
||||
SetPixelFormat(hDC, nPixelFormat, &pfd);
|
||||
}
|
||||
|
||||
std::vector <glm::vec3> vertices;
|
||||
std::vector <glm::vec2> uvs;
|
||||
std::vector <glm::vec3> normals; // Won't be used at the moment.
|
||||
GLuint vertexbuffer;
|
||||
GLuint uvbuffer;
|
||||
std::time_t lastTime = std::time(nullptr);
|
||||
|
||||
void setup(){
|
||||
// załaduj model
|
||||
|
||||
// if(!glfwInit()) {
|
||||
// fprintf(stderr, "Failed to initialize GLFW\n");
|
||||
// getchar();
|
||||
// return;
|
||||
// }
|
||||
|
||||
// Initialize GLEW
|
||||
timestampedCout("Inicjalizowanie GLEW...");
|
||||
glewExperimental = true; // Needed for core profile
|
||||
if (glewInit() != GLEW_OK) {
|
||||
fprintf(stderr, "Failed to initialize GLEW\n");
|
||||
getchar();
|
||||
// glfwTerminate();
|
||||
return;
|
||||
}
|
||||
|
||||
timestampedCout("Zainicjalizowano GLEW.");
|
||||
|
||||
/* */
|
||||
// Read our .obj file
|
||||
|
||||
// TODO: zmierzyć czas ładowania łazika w cyklach procesora/mikrosekundach
|
||||
|
||||
timestampedCout("Ladowanie lazika...");
|
||||
bool res = loadOBJ("res/models/lazik3.obj", vertices, uvs, normals);
|
||||
// bool res = loadOBJ("res/models/suzanne.obj", vertices, uvs, normals);
|
||||
|
||||
if (res) {
|
||||
timestampedCout("Pomyslnie zaladowano model lazika.");
|
||||
}
|
||||
else timestampedCout("Nie udalo sie zaladowac modelu lazika.");
|
||||
|
||||
/* */
|
||||
|
||||
glGenBuffers(1, &vertexbuffer);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
|
||||
glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(glm::vec3), &vertices[0], GL_STATIC_DRAW);
|
||||
|
||||
glGenBuffers(1, &uvbuffer);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, uvbuffer);
|
||||
glBufferData(GL_ARRAY_BUFFER, uvs.size() * sizeof(glm::vec2), &uvs[0], GL_STATIC_DRAW);
|
||||
|
||||
loadCount++;
|
||||
|
||||
//glClearColor(0.0f, 0.0f, 0.4f, 0.0f);
|
||||
|
||||
}
|
||||
|
||||
void RenderScene(void) {
|
||||
if (loadCount == 0) setup();
|
||||
|
||||
//float normal[3]; // Storage for calculated surface normal
|
||||
|
||||
// Clear the window with current clearing color
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
// Save the matrix state and do the rotations
|
||||
glPushMatrix();
|
||||
glRotatef(xRot, 1.0f, 0.0f, 0.0f);
|
||||
glRotatef(yRot, 0.0f, 1.0f, 0.0f);
|
||||
glRotatef(zRot, 0.0f, 0.0f, 1.0f);
|
||||
|
||||
// gluLookAt(
|
||||
// 0, 0, 0, // the position of your camera, in world space
|
||||
// 0, 0, 0, // where you want to look at, in world space
|
||||
// 0, 1, 0 // probably glm::vec3(0,1,0), but (0,-1,0) would make you looking upside-down, which can be great too
|
||||
// );
|
||||
|
||||
/////////////////////////////////////////////////////////////////
|
||||
// MIEJSCE NA KOD OPENGL DO TWORZENIA WLASNYCH SCEN: //
|
||||
/////////////////////////////////////////////////////////////////
|
||||
//szescian();
|
||||
|
||||
//Sposób na odróżnienie "przedniej" i "tylniej" ściany wielokąta:
|
||||
//glPolygonMode(GL_BACK,GL_LINE);
|
||||
//walec(40, 40);
|
||||
//szescian();
|
||||
|
||||
switch (polygonmode) {
|
||||
case 0:
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||
break;
|
||||
|
||||
case 1:
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
||||
break;
|
||||
|
||||
default:
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||
}
|
||||
|
||||
|
||||
// Clear the screen
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
// Use our shader
|
||||
//glUseProgram(programID);
|
||||
|
||||
// // Bind our texture in Texture Unit 0
|
||||
// glActiveTexture(GL_TEXTURE0);
|
||||
// glBindTexture(GL_TEXTURE_2D, Texture);
|
||||
// // Set our "myTextureSampler" sampler to use Texture Unit 0
|
||||
// glUniform1i(TextureID, 0);
|
||||
|
||||
// 1rst attribute buffer : vertices
|
||||
glEnableVertexAttribArray(0);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
|
||||
glVertexAttribPointer(
|
||||
0, // attribute
|
||||
3, // size
|
||||
GL_FLOAT, // type
|
||||
GL_FALSE, // normalized?
|
||||
0, // stride
|
||||
(void*)0 // array buffer offset
|
||||
);
|
||||
|
||||
// 2nd attribute buffer: UVs
|
||||
glEnableVertexAttribArray(1);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, uvbuffer);
|
||||
glVertexAttribPointer(
|
||||
1, // attribute
|
||||
2, // size
|
||||
GL_FLOAT, // type
|
||||
GL_FALSE, // normalized?
|
||||
0, // stride
|
||||
(void*)0 // array buffer offset
|
||||
);
|
||||
|
||||
// Draw the triangle!
|
||||
glDrawArrays(GL_TRIANGLES, 0, vertices.size() );
|
||||
|
||||
glDisableVertexAttribArray(0);
|
||||
glDisableVertexAttribArray(1);
|
||||
|
||||
// Swap buffers
|
||||
//glfwSwapBuffers(window);
|
||||
//glfwPollEvents();
|
||||
|
||||
/*
|
||||
szescian nowy;
|
||||
nowy.create(0, 0, 0, 10);
|
||||
nowy.create(-10, 20, 0, 10);
|
||||
nowy.create(25, 10, 0, 10);
|
||||
*/
|
||||
|
||||
glDrawArrays(GL_TRIANGLES, 0, vertices.size());
|
||||
|
||||
/*
|
||||
szescian nowy2;
|
||||
nowy2.create(0, 10, 0, 10);
|
||||
szescian nowy3;
|
||||
nowy3.create(0, 20, -10, 10);
|
||||
*/
|
||||
|
||||
//Uzyskanie siatki:
|
||||
//glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
||||
|
||||
//Wyrysowanie prostokata:
|
||||
//glRectd(-10.0,-10.0,20.0,20.0);
|
||||
|
||||
/////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////
|
||||
glPopMatrix();
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
|
||||
// Flush drawing commands
|
||||
glFlush();
|
||||
}
|
||||
|
||||
// If necessary, creates a 3-3-2 palette for the device context listed.
|
||||
HPALETTE GetOpenGLPalette(HDC hDC) {
|
||||
HPALETTE hRetPal = NULL; // Handle to palette to be created
|
||||
PIXELFORMATDESCRIPTOR pfd; // Pixel Format Descriptor
|
||||
LOGPALETTE* pPal; // Pointer to memory for logical palette
|
||||
int nPixelFormat; // Pixel format index
|
||||
int nColors; // Number of entries in palette
|
||||
int i; // Counting variable
|
||||
BYTE RedRange, GreenRange, BlueRange;
|
||||
// Range for each color entry (7,7,and 3)
|
||||
|
||||
|
||||
// Get the pixel format index and retrieve the pixel format description
|
||||
nPixelFormat = GetPixelFormat(hDC);
|
||||
DescribePixelFormat(hDC, nPixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &pfd);
|
||||
|
||||
// Does this pixel format require a palette? If not, do not create a
|
||||
// palette and just return NULL
|
||||
if (!(pfd.dwFlags & PFD_NEED_PALETTE)) return NULL;
|
||||
|
||||
// Number of entries in palette. 8 bits yeilds 256 entries
|
||||
nColors = 1 << pfd.cColorBits;
|
||||
|
||||
// Allocate space for a logical palette structure plus all the palette entries
|
||||
pPal = (LOGPALETTE*)malloc(sizeof(LOGPALETTE) + nColors * sizeof(PALETTEENTRY));
|
||||
|
||||
// Fill in palette header
|
||||
pPal->palVersion = 0x300; // Windows 3.0
|
||||
pPal->palNumEntries = nColors; // table size
|
||||
|
||||
// Build mask of all 1's. This creates a number represented by having
|
||||
// the low order x bits set, where x = pfd.cRedBits, pfd.cGreenBits, and
|
||||
// pfd.cBlueBits.
|
||||
RedRange = (1 << pfd.cRedBits) - 1;
|
||||
GreenRange = (1 << pfd.cGreenBits) - 1;
|
||||
BlueRange = (1 << pfd.cBlueBits) - 1;
|
||||
|
||||
// Loop through all the palette entries
|
||||
for (i = 0; i < nColors; i++) {
|
||||
|
||||
// Fill in the 8-bit equivalents for each component
|
||||
pPal->palPalEntry[i].peRed = (i >> pfd.cRedShift) & RedRange;
|
||||
pPal->palPalEntry[i].peRed = (unsigned char)(
|
||||
(double)pPal->palPalEntry[i].peRed * 255.0 / RedRange);
|
||||
|
||||
pPal->palPalEntry[i].peGreen = (i >> pfd.cGreenShift) & GreenRange;
|
||||
pPal->palPalEntry[i].peGreen = (unsigned char)(
|
||||
(double)pPal->palPalEntry[i].peGreen * 255.0 / GreenRange);
|
||||
|
||||
pPal->palPalEntry[i].peBlue = (i >> pfd.cBlueShift) & BlueRange;
|
||||
pPal->palPalEntry[i].peBlue = (unsigned char)(
|
||||
(double)pPal->palPalEntry[i].peBlue * 255.0 / BlueRange);
|
||||
|
||||
// pPal->palPalEntry[i].peFlags = (unsigned char) NULL;
|
||||
pPal->palPalEntry[i].peFlags = 0;
|
||||
}
|
||||
|
||||
|
||||
// Create the palette
|
||||
hRetPal = CreatePalette(pPal);
|
||||
|
||||
// Go ahead and select and realize the palette for this device context
|
||||
SelectPalette(hDC, hRetPal, FALSE);
|
||||
RealizePalette(hDC);
|
||||
|
||||
// Free the memory used for the logical palette structure
|
||||
free(pPal);
|
||||
|
||||
// Return the handle to the new palette
|
||||
return hRetPal;
|
||||
}
|
||||
// Zmienne globalne tylko dla okna
|
||||
static LPCTSTR lpszAppName = "grafikaKBT";
|
||||
static HINSTANCE hInstance;
|
||||
static const int targetFPS = 144;
|
||||
|
||||
int APIENTRY WinMain(HINSTANCE hInst, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
|
||||
CreateConsole();
|
||||
DisableQuickEdit();
|
||||
AsyncLogger::getInstance().start();
|
||||
|
||||
MSG msg; // Windows message structure
|
||||
WNDCLASS wc; // Windows class structure
|
||||
HWND hWnd; // Storeage for window handle
|
||||
|
||||
MSG msg;
|
||||
WNDCLASS wc{};
|
||||
HWND hWnd;
|
||||
hInstance = hInst;
|
||||
|
||||
// Register Window style
|
||||
wc.style = CS_HREDRAW | CS_VREDRAW;
|
||||
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
|
||||
wc.lpfnWndProc = (WNDPROC)WndProc;
|
||||
wc.cbClsExtra = 0;
|
||||
wc.cbWndExtra = 0;
|
||||
wc.hInstance = hInstance;
|
||||
wc.hIcon = NULL;
|
||||
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
|
||||
|
||||
// No need for background brush for OpenGL window
|
||||
wc.hbrBackground = NULL;
|
||||
|
||||
wc.lpszMenuName = MAKEINTRESOURCE(IDR_MENU);
|
||||
wc.lpszClassName = lpszAppName;
|
||||
|
||||
// Register the window class
|
||||
if (RegisterClass(&wc) == 0) return FALSE;
|
||||
|
||||
int screenWidth = GetSystemMetrics(SM_CXSCREEN);
|
||||
int screenHeight = GetSystemMetrics(SM_CYSCREEN);
|
||||
|
||||
// Create the main application window
|
||||
// 2. Utwórz okno z pełnym zestawem przycisków (WS_OVERLAPPEDWINDOW)
|
||||
hWnd = CreateWindow(
|
||||
lpszAppName,
|
||||
lpszAppName,
|
||||
|
||||
// OpenGL requires WS_CLIPCHILDREN and WS_CLIPSIBLINGS
|
||||
lpszAppName, lpszAppName,
|
||||
WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS,
|
||||
0, 0, // Pozycja startowa (lewy górny róg)
|
||||
screenWidth, screenHeight, // Rozmiar (wstępnie cały ekran)
|
||||
NULL, NULL, hInstance, NULL);
|
||||
|
||||
// Window position and size
|
||||
50, 50,
|
||||
400, 400,
|
||||
NULL,
|
||||
NULL,
|
||||
hInstance,
|
||||
NULL);
|
||||
|
||||
// If window was not created, quit
|
||||
if (hWnd == NULL) return FALSE;
|
||||
|
||||
HDC hDC = GetDC(hWnd);
|
||||
const WORD ID_TIMER = 1;
|
||||
SetTimer(hWnd, ID_TIMER, 100, NULL);
|
||||
|
||||
// Display the window
|
||||
ShowWindow(hWnd, SW_SHOW);
|
||||
ShowWindow(hWnd, SW_SHOWMAXIMIZED);
|
||||
UpdateWindow(hWnd);
|
||||
|
||||
// Process application messages until the application closes
|
||||
while (GetMessage(&msg, NULL, 0, 0)) {
|
||||
ZeroMemory(&msg, sizeof(msg));
|
||||
auto lastFrameTime = std::chrono::high_resolution_clock::now();
|
||||
|
||||
while (msg.message != WM_QUIT) {
|
||||
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessage(&msg);
|
||||
}
|
||||
else {
|
||||
auto currentFrameTime = std::chrono::high_resolution_clock::now();
|
||||
std::chrono::duration<float> timeSpan = currentFrameTime - lastFrameTime;
|
||||
deltaTime = timeSpan.count();
|
||||
lastFrameTime = currentFrameTime;
|
||||
|
||||
RenderScene();
|
||||
SwapBuffers(hDC);
|
||||
GAME_LOG("Klatka wyrenderowana. FPS: " << fpsCounter.getFPS());
|
||||
LimitFPS(targetFPS);
|
||||
}
|
||||
}
|
||||
|
||||
ReleaseDC(hWnd, hDC);
|
||||
return msg.wParam;
|
||||
}
|
||||
|
||||
|
||||
// Window procedure, handles all messages for this program
|
||||
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
|
||||
static HGLRC hRC; // Permenant Rendering context
|
||||
static HDC hDC; // Private GDI Device context
|
||||
static HGLRC hRC;
|
||||
static HDC hDC;
|
||||
|
||||
switch (message) {
|
||||
// Window creation, setup for OpenGL
|
||||
case WM_CREATE:
|
||||
// Store the device context
|
||||
hDC = GetDC(hWnd);
|
||||
|
||||
// Select the pixel format
|
||||
SetDCPixelFormat(hDC);
|
||||
|
||||
// Create palette if needed
|
||||
hPalette = GetOpenGLPalette(hDC);
|
||||
|
||||
// Create the rendering context and make it current
|
||||
GetOpenGLPalette(hDC);
|
||||
hRC = wglCreateContext(hDC);
|
||||
wglMakeCurrent(hDC, hRC);
|
||||
SetupRC();
|
||||
glGenTextures(2, &texture[0]); // tworzy obiekt tekstury
|
||||
|
||||
// ładuje pierwszy obraz tekstury:
|
||||
bitmapData = LoadBitmapFile((char*)"Bitmapy\\checker.bmp", &bitmapInfoHeader);
|
||||
// Ładowanie tekstur (uproszczone dla czytelności, można wydzielić funkcję LoadTextures)
|
||||
{
|
||||
GLfloat fLargest;
|
||||
glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &fLargest);
|
||||
glGenTextures(4, &texture[0]);
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, texture[0]); // aktywuje obiekt tekstury
|
||||
// Tutaj możesz przenieść logikę ładowania tekstur do np. Utils.cpp -> LoadAllTextures()
|
||||
// Aby nie zaśmiecać WndProc.
|
||||
const char* texFiles[] = {
|
||||
"res/img/woodenTextureHighExposure.bmp",
|
||||
"res/img/grass02.bmp",
|
||||
"res/img/barnroof.bmp",
|
||||
"res/img/brickwall.bmp"
|
||||
};
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
|
||||
|
||||
// tworzy obraz tekstury
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, bitmapInfoHeader.biWidth,
|
||||
bitmapInfoHeader.biHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, bitmapData);
|
||||
|
||||
if (bitmapData) free(bitmapData);
|
||||
|
||||
// ładuje drugi obraz tekstury:
|
||||
bitmapData = LoadBitmapFile((char*)"Bitmapy\\crate.bmp", &bitmapInfoHeader);
|
||||
glBindTexture(GL_TEXTURE_2D, texture[1]); // aktywuje obiekt tekstury
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
|
||||
|
||||
// tworzy obraz tekstury
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, bitmapInfoHeader.biWidth,
|
||||
bitmapInfoHeader.biHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, bitmapData);
|
||||
|
||||
if (bitmapData) free(bitmapData);
|
||||
|
||||
// ustalenie sposobu mieszania tekstury z tłem
|
||||
for (int i = 0; i < 4; i++) {
|
||||
bitmapData = LoadBitmapFile((char*)texFiles[i], &bitmapInfoHeader);
|
||||
if (bitmapData) {
|
||||
glBindTexture(GL_TEXTURE_2D, texture[i]);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, fLargest);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT); // lub GL_CLAMP zależnie od idx
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT);
|
||||
gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, bitmapInfoHeader.biWidth, bitmapInfoHeader.biHeight, GL_RGB, GL_UNSIGNED_BYTE, bitmapData);
|
||||
free(bitmapData);
|
||||
}
|
||||
}
|
||||
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
||||
}
|
||||
break;
|
||||
|
||||
// Window is being destroyed, cleanup
|
||||
case WM_DESTROY:
|
||||
// Deselect the current rendering context and delete it
|
||||
user.unload();
|
||||
wglMakeCurrent(hDC, NULL);
|
||||
wglDeleteContext(hRC);
|
||||
|
||||
// Delete the palette if it was created
|
||||
if (hPalette != NULL) DeleteObject(hPalette);
|
||||
|
||||
// Tell the application to terminate after the window
|
||||
// is gone.
|
||||
PostQuitMessage(0);
|
||||
AsyncLogger::getInstance().stop();
|
||||
break;
|
||||
|
||||
// Window is resized.
|
||||
case WM_SIZE:
|
||||
// Call our function which modifies the clipping
|
||||
// volume and viewport
|
||||
ChangeSize(LOWORD(lParam), HIWORD(lParam));
|
||||
break;
|
||||
|
||||
|
||||
// The painting function. This message sent by Windows
|
||||
// whenever the screen needs updating.
|
||||
case WM_PAINT:
|
||||
// Call OpenGL drawing code
|
||||
RenderScene();
|
||||
|
||||
SwapBuffers(hDC);
|
||||
|
||||
// Validate the newly painted client area
|
||||
ValidateRect(hWnd, NULL);
|
||||
break;
|
||||
|
||||
// Windows is telling the application that it may modify
|
||||
// the system palette. This message in essance asks the
|
||||
// application for a new palette.
|
||||
case WM_QUERYNEWPALETTE:
|
||||
// If the palette was created.
|
||||
if (hPalette) {
|
||||
int nRet;
|
||||
|
||||
// Selects the palette into the current device context
|
||||
SelectPalette(hDC, hPalette, FALSE);
|
||||
|
||||
// Map entries from the currently selected palette to
|
||||
// the system palette. The return value is the number
|
||||
// of palette entries modified.
|
||||
nRet = RealizePalette(hDC);
|
||||
|
||||
// Repaint, forces remap of palette in current window
|
||||
InvalidateRect(hWnd, NULL, FALSE);
|
||||
|
||||
return nRet;
|
||||
case WM_MOUSEWHEEL:
|
||||
{
|
||||
int zDelta = GET_WHEEL_DELTA_WPARAM(wParam);
|
||||
CameraHeight -= (float)zDelta * 0.1f;
|
||||
if (CameraHeight < 20.0f) CameraHeight = 20.0f; // Stała MinDistance
|
||||
if (CameraHeight > 1000.0f) CameraHeight = 1000.0f; // Stała MaxDistance
|
||||
}
|
||||
break;
|
||||
|
||||
// This window may set the palette, even though it is not the
|
||||
// currently active window.
|
||||
case WM_PALETTECHANGED:
|
||||
// Don't do anything if the palette does not exist, or if
|
||||
// this is the window that changed the palette.
|
||||
if ((hPalette != NULL) && ((HWND)wParam != hWnd)) {
|
||||
// Select the palette into the device context
|
||||
SelectPalette(hDC, hPalette, FALSE);
|
||||
|
||||
// Map entries to system palette
|
||||
RealizePalette(hDC);
|
||||
|
||||
// Remap the current colors to the newly realized palette
|
||||
UpdateColors(hDC);
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
|
||||
// Key press, check for arrow keys to do cube rotation.
|
||||
case WM_KEYDOWN:
|
||||
|
||||
case WM_KEYUP:
|
||||
switch (wParam) {
|
||||
case VK_UP:
|
||||
xRot -= 5.0f;
|
||||
case 'W': keyWPressed = false; break;
|
||||
case 'S': keySPressed = false; break;
|
||||
case 'A': keyAPressed = false; break;
|
||||
case 'D': keyDPressed = false; break;
|
||||
case 112: // F1
|
||||
fpv_view = !fpv_view;
|
||||
if (fpv_view) panoramic_view = false;
|
||||
break;
|
||||
case 'N': dayNight.toggle(); break;
|
||||
}
|
||||
break;
|
||||
|
||||
case VK_DOWN:
|
||||
xRot += 5.0f;
|
||||
case WM_KEYDOWN:
|
||||
switch (wParam) {
|
||||
case VK_UP: xRot -= 5.0f; break;
|
||||
case VK_DOWN: xRot += 5.0f; break;
|
||||
case VK_LEFT: yRot -= 5.0f; break;
|
||||
case VK_RIGHT: yRot += 5.0f; break;
|
||||
case 'Q': zRot += 5.0f; break;
|
||||
case 'E': zRot -= 5.0f; break;
|
||||
case 'R': xRot = yRot = zRot = 0; break;
|
||||
case ' ': polygonmode = !polygonmode; break;
|
||||
case 'K': Kolizja = !Kolizja; break;
|
||||
case 'W': keyWPressed = true; break;
|
||||
case 'S': keySPressed = true; break;
|
||||
case 'A': keyAPressed = true; break;
|
||||
case 'D': keyDPressed = true; break;
|
||||
case 116: // F5
|
||||
case 16: // Shift
|
||||
panoramic_view = !panoramic_view; break;
|
||||
case 8: // Backspace
|
||||
nadpiszNowaSiatke(biezacy_wzor); // Zakładam, że ta zmienna jest w fabula.hpp
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case VK_LEFT:
|
||||
yRot -= 5.0f;
|
||||
break;
|
||||
|
||||
case VK_RIGHT:
|
||||
yRot += 5.0f;
|
||||
break;
|
||||
|
||||
case 'Q':
|
||||
zRot += 5.0f;
|
||||
break;
|
||||
|
||||
case 'E':
|
||||
zRot -= 5.0f;
|
||||
break;
|
||||
|
||||
case 'R':
|
||||
xRot = 0;
|
||||
yRot = 0;
|
||||
zRot = 0;
|
||||
break;
|
||||
|
||||
case ' ': // 32
|
||||
polygonmode = !polygonmode;
|
||||
getTime;
|
||||
if (polygonmode) timestampedCout("Uwaga! Tryb wireframe jest niewydajny i powinien sluzyc tylko do debugowania!");
|
||||
case WM_COMMAND:
|
||||
switch (LOWORD(wParam)) {
|
||||
case ID_FILE_EXIT: DestroyWindow(hWnd); break;
|
||||
case ID_HELP_ABOUT: DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG_ABOUT), hWnd, (DLGPROC)AboutDlgProc); break;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
getTime;
|
||||
timestampedCout("Nacisnieto nierozpoznany klawisz: " << (int)wParam);
|
||||
}
|
||||
|
||||
xRot = (const int)xRot % 360;
|
||||
yRot = (const int)yRot % 360;
|
||||
zRot = (const int)zRot % 360;
|
||||
|
||||
InvalidateRect(hWnd, NULL, FALSE);
|
||||
break;
|
||||
|
||||
// A menu command
|
||||
case WM_COMMAND:
|
||||
|
||||
switch (LOWORD(wParam)) {
|
||||
|
||||
// Exit the program
|
||||
case ID_FILE_EXIT:
|
||||
DestroyWindow(hWnd);
|
||||
break;
|
||||
|
||||
// Display the about box
|
||||
case ID_HELP_ABOUT:
|
||||
DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG_ABOUT), hWnd, (DLGPROC)AboutDlgProc);
|
||||
break;
|
||||
|
||||
}
|
||||
break;
|
||||
|
||||
default: // Passes it on if unproccessed
|
||||
return (DefWindowProc(hWnd, message, wParam, lParam));
|
||||
}
|
||||
|
||||
return (0L);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// Dialog procedure.
|
||||
BOOL APIENTRY AboutDlgProc(HWND hDlg, UINT message, UINT wParam, LONG lParam) {
|
||||
|
||||
switch (message) {
|
||||
// Initialize the dialog box
|
||||
case WM_INITDIALOG:
|
||||
int i;
|
||||
GLenum glError;
|
||||
|
||||
// glGetString demo
|
||||
SetDlgItemText(hDlg, IDC_OPENGL_VENDOR, reinterpret_cast<LPCSTR>(glGetString(GL_VENDOR)));
|
||||
SetDlgItemText(hDlg, IDC_OPENGL_RENDERER, (LPCSTR)glGetString(GL_RENDERER));
|
||||
SetDlgItemText(hDlg, IDC_OPENGL_VERSION, (LPCSTR)glGetString(GL_VERSION));
|
||||
SetDlgItemText(hDlg, IDC_OPENGL_EXTENSIONS, (LPCSTR)glGetString(GL_EXTENSIONS));
|
||||
|
||||
// gluGetString demo
|
||||
SetDlgItemText(hDlg, IDC_GLU_VERSION, (LPCSTR)gluGetString(GLU_VERSION));
|
||||
SetDlgItemText(hDlg, IDC_GLU_EXTENSIONS, (LPCSTR)gluGetString(GLU_EXTENSIONS));
|
||||
|
||||
|
||||
// Display any recent error messages
|
||||
i = 0;
|
||||
do {
|
||||
glError = glGetError();
|
||||
SetDlgItemText(hDlg, IDC_ERROR1 + i, (LPCSTR)gluErrorString(glError));
|
||||
i++;
|
||||
} while (i < 6 && glError != GL_NO_ERROR);
|
||||
|
||||
|
||||
return (TRUE);
|
||||
|
||||
break;
|
||||
|
||||
// Process command messages
|
||||
case WM_COMMAND:
|
||||
|
||||
// Validate and Make the changes
|
||||
if (LOWORD(wParam) == IDOK) EndDialog(hDlg, TRUE);
|
||||
break;
|
||||
|
||||
// Closed from sysbox
|
||||
case WM_CLOSE:
|
||||
|
||||
EndDialog(hDlg, TRUE);
|
||||
break;
|
||||
|
||||
if (message == WM_INITDIALOG) {
|
||||
// ... (Kod dialogu bez zmian, ewentualnie dodaj include gluGetString)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (message == WM_COMMAND && LOWORD(wParam) == IDOK) EndDialog(hDlg, TRUE);
|
||||
if (message == WM_CLOSE) EndDialog(hDlg, TRUE);
|
||||
return FALSE;
|
||||
}
|
||||
BIN
output.exe
75
plane.cpp
Normal file
@@ -0,0 +1,75 @@
|
||||
#include "plane.hpp"
|
||||
|
||||
plane::plane(float x, float y, float z, const char* modelpath){
|
||||
|
||||
this->c_x = x;
|
||||
this->c_y = y;
|
||||
this->c_z = z;
|
||||
this->modelpath = modelpath;
|
||||
timestampedCout("plane.cpp: Zaladowano dane w konstruktorze.")
|
||||
|
||||
}
|
||||
|
||||
void plane::loadModel() {
|
||||
|
||||
timestampedCout("plane.cpp:");
|
||||
std::cout << " Ladowanie modelu ze sciezki " << this->modelpath << "...\n";
|
||||
bool res = loadOBJ(this->modelpath, this->vertices, this->uvs, this->normals);
|
||||
if (res) timestampedCout("Pomyslnie zaladowano model mapki.")
|
||||
else timestampedCout("Nie udalo sie zaladowac modelu mapki.");
|
||||
|
||||
glGenBuffers(1, &vertexbuffer);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, this->vertexbuffer);
|
||||
glBufferData(GL_ARRAY_BUFFER, this->vertices.size() * sizeof(glm::vec3), &vertices[0], GL_STATIC_DRAW);
|
||||
|
||||
glGenBuffers(1, &uvbuffer);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, this->uvbuffer);
|
||||
glBufferData(GL_ARRAY_BUFFER, this->uvs.size() * sizeof(glm::vec2), &uvs[0], GL_STATIC_DRAW);
|
||||
|
||||
}
|
||||
|
||||
void plane::draw() {
|
||||
|
||||
// 1st attribute buffer: vertices
|
||||
glEnableVertexAttribArray(0);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, this->vertexbuffer);
|
||||
glVertexAttribPointer(
|
||||
0, // attribute
|
||||
3, // size
|
||||
GL_FLOAT, // type
|
||||
GL_FALSE, // normalized?
|
||||
0, // stride
|
||||
(void*)0 // array buffer offset
|
||||
);
|
||||
|
||||
// 2nd attribute buffer: UVs
|
||||
glEnableVertexAttribArray(1);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, this->uvbuffer);
|
||||
glVertexAttribPointer(
|
||||
1, // attribute
|
||||
2, // size
|
||||
GL_FLOAT, // type
|
||||
GL_FALSE, // normalized?
|
||||
0, // stride
|
||||
(void*)0 // array buffer offset
|
||||
);
|
||||
|
||||
// Draw vertices
|
||||
glDrawArrays(GL_TRIANGLES, 0, this->vertices.size());
|
||||
|
||||
glDisableVertexAttribArray(0);
|
||||
glDisableVertexAttribArray(1);
|
||||
|
||||
}
|
||||
|
||||
void plane::moveX(float x){
|
||||
timestampedCout("dummy moveX");
|
||||
}
|
||||
|
||||
void plane::moveY(float y){
|
||||
timestampedCout("dummy moveY");
|
||||
}
|
||||
|
||||
void plane::moveZ(float z){
|
||||
timestampedCout("dummy moveZ");
|
||||
}
|
||||
34
plane.hpp
Normal file
@@ -0,0 +1,34 @@
|
||||
#pragma once
|
||||
#include <windows.h>
|
||||
#include "GL/glew.h"
|
||||
#include <gl/gl.h>
|
||||
#include <gl/glu.h>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include "timeh.hpp"
|
||||
#include "GL/glm/glm.hpp"
|
||||
#include "loadOBJ.h"
|
||||
#include "texture.hpp"
|
||||
|
||||
class plane {
|
||||
private:
|
||||
float c_x{0};
|
||||
float c_y{0};
|
||||
float c_z{0};
|
||||
float rot_x{0};
|
||||
float rot_y{0};
|
||||
float rot_z{0};
|
||||
std::vector <glm::vec3> vertices;
|
||||
std::vector <glm::vec2> uvs;
|
||||
std::vector <glm::vec3> normals; // Won't be used at the moment.
|
||||
GLuint vertexbuffer;
|
||||
GLuint uvbuffer;
|
||||
const char* modelpath;
|
||||
public:
|
||||
plane(float x, float y, float z, const char* modelpath);
|
||||
void loadModel();
|
||||
void draw();
|
||||
void moveX(float x);
|
||||
void moveY(float y);
|
||||
void moveZ(float z);
|
||||
};
|
||||
137
rain.hpp
Normal file
@@ -0,0 +1,137 @@
|
||||
#ifndef RAIN_HPP
|
||||
#define RAIN_HPP
|
||||
|
||||
#include <vector>
|
||||
#include <cstdlib>
|
||||
#include <ctime>
|
||||
#include <cmath>
|
||||
#include "GL/glew.h"
|
||||
|
||||
// Struktura pojedynczej kropli
|
||||
struct RainDrop {
|
||||
float x, y, z; // Pozycja
|
||||
float speed; // Prędkość spadania
|
||||
bool isSplash; // Czy to jest moment rozbicia?
|
||||
float splashTime; // Czas trwania animacji rozbicia
|
||||
float life; // Do losowania długości życia kropli
|
||||
};
|
||||
|
||||
class RainSystem {
|
||||
private:
|
||||
std::vector<RainDrop> drops;
|
||||
int maxDrops;
|
||||
float range; // Promień wokół gracza, gdzie pada deszcz
|
||||
float skyHeight; // Wysokość, z której spada deszcz
|
||||
|
||||
// Funkcja pomocnicza do losowania liczb float
|
||||
float randomFloat(float min, float max) {
|
||||
return min + static_cast<float>(rand()) / (static_cast<float>(RAND_MAX / (max - min)));
|
||||
}
|
||||
|
||||
public:
|
||||
RainSystem(int count = 2000, float rangeRadius = 300.0f, float height = 200.0f) {
|
||||
maxDrops = count;
|
||||
range = rangeRadius;
|
||||
skyHeight = height;
|
||||
|
||||
// Inicjalizacja kropel
|
||||
for (int i = 0; i < maxDrops; i++) {
|
||||
RainDrop drop;
|
||||
drop.isSplash = false;
|
||||
drop.splashTime = 0.0f;
|
||||
drop.speed = randomFloat(200.0f, 300.0f); // Szybkość deszczu
|
||||
|
||||
// Losowa pozycja początkowa
|
||||
drop.x = randomFloat(-range, range);
|
||||
drop.y = randomFloat(0.0f, skyHeight * 2.0f); // Rozrzucamy je w pionie na start
|
||||
drop.z = randomFloat(-range, range);
|
||||
|
||||
drops.push_back(drop);
|
||||
}
|
||||
}
|
||||
|
||||
// Aktualizacja fizyki deszczu
|
||||
void update(float deltaTime, float playerX, float playerZ) {
|
||||
for (auto& drop : drops) {
|
||||
if (drop.isSplash) {
|
||||
// Obsługa animacji rozbicia
|
||||
drop.splashTime -= deltaTime;
|
||||
if (drop.splashTime <= 0.0f) {
|
||||
// Koniec rozbicia, reset kropli do nieba
|
||||
drop.isSplash = false;
|
||||
drop.y = skyHeight + randomFloat(0.0f, 50.0f);
|
||||
|
||||
// Reset pozycji względem gracza (deszcz podąża za łazikiem)
|
||||
drop.x = playerX + randomFloat(-range, range);
|
||||
drop.z = playerZ + randomFloat(-range, range);
|
||||
drop.speed = randomFloat(200.0f, 300.0f);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Spadanie
|
||||
drop.y -= drop.speed * deltaTime;
|
||||
|
||||
// Sprawdzenie kolizji z podłogą (y <= 0)
|
||||
if (drop.y <= 0.0f) {
|
||||
drop.y = 0.1f; // Lekko nad ziemią
|
||||
drop.isSplash = true;
|
||||
drop.splashTime = 0.2f; // Czas trwania "plusku" (0.2 sekundy)
|
||||
}
|
||||
|
||||
// Jeśli gracz uciekł zbyt daleko od kropli, przenieś ją bliżej gracza
|
||||
// (Optymalizacja: nie liczymy deszczu tam, gdzie nas nie ma)
|
||||
if (std::abs(drop.x - playerX) > range) drop.x = playerX + randomFloat(-range, range);
|
||||
if (std::abs(drop.z - playerZ) > range) drop.z = playerZ + randomFloat(-range, range);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Rysowanie deszczu
|
||||
void draw() {
|
||||
// Zapisujemy aktualny stan OpenGL
|
||||
glPushAttrib(GL_ENABLE_BIT | GL_CURRENT_BIT | GL_POINT_BIT | GL_LINE_BIT);
|
||||
|
||||
glDisable(GL_LIGHTING); // Deszcz ma własny kolor, nie potrzebuje cieniowania
|
||||
glDisable(GL_TEXTURE_2D); // Deszcz to linie, nie tekstury
|
||||
glEnable(GL_BLEND); // Przezroczystość
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glDepthMask(GL_FALSE); // Deszcz nie powinien zasłaniać obiektów w buforze głębokości (opcjonalne)
|
||||
|
||||
glLineWidth(1.0f);
|
||||
|
||||
glBegin(GL_LINES);
|
||||
glColor4f(0.7f, 0.8f, 1.0f, 0.6f); // Jasnoniebieski, lekko przezroczysty
|
||||
|
||||
for (const auto& drop : drops) {
|
||||
if (!drop.isSplash) {
|
||||
// Rysuj spadającą linię (długość zależna od prędkości dla efektu rozmycia)
|
||||
glVertex3f(drop.x, drop.y, drop.z);
|
||||
glVertex3f(drop.x, drop.y + 4.0f, drop.z);
|
||||
}
|
||||
}
|
||||
glEnd();
|
||||
|
||||
// Rysowanie rozbryzgów (jako punkty)
|
||||
glPointSize(3.0f); // Grubsze kropki dla rozbryzgów
|
||||
glBegin(GL_POINTS);
|
||||
glColor4f(0.9f, 0.9f, 1.0f, 0.8f); // Bardziej białe przy uderzeniu
|
||||
|
||||
for (const auto& drop : drops) {
|
||||
if (drop.isSplash) {
|
||||
// Mały losowy rozrzut dla efektu rozbicia
|
||||
float splashOffset = (0.2f - drop.splashTime) * 10.0f; // Rozszerza się z czasem
|
||||
|
||||
// Rysujemy 3 małe kropelki odbijające się od ziemi
|
||||
glVertex3f(drop.x + splashOffset, drop.y + splashOffset * 0.5f, drop.z);
|
||||
glVertex3f(drop.x - splashOffset, drop.y + splashOffset * 0.5f, drop.z);
|
||||
glVertex3f(drop.x, drop.y + splashOffset, drop.z + splashOffset);
|
||||
}
|
||||
}
|
||||
glEnd();
|
||||
|
||||
glDepthMask(GL_TRUE); // Przywracamy zapis do bufora głębokości
|
||||
glPopAttrib(); // Przywracamy stare ustawienia
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
BIN
res/img/barnroof.bmp
Normal file
|
After Width: | Height: | Size: 768 KiB |
BIN
res/img/brickwall.bmp
Normal file
|
After Width: | Height: | Size: 768 KiB |
BIN
res/img/grass01.bmp
Normal file
|
After Width: | Height: | Size: 768 KiB |
BIN
res/img/grass02.bmp
Normal file
|
After Width: | Height: | Size: 768 KiB |
BIN
res/img/t01.bmp
Normal file
|
After Width: | Height: | Size: 768 KiB |
BIN
res/img/t02.bmp
Normal file
|
After Width: | Height: | Size: 768 KiB |
BIN
res/img/woodenTexture.bmp
Normal file
|
After Width: | Height: | Size: 3.0 MiB |
BIN
res/img/woodenTextureHighExposure.bmp
Normal file
|
After Width: | Height: | Size: 3.0 MiB |
@@ -1,44 +1,47 @@
|
||||
# Blender 4.2.1 LTS
|
||||
# www.blender.org
|
||||
o Cube
|
||||
v 1.000000 1.000000 -1.000000
|
||||
# Blender3D v249 OBJ File: untitled.blend
|
||||
# www.blender3d.org
|
||||
mtllib cube.mtl
|
||||
v 1.000000 -1.000000 -1.000000
|
||||
v 1.000000 1.000000 1.000000
|
||||
v 1.000000 -1.000000 1.000000
|
||||
v -1.000000 1.000000 -1.000000
|
||||
v -1.000000 -1.000000 -1.000000
|
||||
v -1.000000 1.000000 1.000000
|
||||
v -1.000000 -1.000000 1.000000
|
||||
vn -0.0000 1.0000 -0.0000
|
||||
vn -0.0000 -0.0000 1.0000
|
||||
vn -1.0000 -0.0000 -0.0000
|
||||
vn -0.0000 -1.0000 -0.0000
|
||||
vn 1.0000 -0.0000 -0.0000
|
||||
vn -0.0000 -0.0000 -1.0000
|
||||
vt 0.875000 0.500000
|
||||
vt 0.625000 0.750000
|
||||
vt 0.625000 0.500000
|
||||
vt 0.375000 1.000000
|
||||
vt 0.375000 0.750000
|
||||
vt 0.625000 0.000000
|
||||
vt 0.375000 0.250000
|
||||
vt 0.375000 0.000000
|
||||
vt 0.375000 0.500000
|
||||
vt 0.125000 0.750000
|
||||
vt 0.125000 0.500000
|
||||
vt 0.625000 0.250000
|
||||
vt 0.875000 0.750000
|
||||
vt 0.625000 1.000000
|
||||
s 0
|
||||
f 5/1/1 3/2/1 1/3/1
|
||||
f 3/2/2 8/4/2 4/5/2
|
||||
f 7/6/3 6/7/3 8/8/3
|
||||
f 2/9/4 8/10/4 6/11/4
|
||||
f 1/3/5 4/5/5 2/9/5
|
||||
f 5/12/6 2/9/6 6/7/6
|
||||
f 5/1/1 7/13/1 3/2/1
|
||||
f 3/2/2 7/14/2 8/4/2
|
||||
f 7/6/3 5/12/3 6/7/3
|
||||
f 2/9/4 4/5/4 8/10/4
|
||||
f 1/3/5 3/2/5 4/5/5
|
||||
f 5/12/6 1/3/6 2/9/6
|
||||
v -1.000000 -1.000000 -1.000000
|
||||
v 1.000000 1.000000 -1.000000
|
||||
v 0.999999 1.000000 1.000001
|
||||
v -1.000000 1.000000 1.000000
|
||||
v -1.000000 1.000000 -1.000000
|
||||
vt 0.748573 0.750412
|
||||
vt 0.749279 0.501284
|
||||
vt 0.999110 0.501077
|
||||
vt 0.999455 0.750380
|
||||
vt 0.250471 0.500702
|
||||
vt 0.249682 0.749677
|
||||
vt 0.001085 0.750380
|
||||
vt 0.001517 0.499994
|
||||
vt 0.499422 0.500239
|
||||
vt 0.500149 0.750166
|
||||
vt 0.748355 0.998230
|
||||
vt 0.500193 0.998728
|
||||
vt 0.498993 0.250415
|
||||
vt 0.748953 0.250920
|
||||
vn 0.000000 0.000000 -1.000000
|
||||
vn -1.000000 -0.000000 -0.000000
|
||||
vn -0.000000 -0.000000 1.000000
|
||||
vn -0.000001 0.000000 1.000000
|
||||
vn 1.000000 -0.000000 0.000000
|
||||
vn 1.000000 0.000000 0.000001
|
||||
vn 0.000000 1.000000 -0.000000
|
||||
vn -0.000000 -1.000000 0.000000
|
||||
usemtl Material_ray.png
|
||||
s off
|
||||
f 5/1/1 1/2/1 4/3/1
|
||||
f 5/1/1 4/3/1 8/4/1
|
||||
f 3/5/2 7/6/2 8/7/2
|
||||
f 3/5/2 8/7/2 4/8/2
|
||||
f 2/9/3 6/10/3 3/5/3
|
||||
f 6/10/4 7/6/4 3/5/4
|
||||
f 1/2/5 5/1/5 2/9/5
|
||||
f 5/1/6 6/10/6 2/9/6
|
||||
f 5/1/7 8/11/7 6/10/7
|
||||
f 8/11/7 7/12/7 6/10/7
|
||||
f 1/2/8 2/9/8 3/13/8
|
||||
f 1/2/8 3/13/8 4/14/8
|
||||
|
||||
44
res/models/kostka.obj
Normal file
@@ -0,0 +1,44 @@
|
||||
# Blender 4.2.1 LTS
|
||||
# www.blender.org
|
||||
o Cube
|
||||
v 1.000000 1.000000 -1.000000
|
||||
v 1.000000 -1.000000 -1.000000
|
||||
v 1.000000 1.000000 1.000000
|
||||
v 1.000000 -1.000000 1.000000
|
||||
v -1.000000 1.000000 -1.000000
|
||||
v -1.000000 -1.000000 -1.000000
|
||||
v -1.000000 1.000000 1.000000
|
||||
v -1.000000 -1.000000 1.000000
|
||||
vn -0.0000 1.0000 -0.0000
|
||||
vn -0.0000 -0.0000 1.0000
|
||||
vn -1.0000 -0.0000 -0.0000
|
||||
vn -0.0000 -1.0000 -0.0000
|
||||
vn 1.0000 -0.0000 -0.0000
|
||||
vn -0.0000 -0.0000 -1.0000
|
||||
vt 0.875000 0.500000
|
||||
vt 0.625000 0.750000
|
||||
vt 0.625000 0.500000
|
||||
vt 0.375000 1.000000
|
||||
vt 0.375000 0.750000
|
||||
vt 0.625000 0.000000
|
||||
vt 0.375000 0.250000
|
||||
vt 0.375000 0.000000
|
||||
vt 0.375000 0.500000
|
||||
vt 0.125000 0.750000
|
||||
vt 0.125000 0.500000
|
||||
vt 0.625000 0.250000
|
||||
vt 0.875000 0.750000
|
||||
vt 0.625000 1.000000
|
||||
s 0
|
||||
f 5/1/1 3/2/1 1/3/1
|
||||
f 3/2/2 8/4/2 4/5/2
|
||||
f 7/6/3 6/7/3 8/8/3
|
||||
f 2/9/4 8/10/4 6/11/4
|
||||
f 1/3/5 4/5/5 2/9/5
|
||||
f 5/12/6 2/9/6 6/7/6
|
||||
f 5/1/1 7/13/1 3/2/1
|
||||
f 3/2/2 7/14/2 8/4/2
|
||||
f 7/6/3 5/12/3 6/7/3
|
||||
f 2/9/4 4/5/4 8/10/4
|
||||
f 1/3/5 3/2/5 4/5/5
|
||||
f 5/12/6 1/3/6 2/9/6
|
||||
44
res/models/kostkawieksza.obj
Normal file
@@ -0,0 +1,44 @@
|
||||
# Blender 4.2.1 LTS
|
||||
# www.blender.org
|
||||
o Cube
|
||||
v 10.000000 10.000000 -10.000000
|
||||
v 10.000000 -10.000000 -10.000000
|
||||
v 10.000000 10.000000 10.000000
|
||||
v 10.000000 -10.000000 10.000000
|
||||
v -10.000000 10.000000 -10.000000
|
||||
v -10.000000 -10.000000 -10.000000
|
||||
v -10.000000 10.000000 10.000000
|
||||
v -10.000000 -10.000000 10.000000
|
||||
vn -0.0000 1.0000 -0.0000
|
||||
vn -0.0000 -0.0000 1.0000
|
||||
vn -1.0000 -0.0000 -0.0000
|
||||
vn -0.0000 -1.0000 -0.0000
|
||||
vn 1.0000 -0.0000 -0.0000
|
||||
vn -0.0000 -0.0000 -1.0000
|
||||
vt 0.500000 0.250000
|
||||
vt 0.750000 0.500000
|
||||
vt 0.500000 0.500000
|
||||
vt 1.000000 0.750000
|
||||
vt 0.750000 0.750000
|
||||
vt 0.000000 0.500000
|
||||
vt 0.250000 0.750000
|
||||
vt 0.000000 0.750000
|
||||
vt 0.500000 0.750000
|
||||
vt 0.750000 1.000000
|
||||
vt 0.500000 1.000000
|
||||
vt 0.250000 0.500000
|
||||
vt 0.750000 0.250000
|
||||
vt 1.000000 0.500000
|
||||
s 0
|
||||
f 5/1/1 3/2/1 1/3/1
|
||||
f 3/2/2 8/4/2 4/5/2
|
||||
f 7/6/3 6/7/3 8/8/3
|
||||
f 2/9/4 8/10/4 6/11/4
|
||||
f 1/3/5 4/5/5 2/9/5
|
||||
f 5/12/6 2/9/6 6/7/6
|
||||
f 5/1/1 7/13/1 3/2/1
|
||||
f 3/2/2 7/14/2 8/4/2
|
||||
f 7/6/3 5/12/3 6/7/3
|
||||
f 2/9/4 4/5/4 8/10/4
|
||||
f 1/3/5 3/2/5 4/5/5
|
||||
f 5/12/6 1/3/6 2/9/6
|
||||
7421
res/models/lazik4.obj
Normal file
89
res/models/mapka.obj
Normal file
@@ -0,0 +1,89 @@
|
||||
# Blender 4.2.1 LTS
|
||||
# www.blender.org
|
||||
o Plane
|
||||
v -25.000000 -0.200000 25.000000
|
||||
v 275.000000 -0.200000 25.000000
|
||||
v -25.000000 -0.200000 -275.000000
|
||||
v 275.000000 -0.200000 -275.000000
|
||||
vn -0.0000 1.0000 -0.0000
|
||||
vt 1.000000 0.000000
|
||||
vt 0.000000 1.000000
|
||||
vt 0.000000 0.000000
|
||||
vt 1.000000 1.000000
|
||||
s 0
|
||||
f 2/1/1 3/2/1 1/3/1
|
||||
f 2/1/1 4/4/1 3/2/1
|
||||
o Cube
|
||||
v -15.000000 0.000000 15.000000
|
||||
v -15.000000 40.000000 15.000000
|
||||
v -15.000000 0.000000 -35.000004
|
||||
v -15.000000 40.000000 -35.000004
|
||||
v 15.000000 0.000000 15.000000
|
||||
v 15.000000 40.000000 15.000000
|
||||
v 15.000000 0.000000 -35.000004
|
||||
v 15.000000 40.000000 -35.000004
|
||||
v 0.000000 52.654823 15.000000
|
||||
v 0.000000 52.654823 -35.000004
|
||||
v -15.000000 20.000000 -35.000004
|
||||
v 0.000000 40.000000 -35.000004
|
||||
v 15.000000 20.000000 -35.000004
|
||||
v 0.000000 20.000000 -35.000004
|
||||
v -15.000000 10.000000 -35.000004
|
||||
v -7.500000 20.000000 -35.000004
|
||||
v 15.000000 10.000000 -35.000004
|
||||
v 7.500000 20.000000 -35.000004
|
||||
vn -1.0000 -0.0000 -0.0000
|
||||
vn -0.0000 -0.0000 -1.0000
|
||||
vn 1.0000 -0.0000 -0.0000
|
||||
vn -0.0000 -0.0000 1.0000
|
||||
vn -0.6448 0.7643 -0.0000
|
||||
vn 0.6448 0.7643 -0.0000
|
||||
vt 0.625000 0.000000
|
||||
vt 0.500000 0.250000
|
||||
vt 0.437500 0.250000
|
||||
vt 0.625000 0.375000
|
||||
vt 0.500000 0.500000
|
||||
vt 0.500000 0.437500
|
||||
vt 0.625000 0.750000
|
||||
vt 0.375000 0.750000
|
||||
vt 0.375000 1.000000
|
||||
vt 0.750000 0.750000
|
||||
vt 0.000000 0.000000
|
||||
vt 0.437500 0.500000
|
||||
vt 0.625000 0.250000
|
||||
vt 0.500000 0.375000
|
||||
vt 0.500000 0.312500
|
||||
vt 0.375000 0.250000
|
||||
vt 0.750000 0.500000
|
||||
vt 0.625000 0.500000
|
||||
vt 0.375000 0.000000
|
||||
vt 0.375000 0.500000
|
||||
vt 0.625000 1.000000
|
||||
s 0
|
||||
f 6/5/2 15/6/2 19/7/2
|
||||
f 16/8/3 17/9/3 22/10/3
|
||||
f 17/9/4 10/11/4 9/12/4
|
||||
f 10/11/5 5/13/5 9/12/5
|
||||
f 13/14/6 8/15/6 6/15/6
|
||||
f 21/16/3 22/10/3 17/9/3
|
||||
f 8/17/3 18/18/3 20/19/3
|
||||
f 19/7/3 20/19/3 7/20/3
|
||||
f 16/8/3 14/21/3 12/22/3
|
||||
f 12/22/7 13/14/7 10/11/7
|
||||
f 6/15/5 10/11/5 13/14/5
|
||||
f 7/20/2 5/23/2 6/5/2
|
||||
f 6/5/2 8/17/2 15/6/2
|
||||
f 19/7/2 7/20/2 6/5/2
|
||||
f 22/10/3 18/18/3 16/8/3
|
||||
f 16/8/3 12/22/3 17/9/3
|
||||
f 9/12/4 11/24/4 21/16/4
|
||||
f 17/9/4 12/22/4 10/11/4
|
||||
f 9/12/4 21/16/4 17/9/4
|
||||
f 10/11/5 6/25/5 5/13/5
|
||||
f 13/14/6 14/21/6 8/15/6
|
||||
f 21/16/3 11/24/3 22/10/3
|
||||
f 20/19/3 15/6/3 8/17/3
|
||||
f 8/17/3 16/8/3 18/18/3
|
||||
f 19/7/3 15/6/3 20/19/3
|
||||
f 16/8/3 8/15/3 14/21/3
|
||||
f 12/22/7 14/21/7 13/14/7
|
||||
1101
res/models/mapka2.obj
Normal file
2274083
res/models/mapka3.obj
Normal file
267
res/models/mapka3_nofence.obj
Normal file
@@ -0,0 +1,267 @@
|
||||
# Blender 4.2.1 LTS
|
||||
# www.blender.org
|
||||
o platforma
|
||||
v -10.000000 0.000000 110.000000
|
||||
v -10.000000 -2.000000 110.000000
|
||||
v -10.000000 0.000000 -20.000000
|
||||
v -10.000000 -2.000000 -20.000000
|
||||
v 110.000000 0.000000 110.000000
|
||||
v 110.000000 -2.000000 110.000000
|
||||
v 110.000000 0.000000 -20.000000
|
||||
v 110.000000 -2.000000 -20.000000
|
||||
vn -0.0000 1.0000 -0.0000
|
||||
vn -0.0000 -0.0000 -1.0000
|
||||
vn 1.0000 -0.0000 -0.0000
|
||||
vn -0.0000 -1.0000 -0.0000
|
||||
vn -1.0000 -0.0000 -0.0000
|
||||
vn -0.0000 -0.0000 1.0000
|
||||
vt 0.875000 0.500000
|
||||
vt 0.625000 0.750000
|
||||
vt 0.625000 0.500000
|
||||
vt 0.375000 1.000000
|
||||
vt 0.375000 0.750000
|
||||
vt 0.625000 0.000000
|
||||
vt 0.375000 0.250000
|
||||
vt 0.375000 0.000000
|
||||
vt 0.375000 0.500000
|
||||
vt 0.125000 0.750000
|
||||
vt 0.125000 0.500000
|
||||
vt 0.625000 0.250000
|
||||
vt 0.875000 0.750000
|
||||
vt 0.625000 1.000000
|
||||
s 0
|
||||
f 5/1/1 3/2/1 1/3/1
|
||||
f 3/2/2 8/4/2 4/5/2
|
||||
f 7/6/3 6/7/3 8/8/3
|
||||
f 2/9/4 8/10/4 6/11/4
|
||||
f 1/3/5 4/5/5 2/9/5
|
||||
f 5/12/6 2/9/6 6/7/6
|
||||
f 5/1/1 7/13/1 3/2/1
|
||||
f 3/2/2 7/14/2 8/4/2
|
||||
f 7/6/3 5/12/3 6/7/3
|
||||
f 2/9/4 4/5/4 8/10/4
|
||||
f 1/3/5 3/2/5 4/5/5
|
||||
f 5/12/6 1/3/6 2/9/6
|
||||
o szopa
|
||||
v 10.000000 0.000000 -19.000000
|
||||
v 10.000000 21.000000 -19.000000
|
||||
v 10.000000 0.000000 -1.000000
|
||||
v 10.000000 21.000000 -1.000000
|
||||
v -9.000000 0.000000 -19.000000
|
||||
v -9.000000 21.000000 -19.000000
|
||||
v -9.000000 0.000000 -1.000000
|
||||
v -9.000000 21.000000 -1.000000
|
||||
v 10.000000 0.000000 -3.000000
|
||||
v 10.000000 0.000000 -17.000000
|
||||
v 10.000000 2.333333 -19.000000
|
||||
v 10.000000 4.666667 -19.000000
|
||||
v 10.000000 7.000000 -19.000000
|
||||
v 10.000000 9.333334 -19.000000
|
||||
v 10.000000 11.666667 -19.000000
|
||||
v 10.000000 14.000000 -19.000000
|
||||
v 10.000000 16.333334 -19.000000
|
||||
v 10.000000 18.666668 -19.000000
|
||||
v 10.000000 21.000000 -17.000000
|
||||
v 10.000000 21.000000 -15.000000
|
||||
v 10.000000 21.000000 -13.000000
|
||||
v 10.000000 21.000000 -11.000000
|
||||
v 10.000000 21.000000 -9.000000
|
||||
v 10.000000 21.000000 -7.000000
|
||||
v 10.000000 21.000000 -5.000000
|
||||
v 10.000000 21.000000 -3.000000
|
||||
v 10.000000 18.666668 -1.000000
|
||||
v 10.000000 16.333334 -1.000000
|
||||
v 10.000000 14.000000 -1.000000
|
||||
v 10.000000 11.666666 -1.000000
|
||||
v 10.000000 9.333333 -1.000000
|
||||
v 10.000000 7.000000 -1.000000
|
||||
v 10.000000 4.666667 -1.000000
|
||||
v 10.000000 2.333333 -1.000000
|
||||
v 10.000000 2.333333 -17.000000
|
||||
v 10.000000 2.333333 -3.000000
|
||||
v 10.000000 4.666667 -17.000000
|
||||
v 10.000000 4.666667 -3.000000
|
||||
v 10.000000 7.000000 -17.000000
|
||||
v 10.000000 7.000000 -3.000000
|
||||
v 10.000000 9.333334 -17.000000
|
||||
v 10.000000 9.333334 -15.000000
|
||||
v 10.000000 9.333333 -5.000000
|
||||
v 10.000000 9.333333 -3.000000
|
||||
v 10.000000 11.666667 -17.000000
|
||||
v 10.000000 11.666667 -15.000000
|
||||
v 10.000000 11.666667 -13.000000
|
||||
v 10.000000 11.666667 -11.000000
|
||||
v 10.000000 11.666667 -9.000000
|
||||
v 10.000000 11.666667 -7.000000
|
||||
v 10.000000 11.666667 -5.000000
|
||||
v 10.000000 11.666666 -3.000000
|
||||
v 10.000000 21.000000 -19.000000
|
||||
v 10.000000 21.000000 -1.000000
|
||||
v -9.000000 21.000000 -19.000000
|
||||
v -9.000000 21.000000 -1.000000
|
||||
v 10.000000 32.000000 -10.000000
|
||||
v -9.000000 32.000000 -10.000000
|
||||
vn -0.0000 -0.0000 1.0000
|
||||
vn -1.0000 -0.0000 -0.0000
|
||||
vn -0.0000 -0.0000 -1.0000
|
||||
vn 1.0000 -0.0000 -0.0000
|
||||
vn -0.0000 0.6332 -0.7740
|
||||
vn -0.0000 0.6332 0.7740
|
||||
vt 0.513889 0.250000
|
||||
vt 0.541667 0.250000
|
||||
vt 0.375000 0.500000
|
||||
vt 0.625000 0.500000
|
||||
vt 0.375000 0.750000
|
||||
vt 0.625000 0.750000
|
||||
vt 0.486111 1.000000
|
||||
vt 0.458333 1.000000
|
||||
vt 0.486111 0.000000
|
||||
vt 0.486111 0.027778
|
||||
vt 0.458333 0.027778
|
||||
vt 0.486111 0.222222
|
||||
vt 0.458333 0.222222
|
||||
vt 0.486111 0.194444
|
||||
vt 0.513889 0.027778
|
||||
vt 0.486111 0.055556
|
||||
vt 0.513889 0.194444
|
||||
vt 0.486111 0.250000
|
||||
vt 0.458333 0.250000
|
||||
vt 0.000000 0.000000
|
||||
vt 0.513889 0.055556
|
||||
vt 0.541667 0.000000
|
||||
vt 0.625000 0.027778
|
||||
vt 0.001001 0.997998
|
||||
vt 0.001001 0.501001
|
||||
vt 0.497998 0.501001
|
||||
vt 0.498999 0.502002
|
||||
vt 0.498999 0.998999
|
||||
vt 0.002002 0.998999
|
||||
vt 0.501001 0.001001
|
||||
vt 0.998999 0.498999
|
||||
vt 0.998999 0.001001
|
||||
vt 0.001001 0.001001
|
||||
vt 0.498999 0.498999
|
||||
vt 0.498999 0.001001
|
||||
vt 0.375000 0.250000
|
||||
vt 0.402778 0.250000
|
||||
vt 0.430556 0.250000
|
||||
vt 0.625000 0.250000
|
||||
vt 0.597222 0.250000
|
||||
vt 0.569444 0.250000
|
||||
vt 0.375000 1.000000
|
||||
vt 0.625000 1.000000
|
||||
vt 0.597222 1.000000
|
||||
vt 0.569444 1.000000
|
||||
vt 0.402778 1.000000
|
||||
vt 0.430556 1.000000
|
||||
vt 0.541667 1.000000
|
||||
vt 0.513889 1.000000
|
||||
vt 0.375000 0.027778
|
||||
vt 0.375000 0.000000
|
||||
vt 0.402778 0.000000
|
||||
vt 0.430556 0.000000
|
||||
vt 0.402778 0.027778
|
||||
vt 0.458333 0.000000
|
||||
vt 0.430556 0.027778
|
||||
vt 0.513889 0.000000
|
||||
vt 0.513889 0.222222
|
||||
vt 0.375000 0.222222
|
||||
vt 0.402778 0.222222
|
||||
vt 0.430556 0.222222
|
||||
vt 0.625000 0.222222
|
||||
vt 0.625000 0.194444
|
||||
vt 0.625000 0.166667
|
||||
vt 0.513889 0.166667
|
||||
vt 0.625000 0.138889
|
||||
vt 0.625000 0.111111
|
||||
vt 0.513889 0.138889
|
||||
vt 0.513889 0.111111
|
||||
vt 0.625000 0.083333
|
||||
vt 0.625000 0.055556
|
||||
vt 0.513889 0.083333
|
||||
vt 0.597222 0.000000
|
||||
vt 0.625000 0.000000
|
||||
vt 0.569444 0.000000
|
||||
vt 0.501001 0.498999
|
||||
vt 0.001001 0.498999
|
||||
s 0
|
||||
f 38/15/7 37/16/7 15/17/7
|
||||
f 16/18/8 13/19/8 15/17/8
|
||||
f 14/20/9 22/21/9 21/22/9
|
||||
f 22/23/10 49/24/10 47/25/10
|
||||
f 52/26/10 48/27/10 51/28/10
|
||||
f 53/29/10 50/30/10 49/24/10
|
||||
f 59/31/10 52/26/10 51/28/10
|
||||
f 52/26/10 39/32/10 40/33/10
|
||||
f 50/30/10 47/25/10 49/24/10
|
||||
f 56/34/10 50/30/10 54/35/10
|
||||
f 51/28/10 57/34/10 59/31/10
|
||||
f 53/29/10 24/36/10 27/37/10
|
||||
f 61/38/10 65/39/10 62/40/10
|
||||
f 64/41/8 66/42/8 63/43/8
|
||||
f 66/44/11 61/45/11 63/46/11
|
||||
f 62/47/12 66/48/12 64/49/12
|
||||
f 15/17/7 11/50/7 42/51/7
|
||||
f 15/17/7 42/51/7 41/52/7
|
||||
f 12/53/7 16/18/7 15/17/7
|
||||
f 35/54/7 12/53/7 15/17/7
|
||||
f 15/17/7 41/52/7 40/33/7
|
||||
f 15/17/7 40/33/7 39/32/7
|
||||
f 36/55/7 35/54/7 15/17/7
|
||||
f 37/16/7 36/55/7 15/17/7
|
||||
f 15/17/7 39/32/7 38/15/7
|
||||
f 16/18/8 14/20/8 13/19/8
|
||||
f 9/56/9 13/19/9 14/20/9
|
||||
f 14/20/9 10/57/9 26/58/9
|
||||
f 14/20/9 26/58/9 25/59/9
|
||||
f 19/60/9 9/56/9 14/20/9
|
||||
f 20/61/9 19/60/9 14/20/9
|
||||
f 14/20/9 25/59/9 24/62/9
|
||||
f 14/20/9 24/62/9 23/63/9
|
||||
f 21/22/9 20/61/9 14/20/9
|
||||
f 14/20/9 23/63/9 22/21/9
|
||||
f 18/64/10 9/65/10 19/66/10
|
||||
f 18/64/10 19/66/10 20/67/10
|
||||
f 43/68/10 18/64/10 20/67/10
|
||||
f 43/68/10 20/67/10 21/69/10
|
||||
f 45/70/10 43/68/10 21/69/10
|
||||
f 22/23/10 23/71/10 53/29/10
|
||||
f 45/70/10 21/69/10 22/23/10
|
||||
f 47/25/10 45/70/10 22/23/10
|
||||
f 22/23/10 53/29/10 49/24/10
|
||||
f 53/29/10 54/35/10 50/30/10
|
||||
f 59/31/10 60/72/10 52/26/10
|
||||
f 11/50/10 17/73/10 44/74/10
|
||||
f 11/50/10 44/74/10 46/75/10
|
||||
f 42/51/10 11/50/10 46/75/10
|
||||
f 42/51/10 46/75/10 48/27/10
|
||||
f 41/52/10 42/51/10 48/27/10
|
||||
f 52/26/10 60/72/10 38/15/10
|
||||
f 41/52/10 48/27/10 52/26/10
|
||||
f 40/33/10 41/52/10 52/26/10
|
||||
f 52/26/10 38/15/10 39/32/10
|
||||
f 34/76/10 12/53/10 35/54/10
|
||||
f 34/76/10 35/54/10 36/55/10
|
||||
f 33/77/10 34/76/10 36/55/10
|
||||
f 37/16/10 38/15/10 60/72/10
|
||||
f 33/77/10 36/55/10 37/16/10
|
||||
f 32/78/10 33/77/10 37/16/10
|
||||
f 37/16/10 60/72/10 59/31/10
|
||||
f 37/16/10 59/31/10 58/79/10
|
||||
f 31/80/10 32/78/10 37/16/10
|
||||
f 30/81/10 31/80/10 37/16/10
|
||||
f 37/16/10 58/79/10 57/82/10
|
||||
f 37/16/10 57/82/10 56/83/10
|
||||
f 29/84/10 30/81/10 37/16/10
|
||||
f 28/85/10 29/84/10 37/16/10
|
||||
f 37/16/10 56/83/10 55/86/10
|
||||
f 37/16/10 55/86/10 54/35/10
|
||||
f 27/37/10 28/85/10 37/16/10
|
||||
f 26/87/10 10/88/10 27/37/10
|
||||
f 25/89/10 26/87/10 27/37/10
|
||||
f 27/37/10 37/16/10 54/35/10
|
||||
f 53/29/10 23/71/10 24/36/10
|
||||
f 27/37/10 54/35/10 53/29/10
|
||||
f 24/36/10 25/89/10 27/37/10
|
||||
f 66/44/11 65/90/11 61/45/11
|
||||
f 62/47/12 65/91/12 66/48/12
|
||||
225
res/models/mapka3_nofence_noplatform.obj
Normal file
@@ -0,0 +1,225 @@
|
||||
# Blender 4.2.1 LTS
|
||||
# www.blender.org
|
||||
o szopa
|
||||
v 10.000000 0.000000 -19.000000
|
||||
v 10.000000 21.000000 -19.000000
|
||||
v 10.000000 0.000000 -1.000000
|
||||
v 10.000000 21.000000 -1.000000
|
||||
v -9.000000 0.000000 -19.000000
|
||||
v -9.000000 21.000000 -19.000000
|
||||
v -9.000000 0.000000 -1.000000
|
||||
v -9.000000 21.000000 -1.000000
|
||||
v 10.000000 0.000000 -3.000000
|
||||
v 10.000000 0.000000 -17.000000
|
||||
v 10.000000 2.333333 -19.000000
|
||||
v 10.000000 4.666667 -19.000000
|
||||
v 10.000000 7.000000 -19.000000
|
||||
v 10.000000 9.333334 -19.000000
|
||||
v 10.000000 11.666667 -19.000000
|
||||
v 10.000000 14.000000 -19.000000
|
||||
v 10.000000 16.333334 -19.000000
|
||||
v 10.000000 18.666668 -19.000000
|
||||
v 10.000000 21.000000 -17.000000
|
||||
v 10.000000 21.000000 -15.000000
|
||||
v 10.000000 21.000000 -13.000000
|
||||
v 10.000000 21.000000 -11.000000
|
||||
v 10.000000 21.000000 -9.000000
|
||||
v 10.000000 21.000000 -7.000000
|
||||
v 10.000000 21.000000 -5.000000
|
||||
v 10.000000 21.000000 -3.000000
|
||||
v 10.000000 18.666668 -1.000000
|
||||
v 10.000000 16.333334 -1.000000
|
||||
v 10.000000 14.000000 -1.000000
|
||||
v 10.000000 11.666666 -1.000000
|
||||
v 10.000000 9.333333 -1.000000
|
||||
v 10.000000 7.000000 -1.000000
|
||||
v 10.000000 4.666667 -1.000000
|
||||
v 10.000000 2.333333 -1.000000
|
||||
v 10.000000 2.333333 -17.000000
|
||||
v 10.000000 2.333333 -3.000000
|
||||
v 10.000000 4.666667 -17.000000
|
||||
v 10.000000 4.666667 -3.000000
|
||||
v 10.000000 7.000000 -17.000000
|
||||
v 10.000000 7.000000 -3.000000
|
||||
v 10.000000 9.333334 -17.000000
|
||||
v 10.000000 9.333334 -15.000000
|
||||
v 10.000000 9.333333 -5.000000
|
||||
v 10.000000 9.333333 -3.000000
|
||||
v 10.000000 11.666667 -17.000000
|
||||
v 10.000000 11.666667 -15.000000
|
||||
v 10.000000 11.666667 -13.000000
|
||||
v 10.000000 11.666667 -11.000000
|
||||
v 10.000000 11.666667 -9.000000
|
||||
v 10.000000 11.666667 -7.000000
|
||||
v 10.000000 11.666667 -5.000000
|
||||
v 10.000000 11.666666 -3.000000
|
||||
v 10.000000 21.000000 -19.000000
|
||||
v 10.000000 21.000000 -1.000000
|
||||
v -9.000000 21.000000 -19.000000
|
||||
v -9.000000 21.000000 -1.000000
|
||||
v 10.000000 32.000000 -10.000000
|
||||
v -9.000000 32.000000 -10.000000
|
||||
vn -0.0000 -0.0000 1.0000
|
||||
vn -1.0000 -0.0000 -0.0000
|
||||
vn -0.0000 -0.0000 -1.0000
|
||||
vn 1.0000 -0.0000 -0.0000
|
||||
vn -0.0000 0.6332 -0.7740
|
||||
vn -0.0000 0.6332 0.7740
|
||||
vt 0.513889 0.250000
|
||||
vt 0.541667 0.250000
|
||||
vt 0.375000 0.500000
|
||||
vt 0.625000 0.500000
|
||||
vt 0.375000 0.750000
|
||||
vt 0.625000 0.750000
|
||||
vt 0.486111 1.000000
|
||||
vt 0.458333 1.000000
|
||||
vt 0.486111 0.000000
|
||||
vt 0.486111 0.027778
|
||||
vt 0.458333 0.027778
|
||||
vt 0.486111 0.222222
|
||||
vt 0.458333 0.222222
|
||||
vt 0.486111 0.194444
|
||||
vt 0.513889 0.027778
|
||||
vt 0.486111 0.055556
|
||||
vt 0.513889 0.194444
|
||||
vt 0.486111 0.250000
|
||||
vt 0.458333 0.250000
|
||||
vt 0.000000 0.000000
|
||||
vt 0.513889 0.055556
|
||||
vt 0.541667 0.000000
|
||||
vt 0.625000 0.027778
|
||||
vt 0.001001 0.997998
|
||||
vt 0.001001 0.501001
|
||||
vt 0.497998 0.501001
|
||||
vt 0.498999 0.502002
|
||||
vt 0.498999 0.998999
|
||||
vt 0.002002 0.998999
|
||||
vt 0.501001 0.001001
|
||||
vt 0.998999 0.498999
|
||||
vt 0.998999 0.001001
|
||||
vt 0.001001 0.001001
|
||||
vt 0.498999 0.498999
|
||||
vt 0.498999 0.001001
|
||||
vt 0.375000 0.250000
|
||||
vt 0.402778 0.250000
|
||||
vt 0.430556 0.250000
|
||||
vt 0.625000 0.250000
|
||||
vt 0.597222 0.250000
|
||||
vt 0.569444 0.250000
|
||||
vt 0.375000 1.000000
|
||||
vt 0.625000 1.000000
|
||||
vt 0.597222 1.000000
|
||||
vt 0.569444 1.000000
|
||||
vt 0.402778 1.000000
|
||||
vt 0.430556 1.000000
|
||||
vt 0.541667 1.000000
|
||||
vt 0.513889 1.000000
|
||||
vt 0.375000 0.027778
|
||||
vt 0.375000 0.000000
|
||||
vt 0.402778 0.000000
|
||||
vt 0.430556 0.000000
|
||||
vt 0.402778 0.027778
|
||||
vt 0.458333 0.000000
|
||||
vt 0.430556 0.027778
|
||||
vt 0.513889 0.000000
|
||||
vt 0.513889 0.222222
|
||||
vt 0.375000 0.222222
|
||||
vt 0.402778 0.222222
|
||||
vt 0.430556 0.222222
|
||||
vt 0.625000 0.222222
|
||||
vt 0.625000 0.194444
|
||||
vt 0.625000 0.166667
|
||||
vt 0.513889 0.166667
|
||||
vt 0.625000 0.138889
|
||||
vt 0.625000 0.111111
|
||||
vt 0.513889 0.138889
|
||||
vt 0.513889 0.111111
|
||||
vt 0.625000 0.083333
|
||||
vt 0.625000 0.055556
|
||||
vt 0.513889 0.083333
|
||||
vt 0.597222 0.000000
|
||||
vt 0.625000 0.000000
|
||||
vt 0.569444 0.000000
|
||||
vt 0.501001 0.498999
|
||||
vt 0.001001 0.498999
|
||||
s 0
|
||||
f 30/1/1 29/2/1 7/3/1
|
||||
f 8/4/2 5/5/2 7/3/2
|
||||
f 6/6/3 14/7/3 13/8/3
|
||||
f 14/9/4 41/10/4 39/11/4
|
||||
f 44/12/4 40/13/4 43/14/4
|
||||
f 45/15/4 42/16/4 41/10/4
|
||||
f 51/17/4 44/12/4 43/14/4
|
||||
f 44/12/4 31/18/4 32/19/4
|
||||
f 42/16/4 39/11/4 41/10/4
|
||||
f 48/20/4 42/16/4 46/21/4
|
||||
f 43/14/4 49/20/4 51/17/4
|
||||
f 45/15/4 16/22/4 19/23/4
|
||||
f 53/24/4 57/25/4 54/26/4
|
||||
f 56/27/2 58/28/2 55/29/2
|
||||
f 58/30/5 53/31/5 55/32/5
|
||||
f 54/33/6 58/34/6 56/35/6
|
||||
f 7/3/1 3/36/1 34/37/1
|
||||
f 7/3/1 34/37/1 33/38/1
|
||||
f 4/39/1 8/4/1 7/3/1
|
||||
f 27/40/1 4/39/1 7/3/1
|
||||
f 7/3/1 33/38/1 32/19/1
|
||||
f 7/3/1 32/19/1 31/18/1
|
||||
f 28/41/1 27/40/1 7/3/1
|
||||
f 29/2/1 28/41/1 7/3/1
|
||||
f 7/3/1 31/18/1 30/1/1
|
||||
f 8/4/2 6/6/2 5/5/2
|
||||
f 1/42/3 5/5/3 6/6/3
|
||||
f 6/6/3 2/43/3 18/44/3
|
||||
f 6/6/3 18/44/3 17/45/3
|
||||
f 11/46/3 1/42/3 6/6/3
|
||||
f 12/47/3 11/46/3 6/6/3
|
||||
f 6/6/3 17/45/3 16/48/3
|
||||
f 6/6/3 16/48/3 15/49/3
|
||||
f 13/8/3 12/47/3 6/6/3
|
||||
f 6/6/3 15/49/3 14/7/3
|
||||
f 10/50/4 1/51/4 11/52/4
|
||||
f 10/50/4 11/52/4 12/53/4
|
||||
f 35/54/4 10/50/4 12/53/4
|
||||
f 35/54/4 12/53/4 13/55/4
|
||||
f 37/56/4 35/54/4 13/55/4
|
||||
f 14/9/4 15/57/4 45/15/4
|
||||
f 37/56/4 13/55/4 14/9/4
|
||||
f 39/11/4 37/56/4 14/9/4
|
||||
f 14/9/4 45/15/4 41/10/4
|
||||
f 45/15/4 46/21/4 42/16/4
|
||||
f 51/17/4 52/58/4 44/12/4
|
||||
f 3/36/4 9/59/4 36/60/4
|
||||
f 3/36/4 36/60/4 38/61/4
|
||||
f 34/37/4 3/36/4 38/61/4
|
||||
f 34/37/4 38/61/4 40/13/4
|
||||
f 33/38/4 34/37/4 40/13/4
|
||||
f 44/12/4 52/58/4 30/1/4
|
||||
f 33/38/4 40/13/4 44/12/4
|
||||
f 32/19/4 33/38/4 44/12/4
|
||||
f 44/12/4 30/1/4 31/18/4
|
||||
f 26/62/4 4/39/4 27/40/4
|
||||
f 26/62/4 27/40/4 28/41/4
|
||||
f 25/63/4 26/62/4 28/41/4
|
||||
f 29/2/4 30/1/4 52/58/4
|
||||
f 25/63/4 28/41/4 29/2/4
|
||||
f 24/64/4 25/63/4 29/2/4
|
||||
f 29/2/4 52/58/4 51/17/4
|
||||
f 29/2/4 51/17/4 50/65/4
|
||||
f 23/66/4 24/64/4 29/2/4
|
||||
f 22/67/4 23/66/4 29/2/4
|
||||
f 29/2/4 50/65/4 49/68/4
|
||||
f 29/2/4 49/68/4 48/69/4
|
||||
f 21/70/4 22/67/4 29/2/4
|
||||
f 20/71/4 21/70/4 29/2/4
|
||||
f 29/2/4 48/69/4 47/72/4
|
||||
f 29/2/4 47/72/4 46/21/4
|
||||
f 19/23/4 20/71/4 29/2/4
|
||||
f 18/73/4 2/74/4 19/23/4
|
||||
f 17/75/4 18/73/4 19/23/4
|
||||
f 19/23/4 29/2/4 46/21/4
|
||||
f 45/15/4 15/57/4 16/22/4
|
||||
f 19/23/4 46/21/4 45/15/4
|
||||
f 16/22/4 17/75/4 19/23/4
|
||||
f 58/30/5 57/76/5 53/31/5
|
||||
f 54/33/6 57/77/6 58/34/6
|
||||
BIN
res/models/uvmap.DDS
Normal file
17
res/shaders/TextureFragmentShader.fragmentshader
Normal file
@@ -0,0 +1,17 @@
|
||||
#version 330 core
|
||||
|
||||
// Interpolated values from the vertex shaders
|
||||
in vec2 UV;
|
||||
|
||||
// Output data
|
||||
out vec3 color;
|
||||
|
||||
// Values that stay constant for the whole mesh.
|
||||
uniform sampler2D myTextureSampler;
|
||||
|
||||
void main() {
|
||||
|
||||
// Output color = color of the texture at the specified UV
|
||||
color = texture(myTextureSampler, UV).rgb;
|
||||
|
||||
}
|
||||
20
res/shaders/TransformVertexShader.vertexshader
Normal file
@@ -0,0 +1,20 @@
|
||||
#version 330 core
|
||||
|
||||
// Input vertex data, different for all executions of this shader.
|
||||
layout(location = 0) in vec3 vertexPosition_modelspace;
|
||||
layout(location = 1) in vec2 vertexUV;
|
||||
|
||||
// Output data; will be interpolated for each fragment.
|
||||
out vec2 UV;
|
||||
|
||||
// Values that stay constant for the whole mesh.
|
||||
uniform mat4 MVP;
|
||||
|
||||
void main() {
|
||||
|
||||
// Output position of the vertex, in clip space: MVP * position
|
||||
gl_Position = MVP * vec4(vertexPosition_modelspace, 1);
|
||||
|
||||
// UV of the vertex. No special space for this one.
|
||||
UV = vertexUV;
|
||||
}
|
||||
94
shader.cpp
Normal file
@@ -0,0 +1,94 @@
|
||||
#include "shader.hpp"
|
||||
|
||||
GLuint LoadShaders(const char * vertex_file_path, const char * fragment_file_path) {
|
||||
|
||||
// Create the shaders
|
||||
GLuint VertexShaderID = glCreateShader(GL_VERTEX_SHADER);
|
||||
GLuint FragmentShaderID = glCreateShader(GL_FRAGMENT_SHADER);
|
||||
|
||||
// Read the Vertex Shader code from the file
|
||||
std::string VertexShaderCode;
|
||||
std::ifstream VertexShaderStream(vertex_file_path, std::ios::in);
|
||||
if (VertexShaderStream.is_open()) {
|
||||
std::stringstream sstr;
|
||||
sstr << VertexShaderStream.rdbuf();
|
||||
VertexShaderCode = sstr.str();
|
||||
VertexShaderStream.close();
|
||||
} else {
|
||||
timestampedCout("shader.cpp: Impossible to open " << vertex_file_path << ". Are you in the right directory?");
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Read the Fragment Shader code from the file
|
||||
std::string FragmentShaderCode;
|
||||
std::ifstream FragmentShaderStream(fragment_file_path, std::ios::in);
|
||||
if(FragmentShaderStream.is_open()){
|
||||
std::stringstream sstr;
|
||||
sstr << FragmentShaderStream.rdbuf();
|
||||
FragmentShaderCode = sstr.str();
|
||||
FragmentShaderStream.close();
|
||||
}
|
||||
|
||||
GLint Result = GL_FALSE;
|
||||
int InfoLogLength;
|
||||
|
||||
|
||||
// Compile Vertex Shader
|
||||
timestampedCout("shader.cpp: Compiling shader: " << vertex_file_path << "...");
|
||||
char const * VertexSourcePointer = VertexShaderCode.c_str();
|
||||
glShaderSource(VertexShaderID, 1, &VertexSourcePointer , NULL);
|
||||
glCompileShader(VertexShaderID);
|
||||
|
||||
// Check Vertex Shader
|
||||
glGetShaderiv(VertexShaderID, GL_COMPILE_STATUS, &Result);
|
||||
glGetShaderiv(VertexShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength);
|
||||
if (InfoLogLength > 0) {
|
||||
std::vector<char> VertexShaderErrorMessage(InfoLogLength + 1);
|
||||
glGetShaderInfoLog(VertexShaderID, InfoLogLength, NULL, &VertexShaderErrorMessage[0]);
|
||||
timestampedCout("shader.cpp: VertexErrorMessage " << &VertexShaderErrorMessage[0]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Compile Fragment Shader
|
||||
timestampedCout("shader.cpp: Compiling shader: " << fragment_file_path << "...");
|
||||
char const * FragmentSourcePointer = FragmentShaderCode.c_str();
|
||||
glShaderSource(FragmentShaderID, 1, &FragmentSourcePointer , NULL);
|
||||
glCompileShader(FragmentShaderID);
|
||||
|
||||
// Check Fragment Shader
|
||||
glGetShaderiv(FragmentShaderID, GL_COMPILE_STATUS, &Result);
|
||||
glGetShaderiv(FragmentShaderID, GL_INFO_LOG_LENGTH, &InfoLogLength);
|
||||
if (InfoLogLength > 0) {
|
||||
std::vector<char> FragmentShaderErrorMessage(InfoLogLength + 1);
|
||||
glGetShaderInfoLog(FragmentShaderID, InfoLogLength, NULL, &FragmentShaderErrorMessage[0]);
|
||||
timestampedCout("shader.cpp: FragmentShaderErrorMessage " << &FragmentShaderErrorMessage[0]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Link the program
|
||||
timestampedCout("shader.cpp: Linking program...");
|
||||
GLuint ProgramID = glCreateProgram();
|
||||
glAttachShader(ProgramID, VertexShaderID);
|
||||
glAttachShader(ProgramID, FragmentShaderID);
|
||||
glLinkProgram(ProgramID);
|
||||
|
||||
// Check the program
|
||||
glGetProgramiv(ProgramID, GL_LINK_STATUS, &Result);
|
||||
glGetProgramiv(ProgramID, GL_INFO_LOG_LENGTH, &InfoLogLength);
|
||||
if (InfoLogLength > 0){
|
||||
std::vector<char> ProgramErrorMessage(InfoLogLength + 1);
|
||||
glGetProgramInfoLog(ProgramID, InfoLogLength, NULL, &ProgramErrorMessage[0]);
|
||||
timestampedCout("shader.cpp: ProgramErrorMessage " << &ProgramErrorMessage[0]);
|
||||
}
|
||||
|
||||
|
||||
glDetachShader(ProgramID, VertexShaderID);
|
||||
glDetachShader(ProgramID, FragmentShaderID);
|
||||
|
||||
glDeleteShader(VertexShaderID);
|
||||
glDeleteShader(FragmentShaderID);
|
||||
|
||||
return ProgramID;
|
||||
}
|
||||
16
shader.hpp
Normal file
@@ -0,0 +1,16 @@
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <algorithm>
|
||||
#include <sstream>
|
||||
using namespace std;
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "timeh.hpp"
|
||||
|
||||
#include "GL/glew.h"
|
||||
|
||||
GLuint LoadShaders(const char * vertex_file_path, const char * fragment_file_path);
|
||||
71
szescian.cpp
@@ -1,71 +0,0 @@
|
||||
#include "szescian.h"
|
||||
|
||||
void szescian::create(float x, float y, float z, float KRAWEDZ) {
|
||||
|
||||
this->c_x = x;
|
||||
this->c_y = y;
|
||||
this->c_z = z;
|
||||
|
||||
// Parametry wierzcholkow
|
||||
|
||||
GLfloat sa[3] = { x + 0.0f, y + 0.0f, z + 0.0f };
|
||||
GLfloat sb[3] = { x + KRAWEDZ, y + 0.0f, z + 0.0f };
|
||||
GLfloat sc[3] = { x + KRAWEDZ, y + KRAWEDZ, z + 0.0f };
|
||||
GLfloat sd[3] = { x + 0.0f, y + KRAWEDZ, z + 0.0f };
|
||||
GLfloat se[3] = { x + 0.0f, y + 0.0f, z - KRAWEDZ };
|
||||
GLfloat sf[3] = { x + KRAWEDZ, y + 0.0f, z - KRAWEDZ };
|
||||
GLfloat sg[3] = { x + KRAWEDZ, y + KRAWEDZ, z - KRAWEDZ };
|
||||
GLfloat sh[3] = { x + 0.0f, y + KRAWEDZ, z - KRAWEDZ };
|
||||
|
||||
// Sciany skladowe
|
||||
|
||||
glColor3f(1.0f, 0.0f, 0.0f);
|
||||
glBegin(GL_POLYGON);
|
||||
glVertex3fv(sa);
|
||||
glVertex3fv(sb);
|
||||
glVertex3fv(sc);
|
||||
glVertex3fv(sd);
|
||||
glEnd();
|
||||
|
||||
|
||||
glColor3f(0.0f, 1.0f, 0.0f);
|
||||
glBegin(GL_POLYGON);
|
||||
glVertex3fv(sb);
|
||||
glVertex3fv(sf);
|
||||
glVertex3fv(sg);
|
||||
glVertex3fv(sc);
|
||||
glEnd();
|
||||
|
||||
glColor3f(0.0f, 0.0f, 1.0f);
|
||||
glBegin(GL_POLYGON);
|
||||
glVertex3fv(sf);
|
||||
glVertex3fv(se);
|
||||
glVertex3fv(sh);
|
||||
glVertex3fv(sg);
|
||||
glEnd();
|
||||
|
||||
glColor3f(1.0f, 1.0f, 0.0f);
|
||||
glBegin(GL_POLYGON);
|
||||
glVertex3fv(se);
|
||||
glVertex3fv(sa);
|
||||
glVertex3fv(sd);
|
||||
glVertex3fv(sh);
|
||||
glEnd();
|
||||
|
||||
glColor3f(0.0f, 1.0f, 1.0f);
|
||||
glBegin(GL_POLYGON);
|
||||
glVertex3fv(sd);
|
||||
glVertex3fv(sc);
|
||||
glVertex3fv(sg);
|
||||
glVertex3fv(sh);
|
||||
glEnd();
|
||||
|
||||
glColor3f(1.0f, 0.0f, 1.0f);
|
||||
glBegin(GL_POLYGON);
|
||||
glVertex3fv(sa);
|
||||
glVertex3fv(sb);
|
||||
glVertex3fv(sf);
|
||||
glVertex3fv(se);
|
||||
glEnd();
|
||||
|
||||
}
|
||||
14
szescian.h
@@ -1,14 +0,0 @@
|
||||
#pragma once
|
||||
#include <windows.h>
|
||||
#include <gl\gl.h>
|
||||
#include <gl\glu.h>
|
||||
|
||||
class szescian
|
||||
{
|
||||
private:
|
||||
float c_x{0};
|
||||
float c_y{0};
|
||||
float c_z{0};
|
||||
public:
|
||||
void create(float x, float y, float z, float KRAWEDZ);
|
||||
};
|
||||
357
teksturowane.cpp
Normal file
@@ -0,0 +1,357 @@
|
||||
#include "teksturowane.hpp"
|
||||
|
||||
void skrzynka(GLfloat k) {
|
||||
glColor3d(0.8, 0.7, 0.3);
|
||||
|
||||
|
||||
glEnable(GL_TEXTURE_2D); // Włącz teksturowanie
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, texture[0]);
|
||||
glBegin(GL_QUADS);
|
||||
glNormal3d(0, 0, 1);
|
||||
glTexCoord2d(1.0, 1.0); glVertex3d( k, k, k);
|
||||
glTexCoord2d(0.0, 1.0); glVertex3d(-k, k, k);
|
||||
glTexCoord2d(0.0, 0.0); glVertex3d(-k, -k, k);
|
||||
glTexCoord2d(1.0, 0.0); glVertex3d( k, -k, k);
|
||||
glEnd();
|
||||
glBindTexture(GL_TEXTURE_2D, texture[1]);
|
||||
glBegin(GL_QUADS);
|
||||
glNormal3d(1, 0, 0);
|
||||
glTexCoord2d(1.0, 1.0); glVertex3d(k, k, k);
|
||||
glTexCoord2d(0.0, 1.0); glVertex3d(k, -k, k);
|
||||
glTexCoord2d(0.0, 0.0); glVertex3d(k, -k, -k);
|
||||
glTexCoord2d(1.0, 0.0); glVertex3d(k, k, -k);
|
||||
glEnd();
|
||||
|
||||
glDisable(GL_TEXTURE_2D); // Wyłącz teksturowanie
|
||||
|
||||
|
||||
glBegin(GL_QUADS);
|
||||
glNormal3d(0, 0, -1);
|
||||
glVertex3d( k, k, -k);
|
||||
glVertex3d( k, -k, -k);
|
||||
glVertex3d(-k, -k, -k);
|
||||
glVertex3d(-k, k, -k);
|
||||
|
||||
glNormal3d(-1, 0, 0);
|
||||
glVertex3d(-k, k, -k);
|
||||
glVertex3d(-k, -k, -k);
|
||||
glVertex3d(-k, -k, k);
|
||||
glVertex3d(-k, k, k);
|
||||
|
||||
glNormal3d(0, 1, 0);
|
||||
glVertex3d( k, k, k);
|
||||
glVertex3d( k, k, -k);
|
||||
glVertex3d(-k, k, -k);
|
||||
glVertex3d(-k, k, k);
|
||||
|
||||
glNormal3d(0, -1, 0);
|
||||
glVertex3d( k, -k, k);
|
||||
glVertex3d(-k, -k, k);
|
||||
glVertex3d(-k, -k, -k);
|
||||
glVertex3d( k, -k, -k);
|
||||
glEnd();
|
||||
}
|
||||
|
||||
void platforma(GLfloat xc, GLfloat yc, GLfloat zc, GLfloat xlen, GLfloat zlen) {
|
||||
// glColor3d(0.729, 0.91, 0.51); // jasnozielony, dla grass02.bmp
|
||||
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glBindTexture(GL_TEXTURE_2D, texture[1]); // Wybieramy teksturę
|
||||
|
||||
// Ustawienie powtarzania tekstury
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT); // Powtarzanie w kierunku S
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT); // Powtarzanie w kierunku T
|
||||
|
||||
glBegin(GL_QUADS);
|
||||
// Powtarzające się współrzędne tekstury (np. *5, aby powtórzyła się 5 razy)
|
||||
glTexCoord2d(5.0, 5.0); glVertex3d(xc - xlen, yc, zc - zlen); // Lewy dolny
|
||||
glTexCoord2d(5.0, 0.0); glVertex3d(xc + xlen, yc, zc - zlen); // Prawy dolny
|
||||
glTexCoord2d(0.0, 0.0); glVertex3d(xc + xlen, yc, zc + zlen); // Prawy górny
|
||||
glTexCoord2d(0.0, 5.0); glVertex3d(xc - xlen, yc, zc + zlen); // Lewy górny
|
||||
glEnd();
|
||||
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
|
||||
void stodola(GLfloat xc, GLfloat yc, GLfloat zc, GLfloat krawedz) {
|
||||
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
|
||||
// ściany stodoły z bruku (brickwall)
|
||||
glColor3d(0.612f, 0.573f, 0.478f); // ciemny szary popadający w brąz (https://rgbcolorpicker.com/0-1)
|
||||
glBindTexture(GL_TEXTURE_2D, texture[3]);
|
||||
glBegin(GL_QUADS);
|
||||
|
||||
glTexCoord2d(1.0, 1.0); glVertex3d(xc - krawedz/2, yc, zc - krawedz/2);
|
||||
glTexCoord2d(1.0, 0.0); glVertex3d(xc - krawedz/2, yc + krawedz, zc - krawedz/2);
|
||||
glTexCoord2d(0.0, 0.0); glVertex3d(xc + krawedz/2, yc + krawedz, zc - krawedz/2);
|
||||
glTexCoord2d(0.0, 1.0); glVertex3d(xc + krawedz/2, yc, zc - krawedz/2);
|
||||
|
||||
glTexCoord2d(1.0, 1.0); glVertex3d(xc - krawedz/2, yc, zc - krawedz/2);
|
||||
glTexCoord2d(1.0, 0.0); glVertex3d(xc - krawedz/2, yc + krawedz, zc - krawedz/2);
|
||||
glTexCoord2d(0.0, 0.0); glVertex3d(xc - krawedz/2, yc + krawedz, zc + krawedz/2);
|
||||
glTexCoord2d(0.0, 1.0); glVertex3d(xc - krawedz/2, yc, zc + krawedz/2);
|
||||
|
||||
glTexCoord2d(1.0, 1.0); glVertex3d(xc - krawedz/2, yc, zc + krawedz/2);
|
||||
glTexCoord2d(1.0, 0.0); glVertex3d(xc - krawedz/2, yc + krawedz, zc + krawedz/2);
|
||||
glTexCoord2d(0.0, 0.0); glVertex3d(xc + krawedz/2, yc + krawedz, zc + krawedz/2);
|
||||
glTexCoord2d(0.0, 1.0); glVertex3d(xc + krawedz/2, yc, zc + krawedz/2);
|
||||
|
||||
glEnd();
|
||||
|
||||
// przód i tył dachu
|
||||
glColor3d(0.612f, 0.573f, 0.478f);
|
||||
glBindTexture(GL_TEXTURE_2D, texture[3]);
|
||||
glBegin(GL_TRIANGLES);
|
||||
|
||||
glTexCoord2f(1.0, 1.0); glVertex3f(xc - krawedz/2, yc + krawedz, zc - krawedz/2);
|
||||
glTexCoord2f(1.0, 0.0); glVertex3f(xc - krawedz/2, yc + 1.5 * krawedz, zc);
|
||||
glTexCoord2f(0.0, 0.0); glVertex3f(xc - krawedz/2, yc + krawedz, zc + krawedz/2);
|
||||
|
||||
glTexCoord2f(1.0, 1.0); glVertex3f(xc + krawedz/2, yc + krawedz, zc - krawedz/2);
|
||||
glTexCoord2f(1.0, 0.0); glVertex3f(xc + krawedz/2, yc + 1.5 * krawedz, zc);
|
||||
glTexCoord2f(0.0, 0.0); glVertex3f(xc + krawedz/2, yc + krawedz, zc + krawedz/2);
|
||||
|
||||
glEnd();
|
||||
|
||||
|
||||
// dach stodoły (barnroof)
|
||||
glColor3d(0.639, 0.553, 0.322); // wyblakły brązowy
|
||||
glBindTexture(GL_TEXTURE_2D, texture[2]);
|
||||
glBegin(GL_QUADS);
|
||||
|
||||
glTexCoord2d(1.0, 1.0); glVertex3d(xc - krawedz/2, yc + krawedz, zc + krawedz/2);
|
||||
glTexCoord2d(1.0, 0.0); glVertex3d(xc - krawedz/2, yc + 1.5 * krawedz, zc);
|
||||
glTexCoord2d(0.0, 0.0); glVertex3d(xc + krawedz/2, yc + 1.5 * krawedz, zc);
|
||||
glTexCoord2d(0.0, 1.0); glVertex3d(xc + krawedz/2, yc + krawedz, zc + krawedz/2);
|
||||
|
||||
glTexCoord2d(1.0, 1.0); glVertex3d(xc - krawedz/2, yc + krawedz, zc - krawedz/2);
|
||||
glTexCoord2d(1.0, 0.0); glVertex3d(xc - krawedz/2, yc + 1.5 * krawedz, zc);
|
||||
glTexCoord2d(0.0, 0.0); glVertex3d(xc + krawedz/2, yc + 1.5 * krawedz, zc);
|
||||
glTexCoord2d(0.0, 1.0); glVertex3d(xc + krawedz/2, yc + krawedz, zc - krawedz/2);
|
||||
|
||||
glEnd();
|
||||
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
|
||||
}
|
||||
|
||||
void plot(GLfloat xc, GLfloat yc, GLfloat zc, GLfloat length, GLfloat gruboscY, bool mod_x) {
|
||||
|
||||
GLfloat grubosc = 1.0f;
|
||||
|
||||
// timestampedCout("main.cpp (plot): otrzymano xc=" << xc << " yc=" << yc << " zc=" << zc << " length=" << length << " mod_x=" << mod_x);
|
||||
|
||||
GLfloat gruboscX = grubosc + mod_x * length;
|
||||
GLfloat gruboscZ = grubosc + !mod_x * length;
|
||||
|
||||
// timestampedCout("main.cpp (plot): gruboscX=" << gruboscX << " gruboscY=" << gruboscY << " gruboscZ=" << gruboscZ);
|
||||
|
||||
// d-----------c Y
|
||||
// / /| ^
|
||||
// a-----------b | \
|
||||
// | h | g C->X
|
||||
// | |/ |
|
||||
// e-----------f v
|
||||
// Z (płaszczyzna XZ, Y to trzeci wymiar)
|
||||
|
||||
GLfloat a1_x = xc - gruboscX / 2, a1_y = yc + 1 + gruboscY, a1_z = zc + gruboscZ / 2; // 3
|
||||
GLfloat b1_x = xc + gruboscX / 2, b1_y = yc + 1 + gruboscY, b1_z = zc + gruboscZ / 2;
|
||||
GLfloat c1_x = xc + gruboscX / 2, c1_y = yc + 1 + gruboscY, c1_z = zc - gruboscZ / 2;
|
||||
GLfloat d1_x = xc - gruboscX / 2, d1_y = yc + 1 + gruboscY, d1_z = zc - gruboscZ / 2;
|
||||
GLfloat e1_x = xc - gruboscX / 2, e1_y = yc + 1 , e1_z = zc + gruboscZ / 2; // 1
|
||||
GLfloat f1_x = xc + gruboscX / 2, f1_y = yc + 1 , f1_z = zc + gruboscZ / 2;
|
||||
GLfloat g1_x = xc + gruboscX / 2, g1_y = yc + 1 , g1_z = zc - gruboscZ / 2;
|
||||
GLfloat h1_x = xc - gruboscX / 2, h1_y = yc + 1 , h1_z = zc - gruboscZ / 2;
|
||||
|
||||
GLfloat a2_x = a1_x, a2_y = a1_y - 1 - gruboscY, a2_z = a1_z; //zc - 1; // -4
|
||||
GLfloat b2_x = b1_x, b2_y = b1_y - 1 - gruboscY, b2_z = b1_z; //zc - 1;
|
||||
GLfloat c2_x = c1_x, c2_y = c1_y - 1 - gruboscY, c2_z = c1_z; //zc - 1;
|
||||
GLfloat d2_x = d1_x, d2_y = d1_y - 1 - gruboscY, d2_z = d1_z; //zc - 1;
|
||||
GLfloat e2_x = e1_x, e2_y = e1_y - 1 - gruboscY, e2_z = e1_z; //zc - 2;
|
||||
GLfloat f2_x = f1_x, f2_y = f1_y - 1 - gruboscY, f2_z = f1_z; //zc - 2;
|
||||
GLfloat g2_x = g1_x, g2_y = g1_y - 1 - gruboscY, g2_z = g1_z; //zc - 2;
|
||||
GLfloat h2_x = h1_x, h2_y = h1_y - 1 - gruboscY, h2_z = h1_z; //zc - 2;
|
||||
|
||||
glColor3d(0.71, 0.522, 0.067);
|
||||
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glBindTexture(GL_TEXTURE_2D, texture[0]);
|
||||
glBegin(GL_QUADS);
|
||||
|
||||
// Góra (1_x, 1_y, 1_z):
|
||||
// ABCD
|
||||
glTexCoord2d(1.0, 1.0); glVertex3d(a1_x, a1_y, a1_z);
|
||||
glTexCoord2d(1.0, 0.0); glVertex3d(b1_x, b1_y, b1_z);
|
||||
glTexCoord2d(0.0, 0.0); glVertex3d(c1_x, c1_y, c1_z);
|
||||
glTexCoord2d(0.0, 1.0); glVertex3d(d1_x, d1_y, d1_z);
|
||||
|
||||
// EFGH
|
||||
glTexCoord2d(1.0, 1.0); glVertex3d(e1_x, e1_y, e1_z);
|
||||
glTexCoord2d(1.0, 0.0); glVertex3d(f1_x, f1_y, f1_z);
|
||||
glTexCoord2d(0.0, 0.0); glVertex3d(g1_x, g1_y, g1_z);
|
||||
glTexCoord2d(0.0, 1.0); glVertex3d(h1_x, h1_y, h1_z);
|
||||
|
||||
// BCGF
|
||||
glTexCoord2d(1.0, 1.0); glVertex3d(b1_x, b1_y, b1_z);
|
||||
glTexCoord2d(1.0, 0.0); glVertex3d(c1_x, c1_y, c1_z);
|
||||
glTexCoord2d(0.0, 0.0); glVertex3d(g1_x, g1_y, g1_z);
|
||||
glTexCoord2d(0.0, 1.0); glVertex3d(f1_x, f1_y, f1_z);
|
||||
|
||||
// ADHE
|
||||
glTexCoord2d(1.0, 1.0); glVertex3d(a1_x, a1_y, a1_z);
|
||||
glTexCoord2d(1.0, 0.0); glVertex3d(b1_x, b1_y, b1_z);
|
||||
glTexCoord2d(0.0, 0.0); glVertex3d(c1_x, c1_y, c1_z);
|
||||
glTexCoord2d(0.0, 1.0); glVertex3d(d1_x, d1_y, d1_z);
|
||||
|
||||
// ABFE
|
||||
glTexCoord2d(1.0, 1.0); glVertex3d(a1_x, a1_y, a1_z);
|
||||
glTexCoord2d(1.0, 0.0); glVertex3d(b1_x, b1_y, b1_z);
|
||||
glTexCoord2d(0.0, 0.0); glVertex3d(f1_x, f1_y, f1_z);
|
||||
glTexCoord2d(0.0, 1.0); glVertex3d(e1_x, e1_y, e1_z);
|
||||
|
||||
// DCGH
|
||||
glTexCoord2d(1.0, 1.0); glVertex3d(d1_x, d1_y, d1_z);
|
||||
glTexCoord2d(1.0, 0.0); glVertex3d(c1_x, c1_y, c1_z);
|
||||
glTexCoord2d(0.0, 0.0); glVertex3d(g1_x, g1_y, g1_z);
|
||||
glTexCoord2d(0.0, 1.0); glVertex3d(h1_x, h1_y, h1_z);
|
||||
|
||||
// Dół (2_x, 2_y, 2_z):
|
||||
// ABCD
|
||||
glTexCoord2d(1.0, 1.0); glVertex3d(a2_x, a2_y, a2_z);
|
||||
glTexCoord2d(1.0, 0.0); glVertex3d(b2_x, b2_y, b2_z);
|
||||
glTexCoord2d(0.0, 0.0); glVertex3d(c2_x, c2_y, c2_z);
|
||||
glTexCoord2d(0.0, 1.0); glVertex3d(d2_x, d2_y, d2_z);
|
||||
|
||||
// EFGH
|
||||
glTexCoord2d(1.0, 1.0); glVertex3d(e2_x, e2_y, e2_z);
|
||||
glTexCoord2d(1.0, 0.0); glVertex3d(f2_x, f2_y, f2_z);
|
||||
glTexCoord2d(0.0, 0.0); glVertex3d(g2_x, g2_y, g2_z);
|
||||
glTexCoord2d(0.0, 1.0); glVertex3d(h2_x, h2_y, h2_z);
|
||||
|
||||
// BCGF
|
||||
glTexCoord2d(1.0, 1.0); glVertex3d(b2_x, b2_y, b2_z);
|
||||
glTexCoord2d(1.0, 0.0); glVertex3d(c2_x, c2_y, c2_z);
|
||||
glTexCoord2d(0.0, 0.0); glVertex3d(g2_x, g2_y, g2_z);
|
||||
glTexCoord2d(0.0, 1.0); glVertex3d(f2_x, f2_y, f2_z);
|
||||
|
||||
// ADHE
|
||||
glTexCoord2d(1.0, 1.0); glVertex3d(a2_x, a2_y, a2_z);
|
||||
glTexCoord2d(1.0, 0.0); glVertex3d(b2_x, b2_y, b2_z);
|
||||
glTexCoord2d(0.0, 0.0); glVertex3d(c2_x, c2_y, c2_z);
|
||||
glTexCoord2d(0.0, 1.0); glVertex3d(d2_x, d2_y, d2_z);
|
||||
|
||||
// ABFE
|
||||
glTexCoord2d(1.0, 1.0); glVertex3d(a2_x, a2_y, a2_z);
|
||||
glTexCoord2d(1.0, 0.0); glVertex3d(b2_x, b2_y, b2_z);
|
||||
glTexCoord2d(0.0, 0.0); glVertex3d(f2_x, f2_y, f2_z);
|
||||
glTexCoord2d(0.0, 1.0); glVertex3d(e2_x, e2_y, e2_z);
|
||||
|
||||
// DCGH
|
||||
glTexCoord2d(1.0, 1.0); glVertex3d(d2_x, d2_y, d2_z);
|
||||
glTexCoord2d(1.0, 0.0); glVertex3d(c2_x, c2_y, c2_z);
|
||||
glTexCoord2d(0.0, 0.0); glVertex3d(g2_x, g2_y, g2_z);
|
||||
glTexCoord2d(0.0, 1.0); glVertex3d(h2_x, h2_y, h2_z);
|
||||
|
||||
// Pachołki
|
||||
|
||||
// d-----------c Y
|
||||
// / /| ^
|
||||
// a-----------b | \
|
||||
// | h | g C->X
|
||||
// | |/ |
|
||||
// e-----------f v
|
||||
// Z (płaszczyzna XZ, Y to trzeci wymiar)
|
||||
|
||||
|
||||
GLfloat p_a_x, p_a_y, p_a_z;
|
||||
GLfloat p_b_x, p_b_y, p_b_z;
|
||||
GLfloat p_c_x, p_c_y, p_c_z;
|
||||
GLfloat p_d_x, p_d_y, p_d_z;
|
||||
GLfloat p_e_x, p_e_y, p_e_z;
|
||||
GLfloat p_f_x, p_f_y, p_f_z;
|
||||
GLfloat p_g_x, p_g_y, p_g_z;
|
||||
GLfloat p_h_x, p_h_y, p_h_z;
|
||||
|
||||
if (!mod_x) {
|
||||
|
||||
p_a_x = xc + gruboscX / 2, p_a_y = yc + 1.5f * gruboscY, p_a_z = zc; // +3 dla y
|
||||
p_b_x = xc - gruboscX / 2, p_b_y = yc + 1.5f * gruboscY, p_b_z = zc; // +3 dla y
|
||||
p_c_x = xc + gruboscX / 2, p_c_y = yc + 1.5f * gruboscY, p_c_z = zc; // +3 dla y
|
||||
p_d_x = xc - gruboscX / 2, p_d_y = yc + 1.5f * gruboscY, p_d_z = zc; // +3 dla y
|
||||
p_e_x = xc + gruboscX / 2, p_e_y = yc - 6 , p_e_z = zc;
|
||||
p_f_x = xc - gruboscX / 2, p_f_y = yc - 6 , p_f_z = zc;
|
||||
p_g_x = xc + gruboscX / 2, p_g_y = yc - 6 , p_g_z = zc;
|
||||
p_h_x = xc - gruboscX / 2, p_h_y = yc - 6 , p_h_z = zc;
|
||||
|
||||
} else {
|
||||
|
||||
p_a_x = xc, p_a_y = yc + 1.5f * gruboscY, p_a_z = zc - gruboscZ / 2; // +3 dla y
|
||||
p_b_x = xc, p_b_y = yc + 1.5f * gruboscY, p_b_z = zc - gruboscZ / 2; // +3 dla y
|
||||
p_c_x = xc, p_c_y = yc + 1.5f * gruboscY, p_c_z = zc + gruboscZ / 2; // +3 dla y
|
||||
p_d_x = xc, p_d_y = yc + 1.5f * gruboscY, p_d_z = zc + gruboscZ / 2; // +3 dla y
|
||||
p_e_x = xc, p_e_y = yc - 6 , p_e_z = zc - gruboscZ / 2;
|
||||
p_f_x = xc, p_f_y = yc - 6 , p_f_z = zc - gruboscZ / 2;
|
||||
p_g_x = xc, p_g_y = yc - 6 , p_g_z = zc + gruboscZ / 2;
|
||||
p_h_x = xc, p_h_y = yc - 6 , p_h_z = zc + gruboscZ / 2;
|
||||
|
||||
}
|
||||
|
||||
for (int i = 0; i < 2; i++) {
|
||||
|
||||
// d-----------c Y
|
||||
// / /| ^
|
||||
// a-----------b | \
|
||||
// | h | g C->X
|
||||
// | |/ |
|
||||
// e-----------f v
|
||||
// Z (płaszczyzna XZ, Y to trzeci wymiar)
|
||||
|
||||
// timestampedCout("main.cpp (plot): p_a_x=" << p_a_x << " p_b_x=" << p_b_x << " p_c_x=" << p_c_x << " p_d_x=" << p_d_x);
|
||||
|
||||
// ABCD
|
||||
glTexCoord2d(1.0, 1.0); glVertex3d(p_a_x + (2*i-1) * (gruboscX/2 - 8) * mod_x, p_a_y, p_a_z + (2*i-1) * (gruboscZ/2 - 5) * !mod_x);
|
||||
glTexCoord2d(1.0, 0.0); glVertex3d(p_b_x + (2*i-1) * (gruboscX/2 - 5) * mod_x, p_b_y, p_b_z + (2*i-1) * (gruboscZ/2 - 5) * !mod_x);
|
||||
glTexCoord2d(0.0, 0.0); glVertex3d(p_c_x + (2*i-1) * (gruboscX/2 - 5) * mod_x, p_c_y, p_c_z + (2*i-1) * (gruboscZ/2 - 8) * !mod_x);
|
||||
glTexCoord2d(0.0, 1.0); glVertex3d(p_d_x + (2*i-1) * (gruboscX/2 - 8) * mod_x, p_d_y, p_d_z + (2*i-1) * (gruboscZ/2 - 8) * !mod_x);
|
||||
|
||||
// EFGH
|
||||
glTexCoord2d(1.0, 1.0); glVertex3d(p_e_x + (2*i-1) * (gruboscX/2 - 8) * mod_x, p_e_y, p_e_z + (2*i-1) * (gruboscZ/2 - 5) * !mod_x);
|
||||
glTexCoord2d(1.0, 0.0); glVertex3d(p_f_x + (2*i-1) * (gruboscX/2 - 5) * mod_x, p_f_y, p_f_z + (2*i-1) * (gruboscZ/2 - 5) * !mod_x);
|
||||
glTexCoord2d(0.0, 0.0); glVertex3d(p_g_x + (2*i-1) * (gruboscX/2 - 5) * mod_x, p_g_y, p_g_z + (2*i-1) * (gruboscZ/2 - 8) * !mod_x);
|
||||
glTexCoord2d(0.0, 1.0); glVertex3d(p_h_x + (2*i-1) * (gruboscX/2 - 8) * mod_x, p_h_y, p_h_z + (2*i-1) * (gruboscZ/2 - 8) * !mod_x);
|
||||
|
||||
// BCGF
|
||||
glTexCoord2d(1.0, 1.0); glVertex3d(p_b_x + (2*i-1) * (gruboscX/2 - 5) * mod_x, p_b_y, p_b_z + (2*i-1) * (gruboscZ/2 - 5) * !mod_x);
|
||||
glTexCoord2d(1.0, 0.0); glVertex3d(p_c_x + (2*i-1) * (gruboscX/2 - 5) * mod_x, p_c_y, p_c_z + (2*i-1) * (gruboscZ/2 - 8) * !mod_x);
|
||||
glTexCoord2d(0.0, 0.0); glVertex3d(p_g_x + (2*i-1) * (gruboscX/2 - 5) * mod_x, p_g_y, p_g_z + (2*i-1) * (gruboscZ/2 - 8) * !mod_x);
|
||||
glTexCoord2d(0.0, 1.0); glVertex3d(p_f_x + (2*i-1) * (gruboscX/2 - 5) * mod_x, p_f_y, p_f_z + (2*i-1) * (gruboscZ/2 - 5) * !mod_x);
|
||||
|
||||
// ADHE
|
||||
glTexCoord2d(1.0, 1.0); glVertex3d(p_a_x + (2*i-1) * (gruboscX/2 - 8) * mod_x, p_a_y, p_a_z + (2*i-1) * (gruboscZ/2 - 5) * !mod_x);
|
||||
glTexCoord2d(1.0, 0.0); glVertex3d(p_d_x + (2*i-1) * (gruboscX/2 - 8) * mod_x, p_d_y, p_d_z + (2*i-1) * (gruboscZ/2 - 8) * !mod_x);
|
||||
glTexCoord2d(0.0, 0.0); glVertex3d(p_h_x + (2*i-1) * (gruboscX/2 - 8) * mod_x, p_h_y, p_h_z + (2*i-1) * (gruboscZ/2 - 8) * !mod_x);
|
||||
glTexCoord2d(0.0, 1.0); glVertex3d(p_e_x + (2*i-1) * (gruboscX/2 - 8) * mod_x, p_e_y, p_e_z + (2*i-1) * (gruboscZ/2 - 5) * !mod_x);
|
||||
|
||||
// ABFE
|
||||
glTexCoord2d(1.0, 1.0); glVertex3d(p_a_x + (2*i-1) * (gruboscX/2 - 8) * mod_x, p_a_y, p_a_z + (2*i-1) * (gruboscZ/2 - 5) * !mod_x);
|
||||
glTexCoord2d(1.0, 0.0); glVertex3d(p_b_x + (2*i-1) * (gruboscX/2 - 5) * mod_x, p_b_y, p_b_z + (2*i-1) * (gruboscZ/2 - 5) * !mod_x);
|
||||
glTexCoord2d(0.0, 0.0); glVertex3d(p_f_x + (2*i-1) * (gruboscX/2 - 5) * mod_x, p_f_y, p_f_z + (2*i-1) * (gruboscZ/2 - 5) * !mod_x);
|
||||
glTexCoord2d(0.0, 1.0); glVertex3d(p_e_x + (2*i-1) * (gruboscX/2 - 8) * mod_x, p_e_y, p_e_z + (2*i-1) * (gruboscZ/2 - 5) * !mod_x);
|
||||
|
||||
// DCGH
|
||||
glTexCoord2d(1.0, 1.0); glVertex3d(p_d_x + (2*i-1) * (gruboscX/2 - 8) * mod_x, p_d_y, p_d_z + (2*i-1) * (gruboscZ/2 - 8) * !mod_x);
|
||||
glTexCoord2d(1.0, 0.0); glVertex3d(p_c_x + (2*i-1) * (gruboscX/2 - 5) * mod_x, p_c_y, p_c_z + (2*i-1) * (gruboscZ/2 - 8) * !mod_x);
|
||||
glTexCoord2d(0.0, 0.0); glVertex3d(p_g_x + (2*i-1) * (gruboscX/2 - 5) * mod_x, p_g_y, p_g_z + (2*i-1) * (gruboscZ/2 - 8) * !mod_x);
|
||||
glTexCoord2d(0.0, 1.0); glVertex3d(p_h_x + (2*i-1) * (gruboscX/2 - 8) * mod_x, p_h_y, p_h_z + (2*i-1) * (gruboscZ/2 - 8) * !mod_x);
|
||||
|
||||
}
|
||||
|
||||
|
||||
glEnd();
|
||||
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
|
||||
}
|
||||
9
teksturowane.hpp
Normal file
@@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
#include "GL/glew.h"
|
||||
|
||||
extern unsigned int texture[4];
|
||||
|
||||
void skrzynka(GLfloat k);
|
||||
void platforma(GLfloat xc, GLfloat yc, GLfloat zc, GLfloat xlen, GLfloat zlen);
|
||||
void stodola(GLfloat xc, GLfloat yc, GLfloat zc, GLfloat krawedz);
|
||||
void plot(GLfloat xc, GLfloat yc, GLfloat zc, GLfloat length, GLfloat gruboscY, bool mod_x);
|
||||
188
texture.cpp
Normal file
@@ -0,0 +1,188 @@
|
||||
#include "texture.hpp"
|
||||
|
||||
GLuint loadBMP_custom(const char * imagepath){
|
||||
|
||||
return 0;
|
||||
|
||||
timestampedCout("texture.cpp: Reading image " << imagepath << "...");
|
||||
|
||||
// Data read from the header of the BMP file
|
||||
unsigned char header[54];
|
||||
unsigned int dataPos;
|
||||
unsigned int imageSize;
|
||||
unsigned int width, height;
|
||||
// Actual RGB data
|
||||
unsigned char * data;
|
||||
|
||||
// Open the file
|
||||
FILE * file = fopen(imagepath, "rb");
|
||||
if (!file) {
|
||||
timestampedCout("texture.cpp: " << imagepath << " could not be opened. Are you in the right directory?");
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Read the header, i.e. the 54 first bytes
|
||||
|
||||
// If less than 54 bytes are read, problem
|
||||
if (fread(header, 1, 54, file) != 54) {
|
||||
timestampedCout("texture.cpp: Not a correct BMP file.");
|
||||
fclose(file);
|
||||
return 0;
|
||||
}
|
||||
// A BMP files always begins with "BM"
|
||||
if (header[0] != 'B' || header[1] != 'M') {
|
||||
timestampedCout("texture.cpp: Not a correct BMP file.");
|
||||
fclose(file);
|
||||
return 0;
|
||||
}
|
||||
// Make sure this is a 24bpp file
|
||||
if (*(int*)&(header[0x1E]) != 0) { timestampedCout("texture.cpp: Not a correct BMP file."); fclose(file); return 0;}
|
||||
if (*(int*)&(header[0x1C]) != 24) { timestampedCout("texture.cpp: Not a correct BMP file."); fclose(file); return 0;}
|
||||
|
||||
// Read the information about the image
|
||||
dataPos = *(int*)&(header[0x0A]);
|
||||
imageSize = *(int*)&(header[0x22]);
|
||||
width = *(int*)&(header[0x12]);
|
||||
height = *(int*)&(header[0x16]);
|
||||
|
||||
// Some BMP files are misformatted, guess missing information
|
||||
if (imageSize == 0) imageSize = width * height * 3; // 3 : one byte for each Red, Green and Blue component
|
||||
if (dataPos == 0) dataPos = 54; // The BMP header is done that way
|
||||
|
||||
// Create a buffer
|
||||
data = new unsigned char [imageSize];
|
||||
|
||||
// Read the actual data from the file into the buffer
|
||||
fread(data, 1, imageSize, file);
|
||||
|
||||
// Everything is in memory now, the file can be closed.
|
||||
fclose(file);
|
||||
|
||||
// Create one OpenGL texture
|
||||
GLuint textureID;
|
||||
glGenTextures(1, &textureID);
|
||||
|
||||
// "Bind" the newly created texture : all future texture functions will modify this texture
|
||||
glBindTexture(GL_TEXTURE_2D, textureID);
|
||||
|
||||
// Give the image to OpenGL
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_BGR, GL_UNSIGNED_BYTE, data);
|
||||
|
||||
// OpenGL has now copied the data. Free our own version
|
||||
delete [] data;
|
||||
|
||||
// Poor filtering, or ...
|
||||
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
||||
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
||||
|
||||
// ... nice trilinear filtering ...
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
|
||||
// ... which requires mipmaps. Generate them automatically.
|
||||
glGenerateMipmap(GL_TEXTURE_2D);
|
||||
|
||||
// Return the ID of the texture we just created
|
||||
return textureID;
|
||||
}
|
||||
|
||||
#define FOURCC_DXT1 0x31545844 // Equivalent to "DXT1" in ASCII
|
||||
#define FOURCC_DXT3 0x33545844 // Equivalent to "DXT3" in ASCII
|
||||
#define FOURCC_DXT5 0x35545844 // Equivalent to "DXT5" in ASCII
|
||||
|
||||
GLuint loadDDS(const char * imagepath){
|
||||
|
||||
return 0;
|
||||
|
||||
unsigned char header[124];
|
||||
|
||||
FILE *fp;
|
||||
|
||||
// timestampedCout("texture.cpp: Hello!");
|
||||
|
||||
/* try to open the file */
|
||||
fp = fopen(imagepath, "rb");
|
||||
if (fp == NULL){
|
||||
timestampedCout("texture.cpp: " << imagepath << " could not be opened. Are you in the right directory?");
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* verify the type of file */
|
||||
char filecode[4];
|
||||
fread(filecode, 1, 4, fp);
|
||||
if (strncmp(filecode, "DDS ", 4) != 0) {
|
||||
fclose(fp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* get the surface desc */
|
||||
fread(&header, 124, 1, fp);
|
||||
|
||||
unsigned int height = *(unsigned int*)&(header[8 ]);
|
||||
unsigned int width = *(unsigned int*)&(header[12]);
|
||||
unsigned int linearSize = *(unsigned int*)&(header[16]);
|
||||
unsigned int mipMapCount = *(unsigned int*)&(header[24]);
|
||||
unsigned int fourCC = *(unsigned int*)&(header[80]);
|
||||
|
||||
|
||||
unsigned char * buffer;
|
||||
unsigned int bufsize;
|
||||
/* how big is it going to be including all mipmaps? */
|
||||
bufsize = mipMapCount > 1 ? linearSize * 2 : linearSize;
|
||||
buffer = (unsigned char*)malloc(bufsize * sizeof(unsigned char));
|
||||
fread(buffer, 1, bufsize, fp);
|
||||
/* close the file pointer */
|
||||
fclose(fp);
|
||||
|
||||
unsigned int components = (fourCC == FOURCC_DXT1) ? 3 : 4;
|
||||
unsigned int format;
|
||||
switch(fourCC) {
|
||||
|
||||
case FOURCC_DXT1:
|
||||
format = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT;
|
||||
break;
|
||||
case FOURCC_DXT3:
|
||||
format = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT;
|
||||
break;
|
||||
case FOURCC_DXT5:
|
||||
format = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
|
||||
break;
|
||||
default:
|
||||
free(buffer);
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
// Create one OpenGL texture
|
||||
GLuint textureID;
|
||||
glGenTextures(1, &textureID);
|
||||
|
||||
// "Bind" the newly created texture : all future texture functions will modify this texture
|
||||
glBindTexture(GL_TEXTURE_2D, textureID);
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
|
||||
unsigned int blockSize = (format == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) ? 8 : 16;
|
||||
unsigned int offset = 0;
|
||||
|
||||
/* load the mipmaps */
|
||||
for (unsigned int level = 0; level < mipMapCount && (width || height); ++level) {
|
||||
|
||||
unsigned int size = ((width + 3) / 4) * ((height + 3) / 4) * blockSize;
|
||||
glCompressedTexImage2D(GL_TEXTURE_2D, level, format, width, height,
|
||||
0, size, buffer + offset);
|
||||
|
||||
offset += size;
|
||||
width /= 2;
|
||||
height /= 2;
|
||||
|
||||
// Deal with Non-Power-Of-Two textures. This code is not included in the webpage to reduce clutter.
|
||||
if (width < 1) width = 1;
|
||||
if (height < 1) height = 1;
|
||||
|
||||
}
|
||||
|
||||
free(buffer);
|
||||
return textureID;
|
||||
|
||||
}
|
||||
11
texture.hpp
Normal file
@@ -0,0 +1,11 @@
|
||||
#include <iostream>
|
||||
//#include <stdlib.h>
|
||||
#include "timeh.hpp"
|
||||
#include <string.h>
|
||||
#include "GL/glew.h"
|
||||
|
||||
// Load a .BMP file using our custom loader
|
||||
GLuint loadBMP_custom(const char * imagepath);
|
||||
|
||||
// Load a .DDS file using GLFW's own loader
|
||||
GLuint loadDDS(const char * imagepath);
|
||||
5
timeh.cpp
Normal file
@@ -0,0 +1,5 @@
|
||||
#include "timeh.hpp"
|
||||
|
||||
std::time_t getTime() {
|
||||
return std::time(nullptr);
|
||||
}
|
||||