简体   繁体   English

OpenGL ES 1.1 for iOS中灯光线的奇怪行为

[英]Strange behaviour with lighting lines in OpenGL ES 1.1 for iOS

I am writing a game with 3D graphics for the iPad. 我正在为iPad编写带有3D图形的游戏。 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. 起初,我以为我的glColor4f函数设置为绘制的最新敌人的颜色,但是我确实将颜色设置为白色,此外-它在关闭照明的情况下绘制为白色。

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. glColor4f用于设置关闭颜色。 When lighting is turned on, OpenGL uses the material properties of the object to set the colour. 启用照明后,OpenGL使用对象的材质属性来设置颜色。 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. 当我绘制线条时,材质属性设置为敌人的材质属性,我要做的就是为线条设置此设置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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