1
0
Fork 0

Update cmake

This commit is contained in:
MrDev023 2016-10-08 18:35:02 +02:00
parent 9b1b3a5c97
commit 8f9bc0da09
7 changed files with 164 additions and 34 deletions

View file

@ -1,5 +1,10 @@
#require opengl,glew,glut,glu,al,alc,sndfile library #require opengl,glew,glut,glu,al,alc,sndfile library
IF (WIN32)
SET(CMAKE_C_COMPILER C:/mingw32/bin/)
SET(CMAKE_CXX_COMPILER C:/mingw32/bin/)
ENDIF()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
cmake_minimum_required(VERSION 2.6) cmake_minimum_required(VERSION 2.6)
@ -14,9 +19,19 @@ set(EXECUTABLE_OUTPUT_PATH bin/${CMAKE_BUILD_TYPE})
#Inclusion de Boost #Inclusion de Boost
IF (WIN32) IF (WIN32)
include_directories($ENV{MINGW_HOME}/usr/include) include_directories($ENV{MINGW_HOME}/include)
link_directories($ENV{MINGW_HOME}/usr/lib) link_directories($ENV{MINGW_HOME}/lib)
ELSE() ELSE()
INCLUDE(FindPkgConfig)
PKG_SEARCH_MODULE(SDL2 REQUIRED sdl2)
PKG_SEARCH_MODULE(SDL2_image REQUIRED SDL2_image)
PKG_SEARCH_MODULE(SDL2_mixer REQUIRED SDL2_mixer)
PKG_SEARCH_MODULE(SDL2_ttf REQUIRED SDL2_ttf)
find_package(GLEW REQUIRED)
find_package(OpenGL REQUIRED)
find_package(GLU REQUIRED)
find_package(GLUT REQUIRED)
find_package(OpenAL REQUIRED)
include_directories(/usr/include) include_directories(/usr/include)
link_directories(/usr/lib) link_directories(/usr/lib)
ENDIF() ENDIF()
@ -37,7 +52,6 @@ add_executable(
) )
#Configuration de l'édition de liens #Configuration de l'édition de liens

3
configure.sh Normal file
View file

@ -0,0 +1,3 @@
#!/bin/bash
sudo apt install libsdl2* libglew* libglut* libglew-dev:i386 libsndfile-dev -y
cmake . && cmake . 1>/dev/null # deux fois car sinon erreur de compilation

View file

@ -1,7 +1,10 @@
#version 150 #version 330
uniform float y; in vec4 color;
in vec3 normal;
in vec2 out_coord_texture;
uniform sampler2D myTexture;
void main(void){ void main(void){
gl_FragColor= vec4(1, 1 - abs(y)/50,1 - abs(y)/50,1); gl_FragColor = color * texture2D(myTexture,out_coord_texture);
} }

View file

@ -1,6 +1,15 @@
#version 150 #version 330
layout (location = 0) in vec3 in_position;
layout (location = 1) in vec4 in_color;
layout (location = 2) in vec2 in_coord_texture;
layout (location = 3) in vec3 in_normal;
out vec4 color;
out vec3 normal;
out vec2 out_coord_texture;
void main(void){ void main(void){
gl_FrontColor = gl_Color; gl_FrontColor = gl_Color;
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; gl_Position = gl_ModelViewProjectionMatrix * vec4(in_position,1.0f);
} }

View file

@ -32,34 +32,40 @@ class VAO;
class VAO{ class VAO{
public: public:
static const int VERTEX_DATA = 0,COLOR_DATA = 1,TEX_COORD_DATA = 2,NORMAL_DATA = 3;
std::vector<VBO*> data; std::vector<VBO*> data;
unsigned int n;
bool isIn3DRender;
GLuint id; GLuint id;
GLuint typeRender; GLuint typeRender;
VAO(GLuint); VAO(GLuint,unsigned int,bool);
~VAO(); ~VAO();
void addData(int,float*,int); void addData(int,float*,int);
void bufferData(); void bufferData();
void render2D(); void render();
void render3D();
}; };
class VBO{ class VBO{
private:
void render2D();
void render3D();
void bufferData2D();
void bufferData3D();
public: public:
GLuint id; GLuint id;
GLuint typeRender; GLuint typeRender;
bool isIn3DRender;
std::vector<float> data; std::vector<float> data;
int size; int size;
VBO(); VBO();
VBO(GLuint); VBO(GLuint,bool);
~VBO(); ~VBO();
void addData(float*,int); void addData(float*,int);
void bufferData(); void bufferData();
void render2D(); void render();
void render3D();
void bindBuffer(); void bindBuffer();
void unBindBuffer(); void unBindBuffer();
}; };

