English 中文(简体)
openGL rotating with Lighting problem
原标题:

I want to draw car in my world. but i have problem with lighting when my car rotate ,it seems light position change when car is rotating; but when i draw simple cube with glut function it work correctly.

void mydisplay(){

glLoadIdentity()
glDisable(GL_LIGHT0);
glColorMaterial ( GL_FRONT_AND_BACK, GL_DIFFUSE) ;
glColor3f(1.0,1.0,1.0);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
p2[0]=50.0;
p2[1]=3.0;
p2[2]=0.0;
glLightfv(GL_LIGHT0,GL_POSITION,p2);
glEnable(GL_LIGHT0);
gluLookAt(50.0,3.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0);
glPushMatrix();
glRotatef(tet,0.0,1.0,0.0);
glutSolidCube(20);
glPopMatrix();
tet+=3.141592653/4;
glutSwapBuffers();

}

when glutSolidCube(20); change to my drawing code,it work in bad way my code:

void Drawing(){

glEnableClientState(GL_VERTEX_ARRAY);
GLfloat CubeVertex[]={  -20.0,0.0,10.0,///////\/////////////////
                -20.0,0.0,-10.0,
                -20.0,3.0,-10.0,
                -20.0,3.0,10.0,    ///BIG   CUBE
            20.0,0.0,10.0,
            20.0,0.0,-10.0,
            20.0,3.0,-10.0,
            20.0,3.0,10.0,///////////////////////////
            -10.0,3.0,10.0,
            -10.0,3.0,-10.0,
            -10.0,5.0,-10.0,
            -10.0,5.0,10.0,     //SMALL  CUBE
            10.0,3.0,10.0, 
            10.0,3.0,-10.0,
            10.0,5.0,-10.0,
            10.0,5.0,10.0,/////////////////////////
            -100.0,-2.4,100.0,
            -100.0,-2.4,-100.0,      //FLOOR
            100.0,-2.4,100.0,
            100.0,-2.4,-100.0
            };///////////////////////\///
GLubyte big_back[]={0,3,2,1};
GLubyte big_front[]={4,5,6,7};
GLubyte big_left[]={4,0,3,7};
GLubyte big_right[]={1,2,6,5};
GLubyte big_up[]={2,3,7,6};
GLubyte big_down[]={0,1,5,4};
GLubyte small_back[]={9,10,11,8};
GLubyte small_front[]={12,13,14,15};
GLubyte small_left[]={8,11,15,12};
GLubyte small_right[]={9,10,14,13};
GLubyte small_up[]={10,11,15,14};
GLubyte floor[]={16,17,19,18};
GLsizei count[]={4,4,4,4,4,4,4,4,4,4,4,4};
GLvoid* indices[12]={big_back,big_front,big_left,big_right,big_up,big_down,small_back,small_front,small_left,small_right,small_up,floor};
glVertexPointer(3,GL_FLOAT,0,CubeVertex);
for(int i=0;i<12;i++){//////////////////glMultiDrawElement////////////////
if(count[i]>0)
    glDrawElements(GL_QUADS,count[i],GL_UNSIGNED_BYTE,indices[i]);
}//////////////////////////////glMultiDrawElements//////////////////////

}

Thank you.

问题回答

You can find the answer here: http://www.opengl.org/resources/faq/technical/lights.htm section: 18.050 How can I make my light move or not move and control the light position?





相关问题
OpenGL 3D Selection

I am trying to create a 3D robot that should perform certain actions when certain body parts are clicked. I have successfully (sort of) implemented picking in that if you click on any x-plane part, it ...

CVDisplayLink instead of NSTimer

I have started to implement cvDisplayLink to drive the render loop instead of nstimer, as detailed in this technical note https://developer.apple.com/library/archive/qa/qa1385/_index.html Is it ...

Can the iPhone simulator handle PVR textures?

I have a really weird problem with PVR textures on the iPhone simulator- the framerate falls through the floor on the iPhone simulator, but on the iPhone itself it works just fine. Has anyone had any ...

Calculate fps (frames per second) for iphone app

I am using an opengl es iphone application. What is the most accurate way to calculate the frames per second of my application for performance tuning?

Java - Zoom / 3D Data Visualization Libraries

What are the best libraries/frameworks for doing 3D and/or Zoom interfaces in Java? I d like to be able to do some prototyping of creating new types of interfaces for navigating within data and ...

FLTK in Cygwin using Eclipse (Linking errors)

I have this assignment due that requires the usage of FLTK. The code is given to us and it should compile straight off of the bat, but I am having linking errors and do not know which other libraries ...

热门标签