gKit2 light
Loading...
Searching...
No Matches
tuto_dynamic_cubemap.cpp File Reference

rendu dans une cubemap More...

#include <memory>
#include "wavefront.h"
#include "texture.h"
#include "orbiter.h"
#include "program.h"
#include "uniforms.h"
#include "draw.h"
#include "app_camera.h"

Go to the source code of this file.

Classes

class  TP
struct  TP::Object

Functions

GLuint read_cubemap (const int unit, const char *filename, const GLenum texel_type=GL_RGBA)
 charge une image, decoupe les 6 faces et renvoie une texture cubemap.
Mesh make_grid (const int n=10)
int main (int argc, char **argv)

Detailed Description

rendu dans une cubemap

Definition in file tuto_dynamic_cubemap.cpp.


Class Documentation

◆ TP::Object

struct TP::Object

Definition at line 202 of file tuto_dynamic_cubemap.cpp.

Class Members
Transform model
Color color

Function Documentation

◆ read_cubemap()

GLuint read_cubemap ( const int unit,
const char * filename,
const GLenum texel_type = GL_RGBA )

charge une image, decoupe les 6 faces et renvoie une texture cubemap.

Definition at line 18 of file tuto_dynamic_cubemap.cpp.

19{
20 // les 6 faces sur une croix
21 ImageData image= read_image_data(filename);
22 if(image.pixels.empty())
23 return 0;
24
25 int w= image.width / 4;
26 int h= image.height / 3;
27 assert(w == h);
28
29 GLenum data_format;
30 GLenum data_type= GL_UNSIGNED_BYTE;
31 if(image.channels == 3)
32 data_format= GL_RGB;
33 else // par defaut
34 data_format= GL_RGBA;
35
36 // creer la texture
37 GLuint texture= 0;
38 glGenTextures(1, &texture);
39 glActiveTexture(GL_TEXTURE0 + unit);
40 glBindTexture(GL_TEXTURE_CUBE_MAP, texture);
41
42 // creer les 6 faces
43 // chaque face de la cubemap est un rectangle [image.width/4 x image.height/3] dans l'image originale
44 struct { int x, y; } faces[]= {
45 {0, 1}, // X+
46 {2, 1}, // X-
47 {1, 2}, // Y+
48 {1, 0}, // Y-
49 {1, 1}, // Z+
50 {3, 1}, // Z-
51 };
52
53 for(int i= 0; i < 6; i++)
54 {
55 ImageData face= flipX(flipY(copy(image, faces[i].x*w, faces[i].y*h, w, h)));
56
57 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X +i, 0,
58 texel_type, w, h, 0,
59 data_format, data_type, face.data());
60 }
61
62 // parametres de filtrage
63 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
64 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
65 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
66 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
67 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
68
69 glGenerateMipmap(GL_TEXTURE_CUBE_MAP);
70
71 // filtrage "correct" sur les bords du cube...
72 glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS);
73 //~ glDisable(GL_TEXTURE_CUBE_MAP_SEAMLESS);
74
75 printf(" cubemap faces %dx%d\n", w, h);
76
77 return texture;
78}
void printf(Text &text, const int px, const int py, const char *format,...)
affiche un texte a la position x, y. meme utilisation que printf().
Definition text.cpp:140
Image flipY(const Image &image)
retourne l'image
Definition image_io.cpp:112
Image flipX(const Image &image)
retourne l'image
Definition image_io.cpp:129
ImageData read_image_data(const void *buffer, const unsigned size, const bool flipY)
charge les donnees d'un fichier png stocke en memoire. renvoie une image initialisee par defaut en ca...
Definition image_io.cpp:315
Image copy(const Image &image, const unsigned xmin, const unsigned ymin, const unsigned width, const unsigned height)
renvoie un bloc de l'image
Definition image_io.cpp:145
stockage temporaire des donnees d'une image.
Definition image_io.h:53

◆ make_grid()

Mesh make_grid ( const int n = 10)

Definition at line 82 of file tuto_dynamic_cubemap.cpp.

83{
84 Mesh grid= Mesh(GL_LINES);
85
86 // grille
87 grid.color(White());
88 float w= float(n-1) / 2;
89 for(int x= 0; x < n; x++)
90 {
91 grid.vertex(x -w, 0, -w);
92 grid.vertex(x -w, 0, w);
93 }
94
95 for(int z= 0; z < n; z++)
96 {
97 grid.vertex(-w, 0, z -w);
98 grid.vertex( w, 0, z -w);
99 }
100
101 // axes XYZ
102 grid.color(Red());
103 grid.vertex(Point(0, .1, 0));
104 grid.vertex(Point(1, .1, 0));
105
106 grid.color(Green());
107 grid.vertex(Point(0, .1, 0));
108 grid.vertex(Point(0, 1, 0));
109
110 grid.color(Blue());
111 grid.vertex(Point(0, .1, 0));
112 grid.vertex(Point(0, .1, 1));
113
114 return grid;
115}
representation d'un objet / maillage.
Definition mesh.h:121
unsigned int vertex(const vec3 &p)
insere un sommet de position p, et ses attributs (s'ils sont definis par color(), texcoord(),...
Definition mesh.cpp:97
Mesh & color(const vec4 &c)
definit la couleur du prochain sommet.
Definition mesh.cpp:66
Color Red()
utilitaire. renvoie une couleur rouge.
Definition color.cpp:28
Color Blue()
utilitaire. renvoie une couleur bleue.
Definition color.cpp:38
Color Green()
utilitaire. renvoie une couleur verte.
Definition color.cpp:33
Color White()
utilitaire. renvoie une couleur blanche.
Definition color.cpp:23
representation d'un point 3d.
Definition vec.h:21

◆ main()

int main ( int argc,
char ** argv )

Definition at line 397 of file tuto_dynamic_cubemap.cpp.

398{
399 TP tp;
400 tp.run();
401
402 return 0;
403}
int run()
execution de l'application.
Definition app.cpp:36
Definition alpha.cpp:58