View file

@ -1,34 +1,45 @@
#include "renderer.h" #include "renderer.h"
VAO::VAO(GLuint typeRender){ VAO::VAO(GLuint typeRender,unsigned int nm,bool isIn3DRender){
glGenVertexArrays(1,&id);
glBindVertexArray(id);
this->typeRender = typeRender; this->typeRender = typeRender;
this->data.push_back(new VBO(typeRender)); for(int i = 0;i < 4;i++){
this->data.push_back(new VBO(typeRender)); data.push_back(new VBO(typeRender,isIn3DRender));
this->data.push_back(new VBO(typeRender)); }
this->data.push_back(new VBO(typeRender)); glBindVertexArray(0);
this->n = nm;
this->isIn3DRender = isIn3DRender;
} }
VAO::~VAO(){ VAO::~VAO(){
for(int i = 0;i < 4;i++){ glBindVertexArray(id);
for(int i = 0;i < this->n;i++){
delete this->data[i]; delete this->data[i];
} }
this->data.clear(); this->data.clear();
glBindVertexArray(0);
glDeleteVertexArrays(1,&id);
} }
void VAO::addData(int type,float* data,int size){ void VAO::addData(int i,float* data,int size){
this->data[type]->addData(data,size); glBindVertexArray(id);
this->data[i]->addData(data,size);
glBindVertexArray(0);
} }
void VAO::bufferData(){ void VAO::bufferData(){
glBindVertexArray(id);
for(int i = 0;i < 4;i++){ for(int i = 0;i < 4;i++){
this->data[i]->bufferData(); this->data[i]->bufferData();
} }
glBindVertexArray(0);
} }
void VAO::render2D(){ void VAO::render(){
glBindVertexArray(id);
for(int i = 0;i < 4;i++){
this->data[i]->render();
}
glBindVertexArray(0);
} }
void VAO::render3D(){
}

View file

