Just ask if you don't have enough code. I took the main parts of the engine.
#include <SFML/Graphics.hpp>
#include "Engine/Core/Core.h"
int main()
{
{ // Juste pour que le destructeur soit appelé avant la fin du main pour le cleanup.
Core core;
core.Init();
core.Load();
while (!core.requestCloseWindow)
{
core.HandleInput();
core.Update();
core.Draw();
}
core.Unload();
core.window->close();
}
return 0;
}
#include <GL/glew.h>
#include "Core.h"
#include <SFML/OpenGL.hpp>
#include <glm/fwd.hpp>
void Core::Init()
{
window = new sf::RenderWindow(sf::VideoMode(800, 600), "SFML works!");
window->setVerticalSyncEnabled(true);
window->setMouseCursorVisible(false);
glewInit(); // Doit être appelé quand il y a un contexte OpenGL, donc après l'instanciation de la fenêtre.
clock = new sf::Clock();
camera = new CameraFreeRoaming (window, glm::vec3(0.0f, 5.0f, 5.0f), VecConst::ZERO_VEC3);
glEnable(GL_TEXTURE_2D);
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE);
glDepthFunc(GL_LEQUAL);
glDepthRange(0.0f, 1.0f);
glClearDepth(1.0f);
}
#include "Core.h"
#include <string>
#include <vector>
#include "../Graphics/DrawBuffers.h"
#include "../Graphics/BufferUsage.h"
#include "../Graphics/CubeDataGenerator.h"
#include "../Graphics/Shader/ShaderType.h"
#include <iostream>
void Core::Load()
{
std::vector<ShaderSource> shaderSources =
{ShaderSource("Resources/Test/Test_Tex_Shader.frag", ShaderType::FRAGMENT),
ShaderSource("Resources/Test/Test_Tex_Shader.vert", ShaderType::VERTEX)};
colorShader = new Shader(shaderSources);
sf::Image img;
//window->pushGLStates();
if (img.loadFromFile("Resources/Test/Google_Chrome_logo.png"))
std::cout << "Texture loaded" << std::endl;
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, img.getSize().x, img.getSize().y, 0, GL_BGRA, GL_UNSIGNED_BYTE, img.getPixelsPtr());
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);
glGenerateMipmap(GL_TEXTURE_2D);
std::cout << gluErrorString(glGetError()) << std::endl;
//window->popGLStates();
/*glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_EDGE_FLAG_ARRAY);
glDisableClientState(GL_FOG_COORD_ARRAY);
glDisableClientState(GL_INDEX_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
glDisableClientState(GL_SECONDARY_COLOR_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);*/
colorShader->useProgram();
projectionMat = glm::perspective(glm::radians(60.0f), (float)window->getSize().x / (float)window->getSize().y, 0.001f, 1000.0f);
glUniformMatrix4fv(glGetUniformLocation(colorShader->program, "ProjectionMatrix"), 1, GL_FALSE, &projectionMat[0][0]);
glUniformMatrix4fv(glGetUniformLocation(colorShader->program, "ModelMatrix"), 1, GL_FALSE, &worldMatrix[0][0]); // Si location = -1 = aucune erreur; autre que -1, mais n'existe pas = erreur
cube1 = new DrawBuffers(CubeDataGenerator::GenCube(DataGeneratorUsage::Position3 | DataGeneratorUsage::ColorRGBA | DataGeneratorUsage::TexCoord), BufferUsage::STATIC_DRAW, true);
cube2 = new DrawBuffers(CubeDataGenerator::GenCube(DataGeneratorUsage::Position3 | DataGeneratorUsage::ColorRGBA | DataGeneratorUsage::TexCoord, 2.0f), BufferUsage::STATIC_DRAW, true);
cube3 = new DrawBuffers(CubeDataGenerator::GenCube(DataGeneratorUsage::Position3 | DataGeneratorUsage::ColorRGBA | DataGeneratorUsage::TexCoord, 1.0f, 3.0f, 0.1f), BufferUsage::STATIC_DRAW, true);
clock->restart();
}
#include "Core.h"
#include <SFML/OpenGL.hpp>
// Header file
#include <glm/fwd.hpp>
#include <glm/gtc/matrix_transform.hpp>
void Core::Draw()
{
window->clear();
glClear(GL_DEPTH_BUFFER_BIT);
colorShader->useProgram();
glUniformMatrix4fv(glGetUniformLocation(colorShader->program, "ViewMatrix"), 1, GL_FALSE, &camera->getView()[0][0]);
glm::vec3 v1 (0.0f, 0.0f, 0.0f);
glm::vec3 v2 (3.0f, 0.0f, 0.0f);
glm::vec3 v3 (6.0f, 0.0f, 0.0f);
glUniformMatrix4fv(glGetUniformLocation(colorShader->program, "ModelMatrix"), 1, GL_FALSE, &glm::translate(worldMatrix, v1)[0][0]);
cube1->draw();
glUniformMatrix4fv(glGetUniformLocation(colorShader->program, "ModelMatrix"), 1, GL_FALSE, &glm::translate(worldMatrix, v2)[0][0]);
cube2->draw();
glUniformMatrix4fv(glGetUniformLocation(colorShader->program, "ModelMatrix"), 1, GL_FALSE, &glm::translate(worldMatrix, v3)[0][0]);
cube3->draw();
window->display();
}