Update cmake
This commit is contained in:
parent
9b1b3a5c97
commit
8f9bc0da09
7 changed files with 164 additions and 34 deletions
|
@ -1,5 +1,10 @@
|
|||
#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")
|
||||
|
||||
cmake_minimum_required(VERSION 2.6)
|
||||
|
@ -14,9 +19,19 @@ set(EXECUTABLE_OUTPUT_PATH bin/${CMAKE_BUILD_TYPE})
|
|||
#Inclusion de Boost
|
||||
|
||||
IF (WIN32)
|
||||
include_directories($ENV{MINGW_HOME}/usr/include)
|
||||
link_directories($ENV{MINGW_HOME}/usr/lib)
|
||||
include_directories($ENV{MINGW_HOME}/include)
|
||||
link_directories($ENV{MINGW_HOME}/lib)
|
||||
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)
|
||||
link_directories(/usr/lib)
|
||||
ENDIF()
|
||||
|
@ -37,7 +52,6 @@ add_executable(
|
|||
)
|
||||
|
||||
|
||||
|
||||
#Configuration de l'édition de liens
|
||||
|
||||
|
||||
|
|
3
configure.sh
Normal file
3
configure.sh
Normal 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
|
|
@ -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){
|
||||
gl_FragColor= vec4(1, 1 - abs(y)/50,1 - abs(y)/50,1);
|
||||
}
|
||||
gl_FragColor = color * texture2D(myTexture,out_coord_texture);
|
||||
}
|
||||
|
|
|
@ -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){
|
||||
gl_FrontColor = gl_Color;
|
||||
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
|
||||
}
|
||||
gl_Position = gl_ModelViewProjectionMatrix * vec4(in_position,1.0f);
|
||||
}
|
||||
|
|
|
@ -32,34 +32,40 @@ class VAO;
|
|||
|
||||
class VAO{
|
||||
public:
|
||||
static const int VERTEX_DATA = 0,COLOR_DATA = 1,TEX_COORD_DATA = 2,NORMAL_DATA = 3;
|
||||
std::vector<VBO*> data;
|
||||
unsigned int n;
|
||||
bool isIn3DRender;
|
||||
GLuint id;
|
||||
GLuint typeRender;
|
||||
|
||||
VAO(GLuint);
|
||||
VAO(GLuint,unsigned int,bool);
|
||||
~VAO();
|
||||
void addData(int,float*,int);
|
||||
void bufferData();
|
||||
void render2D();
|
||||
void render3D();
|
||||
void render();
|
||||
};
|
||||
|
||||
class VBO{
|
||||
|
||||
private:
|
||||
void render2D();
|
||||
void render3D();
|
||||
void bufferData2D();
|
||||
void bufferData3D();
|
||||
|
||||
public:
|
||||
GLuint id;
|
||||
GLuint typeRender;
|
||||
bool isIn3DRender;
|
||||
std::vector<float> data;
|
||||
int size;
|
||||
|
||||
VBO();
|
||||
VBO(GLuint);
|
||||
VBO(GLuint,bool);
|
||||
~VBO();
|
||||
void addData(float*,int);
|
||||
void bufferData();
|
||||
void render2D();
|
||||
void render3D();
|
||||
void render();
|
||||
void bindBuffer();
|
||||
void unBindBuffer();
|
||||
};
|
||||
|
|
|
@ -1,34 +1,45 @@
|
|||
#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->data.push_back(new VBO(typeRender));
|
||||
this->data.push_back(new VBO(typeRender));
|
||||
this->data.push_back(new VBO(typeRender));
|
||||
this->data.push_back(new VBO(typeRender));
|
||||
for(int i = 0;i < 4;i++){
|
||||
data.push_back(new VBO(typeRender,isIn3DRender));
|
||||
}
|
||||
glBindVertexArray(0);
|
||||
this->n = nm;
|
||||
this->isIn3DRender = isIn3DRender;
|
||||
}
|
||||
|
||||
VAO::~VAO(){
|
||||
for(int i = 0;i < 4;i++){
|
||||
glBindVertexArray(id);
|
||||
for(int i = 0;i < this->n;i++){
|
||||
delete this->data[i];
|
||||
}
|
||||
this->data.clear();
|
||||
glBindVertexArray(0);
|
||||
glDeleteVertexArrays(1,&id);
|
||||
}
|
||||
|
||||
void VAO::addData(int type,float* data,int size){
|
||||
this->data[type]->addData(data,size);
|
||||
void VAO::addData(int i,float* data,int size){
|
||||
glBindVertexArray(id);
|
||||
this->data[i]->addData(data,size);
|
||||
glBindVertexArray(0);
|
||||
}
|
||||
|
||||
void VAO::bufferData(){
|
||||
glBindVertexArray(id);
|
||||
for(int i = 0;i < 4;i++){
|
||||
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(){
|
||||
|
||||
}
|
|
@ -4,12 +4,14 @@ VBO::VBO(){
|
|||
this->typeRender = GL_TRIANGLE_STRIP;
|
||||
glGenBuffers(1,&this->id);
|
||||
this->size = 0;
|
||||
this->isIn3DRender = true;
|
||||
}
|
||||
|
||||
VBO::VBO(GLuint typeRender){
|
||||
VBO::VBO(GLuint typeRender,bool isIn3DRender){
|
||||
this->typeRender = typeRender;
|
||||
glGenBuffers(1,&this->id);
|
||||
this->size = 0;
|
||||
this->isIn3DRender = isIn3DRender;
|
||||
}
|
||||
|
||||
VBO::~VBO(){
|
||||
|
@ -17,6 +19,7 @@ VBO::~VBO(){
|
|||
glDeleteBuffers(1,&this->id);
|
||||
}
|
||||
|
||||
// 2 ou 3 vertex + 4 color (RGBA) + TexCoords + Normal
|
||||
void VBO::addData(float* data,int size){
|
||||
for(int i = 0;i < size;i++){
|
||||
this->data.push_back(data[i]);
|
||||
|
@ -25,8 +28,55 @@ void VBO::addData(float* data,int size){
|
|||
}
|
||||
|
||||
void VBO::bufferData(){
|
||||
if(this->isIn3DRender) bufferData3D();
|
||||
else bufferData2D();
|
||||
}
|
||||
|
||||
void VBO::bufferData2D(){
|
||||
glBindBuffer(GL_ARRAY_BUFFER,this->id);
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -37,11 +87,45 @@ void VBO::bindBuffer(){
|
|||
void VBO::unBindBuffer(){
|
||||
glBindBuffer(GL_ARRAY_BUFFER,0);
|
||||
}
|
||||
|
||||
void VBO::render(){
|
||||
if(this->isIn3DRender) render3D();
|
||||
else 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(){
|
||||
// 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);
|
||||
}
|
Reference in a new issue