• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.

jerrylin88

Members
  • 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]