gKit2 light

- Main Page
- Related Pages
- Modules
- Classes
- Files

- File List
- File Members

Classes | Functions | Variables
shader_kit.cpp File Reference

shader_kit light, bac a sable fragment shader, cf shader_toy More...

`#include <cstdio>`
`#include <cstring>`
`#include "glcore.h"`
`#include "window.h"`
`#include "program.h"`
`#include "uniforms.h"`
`#include "texture.h"`
`#include "mesh.h"`
`#include "wavefront.h"`
`#include "buffer.h"`
`#include "vec.h"`
`#include "mat.h"`
`#include "orbiter.h"`
`#include "text.h"`
`#include "widgets.h"`

Go to the source code of this file.

## Classes
struct | Filename

## Functions
void | reload_program ()
const char * | option_find (std::vector< const char * > &options, const char *ext)
int | init (std::vector< const char * > &options)
int | quit ()
int | draw (void)
int | main (int argc, char **argv)

## Variables
Filename | program_filename
GLuint | program
std::string | program_log
int | program_area
bool | program_failed
Filename | mesh_filename
Mesh | mesh
Point | mesh_pmin
Point | mesh_pmax
int | vertex_count
GLuint | vao
bool | wireframe = false
std::vector< Filename > | texture_filenames
std::vector< GLuint > | textures
Orbiter | camera
Widgets | widgets

## Detailed Description

shader_kit light, bac a sable fragment shader, cf shader_toy

Definition in file shader_kit.cpp.

## Function Documentation

int init | ( | std::vector< const char * > & | options | ) |

compile les shaders et construit le programme + les buffers + le vertex array. renvoie -1 en cas d'erreur.

Definition at line 96 of file shader_kit.cpp.

97 {
98 widgets= create_widgets();
99 camera= Orbiter();
100
101 program= 0;
102 const char *option;
103 option= option_find(options, ".glsl");
104 if(option != NULL)
105 {
106 program_filename= Filename(option);
107 reload_program();
108 }
109
110 glGenVertexArrays(1, &vao);
111 vertex_count= 3;
112
113 option= option_find(options, ".obj");
114 if(option != NULL)
115 {
116 mesh= read_mesh(option);
117 if(mesh.vertex_buffer_size() > 0)
118 {
119 mesh_filename= Filename(option);
120
121 vao= mesh.create_buffers();
122 vertex_count= mesh.vertex_count();
123
124 mesh.bounds(mesh_pmin, mesh_pmax);
125 camera.lookat(mesh_pmin, mesh_pmax);
126 }
127 }
128
129 // charge les textures, si necessaire
130 for(unsigned int i= 0; i < (unsigned int) options.size(); i++)
131 {
132 GLuint texture= read_texture(0, options[i]);
133 if(texture > 0)
134 {
135 texture_filenames.push_back(Filename(options[i]));
136 textures.push_back(texture);
137 }
138 }
139
140 // nettoyage
141 glUseProgram(0);
142 glBindTexture(GL_TEXTURE_2D, 0);
143 glBindVertexArray(0);
144 glBindBuffer(GL_ARRAY_BUFFER, 0);
145 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
146
147 // etat openGL par defaut
148 glClearColor(0.2f, 0.2f, 0.2f, 1.f);
149 glClearDepth(1.f);
150
151 glCullFace(GL_BACK);
152 glFrontFace(GL_CCW);
153 //~ glEnable(GL_CULL_FACE); // n'affiche que les faces correctement orientees...
154 glDisable(GL_CULL_FACE); // les faces mal orientees sont affichees avec des hachures oranges...
155
156 glDepthFunc(GL_LESS);
157 glEnable(GL_DEPTH_TEST);
158
159 return 0;
160 }
Orbiter
representation de la camera, type orbiter, placee sur une sphere autour du centre de l'objet...
Definition: orbiter.h:16
Mesh::bounds
void bounds(Point &pmin, Point &pmax)
renvoie min et max les coordonnees des extremites des positions des sommets de l'objet (boite engloba...
Definition: mesh.cpp:146
create_widgets
Widgets create_widgets()
cree une interface graphique. a detruire avec release_widgets( ).
Definition: widgets.cpp:12
Mesh::vertex_buffer_size
std::size_t vertex_buffer_size() const
renvoie la longueur (en octets) du vertex buffer.
Definition: mesh.h:199
Mesh::create_buffers
GLuint create_buffers(const bool use_texcoord=true, const bool use_normal=true, const bool use_color=true)
Definition: mesh.cpp:189
read_texture
GLuint read_texture(const int unit, const char *filename)
cree une texture a partir d'un fichier filename. a detruire avec glDeleteTextures( )...
Definition: texture.cpp:97
Orbiter::lookat
void lookat(const Point &center, const float size)
observe le point center a une distance size.
Definition: orbiter.cpp:6
Mesh::vertex_count
int vertex_count() const
renvoie le nombre de sommets.
Definition: mesh.h:192
Filename
Definition: shader_kit.cpp:27
read_mesh
Mesh read_mesh(const char *filename)
charge un fichier wavefront .obj et renvoie un mesh compose de triangles non indexes. utiliser glDrawArrays pour l'afficher. a detruire avec Mesh::release( ).
Definition: wavefront.cpp:8