goat3dgfx
diff examples/cubemap/src/main.cc @ 6:3d96734fd477
cubemap loading and cubemap example program
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sun, 17 Nov 2013 08:20:13 +0200 |
parents | 18879c956eb1 |
children | 25b911c7c35c |
line diff
1.1 --- a/examples/cubemap/src/main.cc Sun Nov 17 03:22:40 2013 +0200 1.2 +++ b/examples/cubemap/src/main.cc Sun Nov 17 08:20:13 2013 +0200 1.3 @@ -4,7 +4,7 @@ 1.4 #include <goat3dgfx/goat3dgfx.h> 1.5 #include <vmath/vmath.h> 1.6 1.7 -#define CUBEMAP_FILENAME "data/cubemap3.jpg" 1.8 +#define CUBEMAP_FILENAME "data/cubemap2.jpg" 1.9 1.10 static bool init(); 1.11 static void cleanup(); 1.12 @@ -79,16 +79,7 @@ 1.13 1.14 setup_gl_matrices(); 1.15 1.16 - skybox(); 1.17 - 1.18 - /*glBegin(GL_QUADS); 1.19 - glColor3f(1, 1, 1); 1.20 - glNormal3f(0, 1, 0); 1.21 - glVertex3f(-0.8, -1, 0.8); 1.22 - glVertex3f(0.8, -1, 0.8); 1.23 - glVertex3f(0.8, -1, -0.8); 1.24 - glVertex3f(-0.8, -1, -0.8); 1.25 - glEnd();*/ 1.26 + skybox(cubemap); 1.27 1.28 glutSwapBuffers(); 1.29 CHECKGLERR; 1.30 @@ -96,52 +87,24 @@ 1.31 1.32 static void skybox(const TextureCube *cubemap) 1.33 { 1.34 + static Mesh *skybox; 1.35 + 1.36 + if(!skybox) { 1.37 + skybox = new Mesh; 1.38 + gen_sphere(skybox, 10.0, 12, 6); 1.39 + } 1.40 + 1.41 glPushAttrib(GL_ENABLE_BIT | GL_TEXTURE_BIT); 1.42 glDisable(GL_DEPTH_TEST); 1.43 glDisable(GL_CULL_FACE); 1.44 glDisable(GL_LIGHTING); 1.45 1.46 + glEnable(GL_TEXTURE_CUBE_MAP); 1.47 + 1.48 if(cubemap) cubemap->bind(); 1.49 sdrsky->bind(); 1.50 1.51 - glBegin(GL_QUADS); 1.52 - // +X 1.53 - glColor3f(1, 0, 0); 1.54 - glVertex3f(1, -1, 1); 1.55 - glVertex3f(1, -1, -1); 1.56 - glVertex3f(1, 1, -1); 1.57 - glVertex3f(1, 1, 1); 1.58 - // -Z 1.59 - glColor3f(0, 1, 0); 1.60 - glVertex3f(1, -1, -1); 1.61 - glVertex3f(-1, -1, -1); 1.62 - glVertex3f(-1, 1, -1); 1.63 - glVertex3f(1, 1, -1); 1.64 - // -X 1.65 - glColor3f(0, 0, 1); 1.66 - glVertex3f(-1, -1, -1); 1.67 - glVertex3f(-1, -1, 1); 1.68 - glVertex3f(-1, 1, 1); 1.69 - glVertex3f(-1, 1, -1); 1.70 - // +Z 1.71 - glColor3f(1, 1, 0); 1.72 - glVertex3f(-1, -1, 1); 1.73 - glVertex3f(1, -1, 1); 1.74 - glVertex3f(1, 1, 1); 1.75 - glVertex3f(-1, 1, 1); 1.76 - // +Y 1.77 - glColor3f(0, 1, 1); 1.78 - glVertex3f(-1, 1, 1); 1.79 - glVertex3f(1, 1, 1); 1.80 - glVertex3f(1, 1, -1); 1.81 - glVertex3f(-1, 1, -1); 1.82 - // -Y 1.83 - glColor3f(1, 0, 1); 1.84 - glVertex3f(-1, -1, -1); 1.85 - glVertex3f(1, -1, -1); 1.86 - glVertex3f(1, -1, 1); 1.87 - glVertex3f(-1, -1, 1); 1.88 - glEnd(); 1.89 + skybox->draw(); 1.90 1.91 glUseProgram(0); 1.92 glPopAttrib();