jerrylin88

Member
  • Content count

    9
  • Joined

  • Last visited

Community Reputation

100 Neutral

About jerrylin88

  • Rank
    Newbie
  1. [quote name='FXACE' timestamp='1295709980' post='4762983'] I'm not sure that my notes can fix your problem... but... (in "main" function) GL_DEPTH_BITS is not used for glClear (it's for glGetIntegerv that returns a value of number of bits containig depth buffer of current applied GL context)... You can use "gl" and "glu" commands only after created and applied GL context (it's initializing by glutCreateWindow(...) on a GLUT API)... otherwise it gives you an error at glGetError() (!=0)... Comparing of two pictures. my opinion is: "Depth buffer is not initialized (not exist) or you are using invalid parameters for visualizing the scene)..." Check out your code (in "reshape" function): "gluPerspective(45.0,w/h,0.0,5.0);" Znear plane must be > 0 (make a modifications with it to 1.0)... like this: "gluPerspective(45.0,w/h,1.0,5.0);" [/quote] thank you very much it works very well now as u mentioned because of sending the wrong parameter to the gluPerspective routine the depth buffer was not initialized correctly.after i correct it.the model turned dark partly due to the light,but obviously the tire hided the component behind it that`s remarkable!
  2. [quote name='FXACE' timestamp='1295642488' post='4762627'] Can you introduce a model (as "how it must looks like") ? for better searching of the problem... [/quote] some other tools showed what that model should be look like perfectly(i am gonna upload the pic later),since it`s just an earlier version of drawing models with non-texture lighting support,the model should be rendered and composed of some smooth and non-textured solid objects,when i say "smooth" i mean the deeper points should be hidden by nearer points other than nearer points hidden by deeper points(i`ve already clear the depth buffer b4 rendering).take a look at my newest picture.
  3. [quote name='run_g' timestamp='1295614723' post='4762367'] Might be a newbie ques. I cant find code examples of how to put specular light shade component a texture mapped object. The program i'm writting the specular light shade only appear non-texture mapped objects. Does any one have a code example or program of specular highlight on textures to share? thanx [/quote] actually i am doing the same job take a look at my post [url="http://www.gamedev.net/topic/593514-problem-with-broken-fragment-improperly-rendering/"]http://www.gamedev.net/topic/593514-problem-with-broken-fragment-improperly-rendering/[/url] but i do believe that specular light have obvious effect on my non-texture model because when i turn down the specular component of light the model changed. undoubtedly u should specify the normal per pixel b4 assigning the light that`s as far as i know hope it helps.but i`ve no idea how those broken fragment came out.let me know anything u hit after another try.
  4. i am currently using lib3ds library loading a vehicle model from 3ds file after i draw in on the screen it appears that there r a lot of broken fragment and cannot be rendered properly.it seems that there r some far points draw onto a nearer surface but i`ve no idea what `s the problem really any answer would be appreciated. [code] #include <windows.h> #include <gl/gl.h> #include <gl/glu.h> #include <gl/glut.h> #include <lib3ds.h> #include <iostream> typedef float Lib3dsVector[3]; typedef float Lib3dsTexel[2]; using namespace std; Lib3dsFile* model; Lib3dsMesh** mesh; Lib3dsCamera** camera; Lib3dsFace* face; Lib3dsLight** light; Lib3dsMaterial** material; unsigned long total_face; void lightup() { glShadeModel(GL_SMOOTH); glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); glFrontFace(GL_CCW); glCullFace(GL_BACK); float gambient[]={0.2,0.2,0.2,1.0}; float lightpos[]={1.0,1.0,1.0,0.0}; float lambient[]={0.8,0.8,0.8,1.0}; float ldiffuse[]={1.0,1.0,1.0,1.0}; float lspecular[]={0.3,0.3,0.3,1.0}; glClearColor(0.0,0.0,0.0,0.0); glLightfv(GL_LIGHT0,GL_DIFFUSE,ldiffuse); glLightfv(GL_LIGHT0,GL_AMBIENT,lambient); glLightfv(GL_LIGHT0,GL_SPECULAR,lspecular); glLightfv(GL_LIGHT0,GL_POSITION,lightpos); glLightModelfv(GL_LIGHT_MODEL_AMBIENT,gambient); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); } void display() { glEnable(GL_DEPTH_TEST); glClearDepth(1.0); glDepthFunc(GL_LEQUAL); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glLoadIdentity(); gluLookAt(camera[0]->position[0]+1000,camera[0]->position[1],camera[0]->position[2],camera[0]->target[0],camera[0]->target[1],camera[0]->target[2],0.0,0.0,1.0); glColor3f(1.0,0.0,0.0); glPushMatrix(); lightup(); glTranslatef(0.0,0.0,-1000.0); long meshcount; for(meshcount=0;meshcount<model->nmeshes;meshcount++) { face=mesh[meshcount]->faces; Lib3dsVector* vertex_normal=new Lib3dsVector[mesh[meshcount]->nfaces*3]; Lib3dsVector* face_normal=new Lib3dsVector[mesh[meshcount]->nfaces]; lib3ds_mesh_calculate_vertex_normals(mesh[meshcount],vertex_normal); lib3ds_mesh_calculate_face_normals(mesh[meshcount],face_normal); for(long i=0;i<mesh[meshcount]->nfaces;i++) { glMaterialfv(GL_FRONT,GL_DIFFUSE,material[face[i].material]->diffuse); glMaterialfv(GL_FRONT,GL_AMBIENT,material[face[i].material]->ambient); glMaterialfv(GL_FRONT,GL_SPECULAR,material[face[i].material]->specular); glBegin(GL_TRIANGLES); glNormal3fv(face_normal[i]); glNormal3fv(vertex_normal[i*3]); glVertex3fv(mesh[meshcount]->vertices[face[i].index[0]]); glNormal3fv(vertex_normal[i*3+1]); glVertex3fv(mesh[meshcount]->vertices[face[i].index[1]]); glNormal3fv(vertex_normal[i*3+2]); glVertex3fv(mesh[meshcount]->vertices[face[i].index[2]]); glEnd(); } } glPopMatrix(); /* glPushMatrix(); glTranslatef(0.0,0.0,-2000.0); glColor3f(1.0,1.0,1.0); glBegin(GL_QUADS); glVertex3f(-10000.0f,-10000.0f,0.0f); glVertex3f(10000.0f,-10000.0f,0.0f); glVertex3f(10000.0f,10000.0f,0.0f); glVertex3f(-10000.0f,10000.0f,0.0f); glEnd(); glPopMatrix(); */ glutSwapBuffers(); } void keypress(unsigned char key,int x,int y) { switch(key) { case 27: exit(0); break; } } void reshape(int w,int h) { if(h==0) h=1; glViewport(0,0,w,h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45.0,w/h,0.0,5.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } int main(int argc,char* argv[]) { glutInit(&argc,argv); model=lib3ds_file_open("vehicle.3DS"); if(model==NULL) cout<<"Error"<<endl; else cout<<model->nmaterials<<endl; mesh=model->meshes; material=model->materials; camera=model->cameras; light=model->lights; cout<<"Light Num:"<<model->nlights<<endl; glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BITS); glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE|GLUT_DEPTH); glutInitWindowSize(800,800); glutInitWindowPosition(100,100); glutCreateWindow("VC 2008 Glut"); //glutFullScreen(); glShadeModel(GL_FLAT); glutKeyboardFunc(keypress); glutDisplayFunc(display); glutReshapeFunc(reshape); glutMainLoop(); return 0; } [/code]
  5. i am currently using lib3ds library loading a vehicle model from 3ds file after i draw in on the screen it appears that there r a lot of broken fragment and cannot be rendered properly.it seems that there r some far points draw onto a nearer surface but i`ve no idea what `s the problem really any answer would be appreciated. attached is my code. [code] #include <windows.h> #include <gl/gl.h> #include <gl/glu.h> #include <gl/glut.h> #include <lib3ds.h> #include <iostream> typedef float Lib3dsVector[3]; typedef float Lib3dsTexel[2]; using namespace std; Lib3dsFile* model; Lib3dsMesh** mesh; Lib3dsCamera** camera; Lib3dsFace* face; Lib3dsLight** light; Lib3dsMaterial** material; unsigned long total_face; void lightup() { glShadeModel(GL_SMOOTH); glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); glFrontFace(GL_CCW); glCullFace(GL_BACK); float gambient[]={0.2,0.2,0.2,1.0}; float lightpos[]={1.0,1.0,1.0,0.0}; float lambient[]={0.8,0.8,0.8,1.0}; float ldiffuse[]={1.0,1.0,1.0,1.0}; float lspecular[]={0.3,0.3,0.3,1.0}; glClearColor(0.0,0.0,0.0,0.0); glLightfv(GL_LIGHT0,GL_DIFFUSE,ldiffuse); glLightfv(GL_LIGHT0,GL_AMBIENT,lambient); glLightfv(GL_LIGHT0,GL_SPECULAR,lspecular); glLightfv(GL_LIGHT0,GL_POSITION,lightpos); glLightModelfv(GL_LIGHT_MODEL_AMBIENT,gambient); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); } void display() { glEnable(GL_DEPTH_TEST); glClearDepth(1.0); glDepthFunc(GL_LEQUAL); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glLoadIdentity(); gluLookAt(camera[0]->position[0]+1000,camera[0]->position[1],camera[0]->position[2],camera[0]->target[0],camera[0]->target[1],camera[0]->target[2],0.0,0.0,1.0); glColor3f(1.0,0.0,0.0); glPushMatrix(); lightup(); glTranslatef(0.0,0.0,-1000.0); long meshcount; for(meshcount=0;meshcount<model->nmeshes;meshcount++) { face=mesh[meshcount]->faces; Lib3dsVector* vertex_normal=new Lib3dsVector[mesh[meshcount]->nfaces*3]; Lib3dsVector* face_normal=new Lib3dsVector[mesh[meshcount]->nfaces]; lib3ds_mesh_calculate_vertex_normals(mesh[meshcount],vertex_normal); lib3ds_mesh_calculate_face_normals(mesh[meshcount],face_normal); for(long i=0;i<mesh[meshcount]->nfaces;i++) { glMaterialfv(GL_FRONT,GL_DIFFUSE,material[face[i].material]->diffuse); glMaterialfv(GL_FRONT,GL_AMBIENT,material[face[i].material]->ambient); glMaterialfv(GL_FRONT,GL_SPECULAR,material[face[i].material]->specular); glBegin(GL_TRIANGLES); glNormal3fv(face_normal[i]); glNormal3fv(vertex_normal[i*3]); glVertex3fv(mesh[meshcount]->vertices[face[i].index[0]]); glNormal3fv(vertex_normal[i*3+1]); glVertex3fv(mesh[meshcount]->vertices[face[i].index[1]]); glNormal3fv(vertex_normal[i*3+2]); glVertex3fv(mesh[meshcount]->vertices[face[i].index[2]]); glEnd(); } } glPopMatrix(); /* glPushMatrix(); glTranslatef(0.0,0.0,-2000.0); glColor3f(1.0,1.0,1.0); glBegin(GL_QUADS); glVertex3f(-10000.0f,-10000.0f,0.0f); glVertex3f(10000.0f,-10000.0f,0.0f); glVertex3f(10000.0f,10000.0f,0.0f); glVertex3f(-10000.0f,10000.0f,0.0f); glEnd(); glPopMatrix(); */ glutSwapBuffers(); } void keypress(unsigned char key,int x,int y) { switch(key) { case 27: exit(0); break; } } void reshape(int w,int h) { if(h==0) h=1; glViewport(0,0,w,h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45.0,w/h,0.0,5.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } int main(int argc,char* argv[]) { glutInit(&argc,argv); model=lib3ds_file_open("vehicle.3DS"); if(model==NULL) cout<<"Error"<<endl; else cout<<model->nmaterials<<endl; mesh=model->meshes; material=model->materials; camera=model->cameras; light=model->lights; cout<<"Light Num:"<<model->nlights<<endl; glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BITS); glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE|GLUT_DEPTH); glutInitWindowSize(800,800); glutInitWindowPosition(100,100); glutCreateWindow("VC 2008 Glut"); //glutFullScreen(); glShadeModel(GL_FLAT); glutKeyboardFunc(keypress); glutDisplayFunc(display); glutReshapeFunc(reshape); glutMainLoop(); return 0; } [/code]
  6. i am currently using lib3ds library loading a vehicle model from 3ds file after i draw in on the screen it appears that there r a lot of broken fragment and cannot be rendered properly.it seems that there r some far points draw onto a nearer surface but i`ve no idea what `s the problem really any answer would be appreciated. attached is my code. [code] #include <windows.h> #include <gl/gl.h> #include <gl/glu.h> #include <gl/glut.h> #include <lib3ds.h> #include <iostream> typedef float Lib3dsVector[3]; typedef float Lib3dsTexel[2]; using namespace std; Lib3dsFile* model; Lib3dsMesh** mesh; Lib3dsCamera** camera; Lib3dsFace* face; Lib3dsLight** light; Lib3dsMaterial** material; unsigned long total_face; void lightup() { glShadeModel(GL_SMOOTH); glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); glFrontFace(GL_CCW); glCullFace(GL_BACK); float gambient[]={0.2,0.2,0.2,1.0}; float lightpos[]={1.0,1.0,1.0,0.0}; float lambient[]={0.8,0.8,0.8,1.0}; float ldiffuse[]={1.0,1.0,1.0,1.0}; float lspecular[]={0.3,0.3,0.3,1.0}; glClearColor(0.0,0.0,0.0,0.0); glLightfv(GL_LIGHT0,GL_DIFFUSE,ldiffuse); glLightfv(GL_LIGHT0,GL_AMBIENT,lambient); glLightfv(GL_LIGHT0,GL_SPECULAR,lspecular); glLightfv(GL_LIGHT0,GL_POSITION,lightpos); glLightModelfv(GL_LIGHT_MODEL_AMBIENT,gambient); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); } void display() { glEnable(GL_DEPTH_TEST); glClearDepth(1.0); glDepthFunc(GL_LEQUAL); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glLoadIdentity(); gluLookAt(camera[0]->position[0]+1000,camera[0]->position[1],camera[0]->position[2],camera[0]->target[0],camera[0]->target[1],camera[0]->target[2],0.0,0.0,1.0); glColor3f(1.0,0.0,0.0); glPushMatrix(); lightup(); glTranslatef(0.0,0.0,-1000.0); long meshcount; for(meshcount=0;meshcount<model->nmeshes;meshcount++) { face=mesh[meshcount]->faces; Lib3dsVector* vertex_normal=new Lib3dsVector[mesh[meshcount]->nfaces*3]; Lib3dsVector* face_normal=new Lib3dsVector[mesh[meshcount]->nfaces]; lib3ds_mesh_calculate_vertex_normals(mesh[meshcount],vertex_normal); lib3ds_mesh_calculate_face_normals(mesh[meshcount],face_normal); for(long i=0;i<mesh[meshcount]->nfaces;i++) { glMaterialfv(GL_FRONT,GL_DIFFUSE,material[face[i].material]->diffuse); glMaterialfv(GL_FRONT,GL_AMBIENT,material[face[i].material]->ambient); glMaterialfv(GL_FRONT,GL_SPECULAR,material[face[i].material]->specular); glBegin(GL_TRIANGLES); glNormal3fv(face_normal[i]); glNormal3fv(vertex_normal[i*3]); glVertex3fv(mesh[meshcount]->vertices[face[i].index[0]]); glNormal3fv(vertex_normal[i*3+1]); glVertex3fv(mesh[meshcount]->vertices[face[i].index[1]]); glNormal3fv(vertex_normal[i*3+2]); glVertex3fv(mesh[meshcount]->vertices[face[i].index[2]]); glEnd(); } } glPopMatrix(); /* glPushMatrix(); glTranslatef(0.0,0.0,-2000.0); glColor3f(1.0,1.0,1.0); glBegin(GL_QUADS); glVertex3f(-10000.0f,-10000.0f,0.0f); glVertex3f(10000.0f,-10000.0f,0.0f); glVertex3f(10000.0f,10000.0f,0.0f); glVertex3f(-10000.0f,10000.0f,0.0f); glEnd(); glPopMatrix(); */ glutSwapBuffers(); } void keypress(unsigned char key,int x,int y) { switch(key) { case 27: exit(0); break; } } void reshape(int w,int h) { if(h==0) h=1; glViewport(0,0,w,h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(45.0,w/h,0.0,5.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } int main(int argc,char* argv[]) { glutInit(&argc,argv); model=lib3ds_file_open("vehicle.3DS"); if(model==NULL) cout<<"Error"<<endl; else cout<<model->nmaterials<<endl; mesh=model->meshes; material=model->materials; camera=model->cameras; light=model->lights; cout<<"Light Num:"<<model->nlights<<endl; glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BITS); glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE|GLUT_DEPTH); glutInitWindowSize(800,800); glutInitWindowPosition(100,100); glutCreateWindow("VC 2008 Glut"); //glutFullScreen(); glShadeModel(GL_FLAT); glutKeyboardFunc(keypress); glutDisplayFunc(display); glutReshapeFunc(reshape); glutMainLoop(); return 0; } [/code]
  7. [color=#1C2837][size=2]hi there is there any gl command manipulate face normals like glNormal*()?and how to use that command on syntax? thanx for reading and any answer would be appreciated. [/size][/color]
  8. hi there is there any gl command manipulate face normals like glNormal*()?and how to use that command on syntax? thanx for reading and answer would be appreciated.
  9. [font="Verdana, Arial, sans-serif"][size="2"]Hi there!I am currently using lib3ds draw models in my opengl program,after drawing vertex reading from the 3ds file,it appears a vehicle model on screen,but while i assign the light onto the surface i found there some fragment displayed incorrectly.some far pixel appeared on the nearer surface(matter fact i enable the depth buffer facility) that i can`t figure what`s wrong with the code attached is my code:[/size][/font] [font="Verdana, Arial, sans-serif"] [/font] [font="Verdana, Arial, sans-serif"][size="2"]#include <windows.h>[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"]#include <gl/gl.h>[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"]#include <gl/glu.h>[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"]#include <gl/glut.h>[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"]#include <lib3ds.h>[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"]#include <iostream>[/size][/font] [font="Verdana, Arial, sans-serif"] [/font] [font="Verdana, Arial, sans-serif"][size="2"]typedef float Lib3dsVector[3];[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"]typedef float Lib3dsTexel[2];[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"]using namespace std;[/size][/font] [font="Verdana, Arial, sans-serif"] [/font] [font="Verdana, Arial, sans-serif"][size="2"]Lib3dsFile* model;[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"]Lib3dsMesh** mesh;[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"]Lib3dsCamera** camera;[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"]Lib3dsFace* face;[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"]Lib3dsLight** light;[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"]Lib3dsMaterial** material;[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"][/size][/font][font="Verdana, Arial, sans-serif"] [/font] [font="Verdana, Arial, sans-serif"][size="2"]unsigned long total_face;[/size][/font] [font="Verdana, Arial, sans-serif"] [/font] [font="Verdana, Arial, sans-serif"][size="2"]void lightup()[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"]{[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] glShadeModel(GL_SMOOTH);[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] glEnable(GL_DEPTH_TEST);[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] glEnable(GL_CULL_FACE);[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] glFrontFace(GL_CCW);[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] float gambient[]={0.2,0.2,0.2,1.0};[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] float lightpos[]={1.0,1.0,1.0,0.0};[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] float lambient[]={1.0,1.0,1.0,1.0};[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] float ldiffuse[]={0.8,0.8,0.8,1.0};[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] float lspecular[]={0.3,0.3,0.3,1.0};[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] [/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] glLightfv(GL_LIGHT0,GL_DIFFUSE,ldiffuse);[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] glLightfv(GL_LIGHT0,GL_AMBIENT,lambient);[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] glLightfv(GL_LIGHT0,GL_SPECULAR,lspecular);[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] glLightfv(GL_LIGHT0,GL_POSITION,lightpos);[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] glLightModelfv(GL_LIGHT_MODEL_AMBIENT,gambient);[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] glEnable(GL_LIGHTING);[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] glEnable(GL_LIGHT0);[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"]}[/size][/font] [font="Verdana, Arial, sans-serif"] [/font] [font="Verdana, Arial, sans-serif"][size="2"]void getfaces()[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"]{[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] total_face=0;[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] for(long meshcount=0;meshcount<model->nmeshes;meshcount++)[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] total_face+=mesh[meshcount]->nfaces;[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"]}[/size][/font] [font="Verdana, Arial, sans-serif"] [/font] [font="Verdana, Arial, sans-serif"][size="2"]void display()[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"]{[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] glEnable(GL_DEPTH_TEST);[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] glClearDepth(1.0);[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] glDepthFunc(GL_LEQUAL);[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] [/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BITS);[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] glLoadIdentity(); [/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] gluLookAt(camera[0]->position[0]+1000,camera[0]->position[1],camera[0]->position[2],camera[0]->target[0],camera[0]->target[1],camera[0]->target[2],0.0,0.0,1.0);[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] [/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] glColor3f(1.0,0.0,0.0);[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] glPushMatrix();[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] lightup();[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] glScalef(0.5,0.5,0.5);[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] glTranslatef(0.0,0.0,-1000.0);[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] long meshcount;[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] for(meshcount=0;meshcount<model->nmeshes;meshcount++)[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] {[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] face=mesh[meshcount]->faces;[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] for(long i=0;i<mesh[meshcount]->nfaces;i++)[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] {[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] glMaterialfv(GL_FRONT,GL_DIFFUSE,material[face[i].material]->diffuse);[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] glMaterialfv(GL_FRONT,GL_AMBIENT,material[face[i].material]->ambient);[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] glMaterialfv(GL_FRONT,GL_SPECULAR,material[face[i].material]->specular);[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] glBegin(GL_TRIANGLES);[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] glVertex3fv(mesh[meshcount]->vertices[face[i].index[0]]);[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] glVertex3fv(mesh[meshcount]->vertices[face[i].index[1]]);[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] glVertex3fv(mesh[meshcount]->vertices[face[i].index[2]]);[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] glEnd();[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] }[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] }[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] [/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] glPopMatrix();[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"]/*[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] glPushMatrix();[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] glTranslatef(0.0,0.0,-2000.0);[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] glColor3f(1.0,1.0,1.0);[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] glBegin(GL_QUADS);[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] glVertex3f(-10000.0f,-10000.0f,0.0f);[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] glVertex3f(10000.0f,-10000.0f,0.0f);[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] glVertex3f(10000.0f,10000.0f,0.0f);[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] glVertex3f(-10000.0f,10000.0f,0.0f);[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] glEnd();[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] glPopMatrix();[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"]*/[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] [/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] glutSwapBuffers();[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"]}[/size][/font] [font="Verdana, Arial, sans-serif"] [/font] [font="Verdana, Arial, sans-serif"][size="2"]void keypress(unsigned char key,int x,int y)[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"]{[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] switch(key)[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] {[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] case 27:[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] exit(0);[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] break;[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] }[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"]}[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"]void reshape(int w,int h)[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"]{[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] if(h==0) h=1;[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] glViewport(0,0,w,h);[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] glMatrixMode(GL_PROJECTION);[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] glLoadIdentity();[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] gluPerspective(45.0,w/h,0.0,1000.0);[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] glMatrixMode(GL_MODELVIEW);[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] glLoadIdentity();[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"]}[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"]int main(int argc,char* argv[])[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"]{[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] [/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] glutInit(&argc,argv);[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] model=lib3ds_file_open("vehicle.3DS");[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] if(model==NULL) cout<<"Error"<<endl; else cout<<model->nmaterials<<endl;[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] mesh=model->meshes;[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] material=model->materials;[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] camera=model->cameras;[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] light=model->lights;[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] cout<<"Light Num:"<<model->nlights<<endl;[/size][/font] [font="Verdana, Arial, sans-serif"] [/font] [font="Verdana, Arial, sans-serif"] [/font] [font="Verdana, Arial, sans-serif"] [/font] [font="Verdana, Arial, sans-serif"][size="2"] glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE|GLUT_DEPTH);[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] glutInitWindowSize(800,800);[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] glutInitWindowPosition(100,100);[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] glutCreateWindow("VC 2008 Glut");[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] //glutFullScreen();[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] glShadeModel(GL_FLAT);[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] glutKeyboardFunc(keypress);[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] glutDisplayFunc(display);[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] glutReshapeFunc(reshape);[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] glutMainLoop();[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"] return 0;[/size][/font] [font="Verdana, Arial, sans-serif"][size="2"]}[/size][/font]