private bool DrawToTexture(ShaderController shader, int textureId) { //GL.BindTexture(TextureTarget.Texture2D, oldTextureId); DrawQuad(1f, 1f, 1f, 1f); GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); GL.Enable(EnableCap.Blend); shader.Begin(); GL.ActiveTexture(TextureUnit.Texture0); GL.BindTexture(TextureTarget.Texture2D, headTextureId); shader.UpdateUniform("u_Texture", 0); GL.ActiveTexture(TextureUnit.Texture1); GL.BindTexture(TextureTarget.Texture2D, textureId); shader.UpdateUniform("u_BaseTexture", 1); shader.UpdateUniform("u_BlendDirectionX", HeadMesh.HeadAngle >= 0 ? 1.0f : -1.0f); HeadMesh.DrawToTexture(textureId); shader.End(); GL.Disable(EnableCap.Blend); return(true); }
private void DrawHead() { idleShader.UpdateUniform("u_LightDirection", Vector3.Normalize(camera.Position)); var worldMatrix = HeadMesh.RotationMatrix; idleShader.UpdateUniform("u_World", worldMatrix); idleShader.UpdateUniform("u_WorldView", worldMatrix * camera.ViewMatrix); idleShader.UpdateUniform("u_ViewProjection", camera.ViewMatrix * camera.ProjectMatrix); HeadMesh.Draw(drawAABB); }
public void Draw(ShaderController shader) { if (!IsVisible) { return; } var useTextures = Vector3.Zero; var useTexture = ProgramCore.MainForm.ctrlRenderControl.UseTexture; GL.ActiveTexture(TextureUnit.Texture1); GL.BindTexture(TextureTarget.Texture2D, Material.TransparentTexture); shader.UpdateUniform("u_TransparentMap", 1); useTextures.Y = Material.TransparentTexture; //shader.UpdateUniform("u_UseTransparent", (float)Material.TransparentTexture); GL.ActiveTexture(TextureUnit.Texture0); GL.BindTexture(TextureTarget.Texture2D, Material.Texture); shader.UpdateUniform("u_Texture", 0); if (useTexture) // заказ старичка. что типа проги не отрабатывают текстуры (которые 3д печать) и надо со всего убрать { shader.UpdateUniform("u_Color", Material.DiffuseColor); useTextures.X = Material.Texture; } //shader.UpdateUniform("u_UseTexture", useTexture ? (float)Material.Texture : 0); shader.UpdateUniform("u_UseTexture", useTextures); GL.EnableClientState(ArrayCap.VertexArray); GL.EnableClientState(ArrayCap.NormalArray); GL.EnableClientState(ArrayCap.TextureCoordArray); GL.EnableClientState(ArrayCap.ColorArray); GL.BindBuffer(BufferTarget.ArrayBuffer, VertexBuffer); GL.BindBuffer(BufferTarget.ElementArrayBuffer, IndexBuffer); GL.VertexPointer(3, VertexPointerType.Float, Vertex.Stride, new IntPtr(0)); GL.NormalPointer(NormalPointerType.Float, Vertex.Stride, new IntPtr(Vector3.SizeInBytes)); GL.TexCoordPointer(2, TexCoordPointerType.Float, Vertex.Stride, new IntPtr(2 * Vector3.SizeInBytes)); GL.ColorPointer(4, ColorPointerType.Float, Vertex.Stride, new IntPtr(2 * Vector3.SizeInBytes + Vector2.SizeInBytes)); GL.DrawRangeElements(PrimitiveType.Triangles, 0, NumIndices, NumIndices, DrawElementsType.UnsignedInt, new IntPtr(0)); GL.BindBuffer(BufferTarget.ArrayBuffer, 0); GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0); GL.DisableClientState(ArrayCap.VertexArray); GL.DisableClientState(ArrayCap.NormalArray); GL.DisableClientState(ArrayCap.TextureCoordArray); GL.DisableClientState(ArrayCap.ColorArray); }
public void Draw(ShaderController shader) { if (!IsVisible) { return; } GL.ActiveTexture(TextureUnit.Texture1); GL.BindTexture(TextureTarget.Texture2D, Material.TransparentTexture); shader.UpdateUniform("u_TransparentMap", 1); shader.UpdateUniform("u_UseTransparent", (float)Material.TransparentTexture); GL.ActiveTexture(TextureUnit.Texture0); GL.BindTexture(TextureTarget.Texture2D, Material.Texture); shader.UpdateUniform("u_Texture", 0); shader.UpdateUniform("u_Color", Material.DiffuseColor); shader.UpdateUniform("u_UseTexture", (float)Material.Texture); GL.EnableClientState(ArrayCap.VertexArray); GL.EnableClientState(ArrayCap.NormalArray); GL.EnableClientState(ArrayCap.TextureCoordArray); GL.EnableClientState(ArrayCap.ColorArray); GL.BindBuffer(BufferTarget.ArrayBuffer, VertexBuffer); GL.BindBuffer(BufferTarget.ElementArrayBuffer, IndexBuffer); GL.VertexPointer(3, VertexPointerType.Float, Vertex.Stride, new IntPtr(0)); GL.NormalPointer(NormalPointerType.Float, Vertex.Stride, new IntPtr(Vector3.SizeInBytes)); GL.TexCoordPointer(2, TexCoordPointerType.Float, Vertex.Stride, new IntPtr(2 * Vector3.SizeInBytes)); GL.ColorPointer(4, ColorPointerType.Float, Vertex.Stride, new IntPtr(2 * Vector3.SizeInBytes + Vector2.SizeInBytes)); GL.DrawRangeElements(PrimitiveType.Triangles, 0, NumIndices, NumIndices, DrawElementsType.UnsignedInt, new IntPtr(0)); GL.BindBuffer(BufferTarget.ArrayBuffer, 0); GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0); GL.DisableClientState(ArrayCap.VertexArray); GL.DisableClientState(ArrayCap.NormalArray); GL.DisableClientState(ArrayCap.TextureCoordArray); GL.DisableClientState(ArrayCap.ColorArray); }