@ -4,12 +4,14 @@ VBO::VBO(){
this->typeRender = GL_TRIANGLE_STRIP; this->typeRender = GL_TRIANGLE_STRIP;
glGenBuffers(1,&this->id); glGenBuffers(1,&this->id);
this->size = 0; this->size = 0;
this->isIn3DRender = true;
} }
VBO::VBO(GLuint typeRender){ VBO::VBO(GLuint typeRender,bool isIn3DRender){
this->typeRender = typeRender; this->typeRender = typeRender;
glGenBuffers(1,&this->id); glGenBuffers(1,&this->id);
this->size = 0; this->size = 0;
this->isIn3DRender = isIn3DRender;
} }
VBO::~VBO(){ VBO::~VBO(){
@ -17,6 +19,7 @@ VBO::~VBO(){
glDeleteBuffers(1,&this->id); glDeleteBuffers(1,&this->id);
} }
// 2 ou 3 vertex + 4 color (RGBA) + TexCoords + Normal
void VBO::addData(float* data,int size){ void VBO::addData(float* data,int size){
for(int i = 0;i < size;i++){ for(int i = 0;i < size;i++){
this->data.push_back(data[i]); this->data.push_back(data[i]);
@ -25,8 +28,55 @@ void VBO::addData(float* data,int size){
} }
void VBO::bufferData(){ void VBO::bufferData(){
if(this->isIn3DRender) bufferData3D();
else bufferData2D();
}
void VBO::bufferData2D(){
glBindBuffer(GL_ARRAY_BUFFER,this->id); glBindBuffer(GL_ARRAY_BUFFER,this->id);
glBufferData(GL_ARRAY_BUFFER, this->size,&this->data[0], GL_STATIC_DRAW); glBufferData(GL_ARRAY_BUFFER, this->size,&this->data[0], GL_STATIC_DRAW);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 2, GL_FLOAT, false, (2 + 3 + 4 + 2) * sizeof(float), 0);
glEnableVertexAttribArray(3);
glVertexAttribPointer(3, 3, GL_FLOAT, false, (2 + 3 + 4 + 2) * sizeof(float), (void*)(2 * sizeof(float)));
glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 4, GL_FLOAT, false, (2 + 3 + 4 + 2) * sizeof(float), (void*)((2 + 3) * sizeof(float)));
glEnableVertexAttribArray(2);
glVertexAttribPointer(2, 2, GL_FLOAT, false, (2 + 3 + 4 + 2) * sizeof(float), (void*)((2 + 3 + 4) * sizeof(float)));
glDisableVertexAttribArray(0);
glDisableVertexAttribArray(1);
glDisableVertexAttribArray(2);
glDisableVertexAttribArray(3);
glBindBuffer(GL_ARRAY_BUFFER,0);
}
void VBO::bufferData3D(){
glBindBuffer(GL_ARRAY_BUFFER,this->id);
glBufferData(GL_ARRAY_BUFFER, this->size,&this->data[0], GL_STATIC_DRAW);
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, false, (3 + 3 + 4 + 2) * sizeof(float), 0);
glEnableVertexAttribArray(3);
glVertexAttribPointer(3, 3, GL_FLOAT, false, (3 + 3 + 4 + 2) * sizeof(float), (void*)(3 * sizeof(float)));
glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 4, GL_FLOAT, false, (3 + 3 + 4 + 2) * sizeof(float), (void*)((3 + 3) * sizeof(float)));
glEnableVertexAttribArray(2);
glVertexAttribPointer(2, 2, GL_FLOAT, false, (3 + 3 + 4 + 2) * sizeof(float), (void*)((3 + 3 + 4) * sizeof(float)));
glDisableVertexAttribArray(0);
glDisableVertexAttribArray(1);
glDisableVertexAttribArray(2);
glDisableVertexAttribArray(3);
glBindBuffer(GL_ARRAY_BUFFER,0); glBindBuffer(GL_ARRAY_BUFFER,0);
} }
@ -37,11 +87,45 @@ void VBO::bindBuffer(){
void VBO::unBindBuffer(){ void VBO::unBindBuffer(){
glBindBuffer(GL_ARRAY_BUFFER,0); glBindBuffer(GL_ARRAY_BUFFER,0);
} }
void VBO::render(){
if(this->isIn3DRender) render3D();
else render2D();
}
void VBO::render2D(){ void VBO::render2D(){
// Plus tard pas besoin pour l instant glBindBuffer(GL_ARRAY_BUFFER,this->id);
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
glEnableVertexAttribArray(2);
glEnableVertexAttribArray(3);
glDrawArrays(GL_QUADS, 0, size/(2 + 3 + 4 + 2));
glDisableVertexAttribArray(0);
glDisableVertexAttribArray(1);
glDisableVertexAttribArray(2);
glDisableVertexAttribArray(3);
glBindBuffer(GL_ARRAY_BUFFER,0);
} }
void VBO::render3D(){ void VBO::render3D(){
// Plus tard pas besoin pour l instant glBindBuffer(GL_ARRAY_BUFFER,this->id);
glEnableVertexAttribArray(0);
glEnableVertexAttribArray(1);
glEnableVertexAttribArray(2);
glEnableVertexAttribArray(3);
glDrawArrays(GL_QUADS, 0, size/(3 + 3 + 4 + 2));
glDisableVertexAttribArray(0);
glDisableVertexAttribArray(1);
glDisableVertexAttribArray(2);
glDisableVertexAttribArray(3);
glBindBuffer(GL_ARRAY_BUFFER,0);
} }