view3d
changeset 4:0aee5df08cfc
fixed some shit
author | John Tsiombikas <nuclear@mutantstargoat.com> |
---|---|
date | Thu, 19 Jan 2012 07:03:47 +0200 |
parents | 7e982a61852a |
children | 58ddd42848f9 |
files | src/main.c src/scene.c |
diffstat | 2 files changed, 20 insertions(+), 14 deletions(-) [+] |
line diff
1.1 --- a/src/main.c Thu Jan 19 06:15:10 2012 +0200 1.2 +++ b/src/main.c Thu Jan 19 07:03:47 2012 +0200 1.3 @@ -44,6 +44,7 @@ 1.4 1.5 int main(int argc, char **argv) 1.6 { 1.7 + float amb[] = {0.01, 0.01, 0.01, 1}; 1.8 float ldir[] = {-1, 1, 1, 0}; 1.9 float dx, dy, dz, diag; 1.10 1.11 @@ -55,7 +56,7 @@ 1.12 } 1.13 1.14 glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE | (stereo ? GLUT_STEREO : 0)); 1.15 - glutCreateWindow("OpenGL Logo"); 1.16 + glutCreateWindow("OpenGL 3D viewer"); 1.17 1.18 glutDisplayFunc(disp); 1.19 glutReshapeFunc(reshape); 1.20 @@ -72,12 +73,15 @@ 1.21 1.22 glewInit(); 1.23 1.24 + glEnable(GL_NORMALIZE); 1.25 glEnable(GL_DEPTH_TEST); 1.26 glEnable(GL_CULL_FACE); 1.27 glEnable(GL_LIGHTING); 1.28 glEnable(GL_LIGHT0); 1.29 glLightfv(GL_LIGHT0, GL_POSITION, ldir); 1.30 1.31 + glLightModelfv(GL_LIGHT_MODEL_AMBIENT, amb); 1.32 + 1.33 if((load_scene(&scn, scene_fname)) == -1) { 1.34 fprintf(stderr, "failed to load: %s\n", scene_fname); 1.35 return 1;
2.1 --- a/src/scene.c Thu Jan 19 06:15:10 2012 +0200 2.2 +++ b/src/scene.c Thu Jan 19 07:03:47 2012 +0200 2.3 @@ -26,17 +26,17 @@ 2.4 const struct aiScene *aiscn; 2.5 unsigned int proc_flags = aiProcess_JoinIdenticalVertices | 2.6 aiProcess_PreTransformVertices | aiProcess_Triangulate | 2.7 - aiProcess_SortByPType; 2.8 - 2.9 - if(verbose) { 2.10 - printf("scene: %s (%d meshes, %d lights)\n", fname, aiscn->mNumMeshes, aiscn->mNumLights); 2.11 - } 2.12 + aiProcess_GenNormals | aiProcess_SortByPType; 2.13 2.14 if(!(aiscn = aiImportFile(fname, proc_flags))) { 2.15 fprintf(stderr, "failed to load: %s\n", fname); 2.16 return -1; 2.17 } 2.18 2.19 + if(verbose) { 2.20 + printf("scene: %s (%d meshes, %d lights)\n", fname, aiscn->mNumMeshes, aiscn->mNumLights); 2.21 + } 2.22 + 2.23 scn->meshes = 0; 2.24 scn->lights = 0; 2.25 2.26 @@ -252,19 +252,19 @@ 2.27 struct light *lt = scn->lights; 2.28 int pass = 0; 2.29 2.30 + glEnable(GL_BLEND); 2.31 + glDepthFunc(GL_LEQUAL); 2.32 + 2.33 while(lt || pass == 0) { 2.34 struct mesh *m; 2.35 2.36 setup_light(lt); 2.37 2.38 - glEnable(GL_BLEND); 2.39 - 2.40 - if(pass > 0) { 2.41 + if(pass == 0) { 2.42 + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 2.43 + } else { 2.44 glBlendFunc(GL_SRC_ALPHA, GL_ONE); 2.45 glDepthMask(0); 2.46 - } else { 2.47 - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 2.48 - glDepthMask(1); 2.49 } 2.50 2.51 m = scn->meshes; 2.52 @@ -273,7 +273,11 @@ 2.53 m = m->next; 2.54 } 2.55 pass++; 2.56 + lt = lt->next; 2.57 } 2.58 + 2.59 + glDisable(GL_BLEND); 2.60 + glDepthMask(1); 2.61 } 2.62 2.63 static void setup_light(struct light *lt) 2.64 @@ -305,8 +309,6 @@ 2.65 glBindTexture(GL_TEXTURE_2D, m->mat.tex); 2.66 } 2.67 2.68 - /* TODO texture */ 2.69 - 2.70 glBindBuffer(GL_ARRAY_BUFFER, m->vert_buf); 2.71 glVertexPointer(3, GL_FLOAT, 0, 0); 2.72 glEnableClientState(GL_VERTEX_ARRAY);