func drawSingleLight(light *obj7.LightInfo, size float32, distance float32, lights *goplanemp.LightStatus) { // Finally we can draw our lights switch light.LightType { case obj7.LightType_RedNavigation: if lights.NavLights { if redNavLightDl == 0 { redNavLightDl = gl.GenLists(1) gl.NewList(redNavLightDl, gl.COMPILE) gl.Begin(gl.QUADS) gl.Color4f(light.RGB_Float[0], light.RGB_Float[1], light.RGB_Float[2], light.RGB_Float[3]) gl.TexCoord2f(0, 0.5) gl.Vertex2f(-(size / 2.0), -(size / 2.0)) gl.TexCoord2f(0, 1.0) gl.Vertex2f(-(size / 2.0), (size / 2.0)) gl.TexCoord2f(0.25, 1.0) gl.Vertex2f((size / 2.0), (size / 2.0)) gl.TexCoord2f(0.25, 0.5) gl.Vertex2f((size / 2.0), -(size / 2.0)) gl.End() gl.EndList() } gl.CallList(redNavLightDl) } case obj7.LightType_GreenNavigation: if lights.NavLights { if greenNavLightDl == 0 { greenNavLightDl = gl.GenLists(1) gl.NewList(greenNavLightDl, gl.COMPILE) gl.Begin(gl.QUADS) gl.Color4f(light.RGB_Float[0], light.RGB_Float[1], light.RGB_Float[2], light.RGB_Float[3]) gl.TexCoord2f(0, 0.5) gl.Vertex2f(-(size / 2.0), -(size / 2.0)) gl.TexCoord2f(0, 1.0) gl.Vertex2f(-(size / 2.0), (size / 2.0)) gl.TexCoord2f(0.25, 1.0) gl.Vertex2f((size / 2.0), (size / 2.0)) gl.TexCoord2f(0.25, 0.5) gl.Vertex2f((size / 2.0), -(size / 2.0)) gl.End() gl.EndList() } gl.CallList(greenNavLightDl) } case obj7.LightType_Beacon: if lights.BeaconLights { if beaconLightDl == 0 { beaconLightDl = gl.GenLists(1) gl.NewList(beaconLightDl, gl.COMPILE) gl.Begin(gl.QUADS) gl.Color4f(light.RGB_Float[0], light.RGB_Float[1], light.RGB_Float[2], light.RGB_Float[3]) gl.TexCoord2f(0, 0.5) gl.Vertex2f(-(size / 2.0), -(size / 2.0)) gl.TexCoord2f(0, 1.0) gl.Vertex2f(-(size / 2.0), (size / 2.0)) gl.TexCoord2f(0.25, 1.0) gl.Vertex2f((size / 2.0), (size / 2.0)) gl.TexCoord2f(0.25, 0.5) gl.Vertex2f((size / 2.0), -(size / 2.0)) gl.End() gl.EndList() } gl.CallList(beaconLightDl) } case obj7.LightType_Strobe: if lights.StrobeLights { if strobeLightDl == 0 { strobeLightDl = gl.GenLists(1) gl.NewList(strobeLightDl, gl.COMPILE) gl.Begin(gl.QUADS) gl.Color4f(light.RGB_Float[0], light.RGB_Float[1], light.RGB_Float[2], light.RGB_Float[3]) gl.TexCoord2f(0.25, 0.0) gl.Vertex2f(-(size / 1.5), -(size / 1.5)) gl.TexCoord2f(0.25, 0.5) gl.Vertex2f(-(size / 1.5), (size / 1.5)) gl.TexCoord2f(0.50, 0.5) gl.Vertex2f((size / 1.5), (size / 1.5)) gl.TexCoord2f(0.50, 0.0) gl.Vertex2f((size / 1.5), -(size / 1.5)) gl.End() gl.EndList() } gl.CallList(strobeLightDl) } case obj7.LightType_Landing: if lights.LandingLights { // BEN SEZ: modulate the _alpha to make this dark, not // the light color. Otherwise if the sky is fairly light the light // will be darker than the sky, which looks f---ed during the day. color := light.RGB_Float if color[0] < 0.0 { color[0] = 0.0 } if color[0] < 0.0 { color[0] = 0.0 } if color[0] < 0.0 { color[0] = 0.0 } color[3] *= (distance * -0.05882) + 1.1764 gl.Color4f(color[0], color[1], color[2], color[3]) if landingLightDl == 0 { landingLightDl = gl.GenLists(1) gl.NewList(landingLightDl, gl.COMPILE) gl.Begin(gl.QUADS) gl.TexCoord2f(0.25, 0.0) gl.Vertex2f(-(size / 2.0), -(size / 2.0)) gl.TexCoord2f(0.25, 0.5) gl.Vertex2f(-(size / 2.0), (size / 2.0)) gl.TexCoord2f(0.50, 0.5) gl.Vertex2f((size / 2.0), (size / 2.0)) gl.TexCoord2f(0.50, 0.0) gl.Vertex2f((size / 2.0), -(size / 2.0)) gl.End() gl.EndList() } gl.CallList(landingLightDl) } case obj7.LightType_Taxi: if lights.LandingLights { // BEN SEZ: modulate the _alpha to make this dark, not // the light color. Otherwise if the sky is fairly light the light // will be darker than the sky, which looks f---ed during the day. color := light.RGB_Float if color[0] < 0.0 { color[0] = 0.0 } if color[0] < 0.0 { color[0] = 0.0 } if color[0] < 0.0 { color[0] = 0.0 } color[3] *= (distance * -0.05882) + 1.1764 gl.Color4f(color[0], color[1], color[2], color[3]) if taxiLightDl == 0 { taxiLightDl = gl.GenLists(1) gl.NewList(taxiLightDl, gl.COMPILE) gl.Begin(gl.QUADS) gl.TexCoord2f(0.25, 0.0) gl.Vertex2f(-(size / 2.0), -(size / 2.0)) gl.TexCoord2f(0.25, 0.5) gl.Vertex2f(-(size / 2.0), (size / 2.0)) gl.TexCoord2f(0.50, 0.5) gl.Vertex2f((size / 2.0), (size / 2.0)) gl.TexCoord2f(0.50, 0.0) gl.Vertex2f((size / 2.0), -(size / 2.0)) gl.End() gl.EndList() } gl.CallList(taxiLightDl) } default: if lights.NavLights { gl.Color4f(light.RGB_Float[0], light.RGB_Float[1], light.RGB_Float[2], light.RGB_Float[3]) if otherLightDl == 0 { otherLightDl = gl.GenLists(1) gl.NewList(otherLightDl, gl.COMPILE) gl.Begin(gl.QUADS) gl.TexCoord2f(0, 0.5) gl.Vertex2f(-(size / 2.0), -(size / 2.0)) gl.TexCoord2f(0, 1.0) gl.Vertex2f(-(size / 2.0), (size / 2.0)) gl.TexCoord2f(0.25, 1.0) gl.Vertex2f((size / 2.0), (size / 2.0)) gl.TexCoord2f(0.25, 0.5) gl.Vertex2f((size / 2.0), -(size / 2.0)) gl.End() gl.EndList() } gl.CallList(otherLightDl) } } }
func (self *DefaultRenderer) drawObj7Model(renderData *planeRenderData) { if renderData.plane.CslAircraft.ObjInfo == nil { //es wurde kein Objekt geladen --> nichts zeichnen return } // Find out what LOD we need to draw lodInfo := calculateLOD(renderData.plane.CslAircraft.ObjInfo, renderData.dist) if lodInfo == nil { //es wurde kein gutes LOD gefunden --> nichts zeichnen return } //PointPool ist leer if lodInfo.PointPool.Size() == 0 && lodInfo.Dl == 0 { return } gl.MatrixMode(gl.MODELVIEW) gl.PushMatrix() gl.Translatef(renderData.x, renderData.y, renderData.z) gl.Rotatef(renderData.plane.PositionData.Heading, 0.0, -1.0, 0.0) gl.Rotatef(renderData.plane.PositionData.Pitch, 1.0, 0.0, 0.0) gl.Rotatef(renderData.plane.PositionData.Roll, 0.0, 0.0, -1.0) textureId, litTextureId := renderData.plane.TextureNum, renderData.plane.LitTextureNum useNight := texture.TextureManagerInstance.UseLitTexture() && litTextureId != -1 texUnits := 1 if useNight { texUnits++ } else { litTextureId = -1 } graphics.SetGraphicsState(true, texUnits, true, true, true, true, true) graphics.BindTexture2d(textureId, 0) if litTextureId != -1 { graphics.BindTexture2d(litTextureId, 1) } gl.TexEnvi(gl.TEXTURE_ENV, gl.TEXTURE_ENV_MODE, gl.MODULATE) if litTextureId != -1 { gl.ActiveTextureARB(gl.TEXTURE1) gl.TexEnvi(gl.TEXTURE_ENV, gl.TEXTURE_ENV_MODE, gl.ADD) gl.ActiveTextureARB(gl.TEXTURE0) } if lodInfo.Dl == 0 { lodInfo.Dl = gl.GenLists(1) var xpBuffer int32 // See if the card even has VBO. If it does, save xplane's pointer // and bind to 0 for us. gl.GetIntegerv(gl.ARRAY_BUFFER_BINDING_ARB, &xpBuffer) gl.BindBufferARB(gl.ARRAY_BUFFER_ARB, 0) // Save XPlanes OpenGL state gl.PushClientAttrib(gl.CLIENT_ALL_ATTRIB_BITS) // Setup OpenGL pointers to our pool lodInfo.PointPool.PreparePoolToDraw() // Enable vertex data sucking gl.EnableClientState(gl.VERTEX_ARRAY) // Enable normal array sucking gl.EnableClientState(gl.NORMAL_ARRAY) // Enable texture coordinate data sucking gl.ClientActiveTextureARB(gl.TEXTURE1) gl.EnableClientState(gl.TEXTURE_COORD_ARRAY) gl.ClientActiveTextureARB(gl.TEXTURE0) gl.EnableClientState(gl.TEXTURE_COORD_ARRAY) // Disable colors - maybe x-plane left it around. gl.DisableClientState(gl.COLOR_ARRAY) gl.NewList(lodInfo.Dl, gl.COMPILE) // Kick OpenGL and draw baby! gl.DrawElements(gl.TRIANGLES, int32(len(lodInfo.TriangleList)), gl.UNSIGNED_INT, unsafe.Pointer(&(lodInfo.TriangleList[0]))) gl.EndList() // Disable vertex data sucking gl.DisableClientState(gl.VERTEX_ARRAY) // Disable texture coordinate data sucking gl.DisableClientState(gl.TEXTURE_COORD_ARRAY) // Disable normal array sucking gl.DisableClientState(gl.NORMAL_ARRAY) // Restore Xplane's OpenGL State gl.PopClientAttrib() // If we bound before, we need to put xplane back where it was gl.BindBufferARB(gl.ARRAY_BUFFER_ARB, uint32(xpBuffer)) lodInfo.TriangleList = make([]int32, 0) lodInfo.PointPool.Purge() } gl.CallList(lodInfo.Dl) gl.PopMatrix() }