简体   繁体   中英

Strange behaviour with lighting lines in OpenGL ES 1.1 for iOS

I am writing a game with 3D graphics for the iPad. I use a lot of wire frame surfaces drawn with lines.

Up until recently, I've always turned off lighting when I draw my lines; I reasoned that lines don't have normals so lighting wouldn't work. Just for fun, I tried turning on lighting to draw my lines just to see what would happen and I got some surprising results.

The lines are drawn in white, and appear white with lighting turned off, however they turn colored when lighting is turned on. Specifically, the lines change to the color of the last enemy to come onto the screen. I also get a fading to white effect which I believe has something to do with the position of the light source.

At first I thought that I my glColor4f function was set to the color of the most recent enemy that was drawn, but I definitely have the color set to white, and besides- it draws as white with lighting turned off.

Here's the code that draws the lines:

-(void)drawWireFrameWithData:(GLSurfaceData*)bufferData
{
    glPushMatrix();

    glDisableClientState(GL_NORMAL_ARRAY);
    //glDisable(GL_LIGHTING);

    glTranslatef(self.centrex, self.centrey, self.centrez);

    glColor4f(1.0f, 1.0f, 1.0f, 1.0f);

    glBindBuffer(GL_ARRAY_BUFFER, bufferData.vertexBuffer);
    glVertexPointer(3, GL_FLOAT, 3 * sizeof(GLfloat), 0);

    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferData.lineIndexBuffer);

    glDrawElements(GL_LINES, bufferData.lineIndexCount, GL_UNSIGNED_SHORT, 0);

    glEnableClientState(GL_NORMAL_ARRAY);
    //glEnable(GL_LIGHTING);

    glPopMatrix();
}

ok, I've worked it out.

glColor4f is used to set the colour is turned off. When lighting is turned on, OpenGL uses the material properties of the object to set the colour. The material properties were set the the material properties of the enemies when I drew the lines, all i need to do was set this for the lines.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM