public static void render_model_surfaces(Matrix4 leftViewMat, Matrix4 leftProjMat, Viewport leftViewport, float time) { int i; // Setup State shader_gl shader = modelSurfaces[0].shader; glshading.setShader(shader); stage_gl stage = shader.stages[0]; shader_prog_t shaderProgram = glshading.setShaderStage(shader, stage, time); BspOpenglBinders.BindShaderAttribs(shaderProgram); GL.ActiveTexture(TextureUnit.Texture0); BspOpenglBinders.BindShaderMatrix(shaderProgram, leftViewMat, leftProjMat); setViewport(leftViewport); for (i = 0; i < modelSurfaces.Count; ++i) { shader_p surface = modelSurfaces[i]; stage_gl stage2 = surface.shader.stages[0]; GL.BindTexture(TextureTarget.Texture2D, stage2.texture); GL.DrawElements(BeginMode.Triangles, surface.elementCount, DrawElementsType.UnsignedShort, surface.indexOffset); } }
public static void BindShaderAttribs(shader_prog_t shader) { // Setup vertex attributes GL.EnableVertexAttribArray(shader.attrib["position"]); GL.VertexAttribPointer(shader.attrib["position"], 3, VertexAttribPointerType.Float, false, Config.q3bsp_vertex_stride, 0); if (shader.attrib.ContainsKey("texCoord")) { GL.EnableVertexAttribArray(shader.attrib["texCoord"]); GL.VertexAttribPointer(shader.attrib["texCoord"], 2, VertexAttribPointerType.Float, false, Config.q3bsp_vertex_stride, 3 * sizeof(float)); } if (shader.attrib.ContainsKey("lightCoord")) { GL.EnableVertexAttribArray(shader.attrib["lightCoord"]); GL.VertexAttribPointer(shader.attrib["lightCoord"], 2, VertexAttribPointerType.Float, false, Config.q3bsp_vertex_stride, 5 * sizeof(float)); } if (shader.attrib.ContainsKey("normal")) { GL.EnableVertexAttribArray(shader.attrib["normal"]); GL.VertexAttribPointer(shader.attrib["normal"], 3, VertexAttribPointerType.Float, false, Config.q3bsp_vertex_stride, 7 * sizeof(float)); } if (shader.attrib.ContainsKey("color")) { GL.EnableVertexAttribArray(shader.attrib["color"]); GL.VertexAttribPointer(shader.attrib["color"], 4, VertexAttribPointerType.Float, false, Config.q3bsp_vertex_stride, 10 * sizeof(float)); } }
public static void render_default_surfaces(Matrix4 leftViewMat, Matrix4 leftProjMat, Viewport leftViewport, float time) { int i; // Map Geometry buffers GL.BindBuffer(BufferTarget.ElementArrayBuffer, indexBuffer); GL.BindBuffer(BufferTarget.ArrayBuffer, vertexBuffer); // Default shader surfaces (can bind shader once and draw all of them very quickly) if (defaultSurfaces.Count > 0 || unshadedSurfaces.Count > 0) { // Setup State shader_gl shader = glshading.defaultShader; glshading.setShader(shader); stage_gl stage = shader.stages[0]; shader_prog_t shaderProgram = glshading.setShaderStage(shader, stage, time); BspOpenglBinders.BindShaderAttribs(shaderProgram); GL.ActiveTexture(TextureUnit.Texture0); GL.BindTexture(TextureTarget.Texture2D, glshading.defaultTexture); BspOpenglBinders.BindShaderMatrix(shaderProgram, leftViewMat, leftProjMat); setViewport(leftViewport); for (i = 0; i < unshadedSurfaces.Count; ++i) { shader_p surface = unshadedSurfaces[i]; GL.DrawElements(BeginMode.Triangles, surface.elementCount, DrawElementsType.UnsignedShort, surface.indexOffset); } for (i = 0; i < defaultSurfaces.Count; ++i) { shader_p surface = defaultSurfaces[i]; //stage_gl stage2 = surface.shader.stages[0]; foreach (stage_gl stage2 in surface.shader.stages) { GL.ActiveTexture(TextureUnit.Texture0); GL.BindTexture(TextureTarget.Texture2D, stage2.texture); GL.DrawElements(BeginMode.Triangles, surface.elementCount, DrawElementsType.UnsignedShort, surface.indexOffset); } } } }
// Draw the map public static void BindShaderMatrix(shader_prog_t shader, Matrix4 modelViewMat, Matrix4 perspective) { Matrix4 model; SceneCamera cam; Matrix4 cameraTransl; Matrix4 cameraRot; Matrix4 MV; model = Matrix4.Identity; cam = AlethaApplication.camera; cameraTransl = Matrix4.CreateTranslation(-cam.Position - new Vector3(0, 0, Config.playerHeight)); cameraRot = Matrix4.CreateFromQuaternion(cam.Orientation); MV = (model * cameraTransl) * cameraRot; GL.UniformMatrix4(shader.uniform["modelViewMat"], false, ref MV); GL.UniformMatrix4(shader.uniform["projectionMat"], false, ref perspective); }