private void RenderVoxels(Vector3 cameraPosition, float[] cam) { _voxelShader.Activate(); GL.ActiveTexture(TextureUnit.Texture0); _materialTextureArray.Activate(); GL.Uniform1(_voxelShader.GetResourceLocation(ShaderResourceType.Uniform, "texArray"), TextureUnit.Texture0 - TextureUnit.Texture0); GL.UniformMatrix4(_voxelShader.GetResourceLocation(ShaderResourceType.Uniform, "camera"), 1, false, cam); GL.Uniform3(_voxelShader.GetResourceLocation(ShaderResourceType.Uniform, "cameraPosition"), cameraPosition.ToOpenTK()); GL.Uniform3(_voxelShader.GetResourceLocation(ShaderResourceType.Uniform, "ambientLightColor"), new OpenTK.Vector3(0.1f, 0.1f, 0.1f)); GL.Uniform3(_voxelShader.GetResourceLocation(ShaderResourceType.Uniform, "lightDirection"), new OpenTK.Vector3(1f, 1.5f, -2f).Normalized()); GL.Uniform3(_voxelShader.GetResourceLocation(ShaderResourceType.Uniform, "lightColor"), new OpenTK.Vector3(1f, 1f, 1f)); foreach (var valuePair in _chunkGeometrys) { _amountBuffers[valuePair.Key].ActivateBind(3); _idBuffers[valuePair.Key].ActivateBind(4); if (valuePair.Value.IDLength > 0) { valuePair.Value.Draw(); } _idBuffers[valuePair.Key].Deactivate(); _amountBuffers[valuePair.Key].Deactivate(); } _materialTextureArray.Deactivate(); _voxelShader.Deactivate(); }
/// <summary> /// Initializes a new instance of the <see cref="FBO"/> class. /// </summary> /// <param name="size"></param> /// <exception cref="FBOException"> /// Given texture is null or texture dimensions do not match primary texture /// </exception> public CubeMapFBO(int size) { _size = size; // Create an FBO object GL.GenFramebuffers(1, out _fboHandle); Texture = new Texture(TextureTarget.TextureCubeMap); //Initialize empty textures in texture Texture.Activate(); for (int i = 0; i < 6; i++) { GL.TexImage2D(TextureTarget.TextureCubeMapPositiveX + i, 0, PixelInternalFormat.Rgba32f, size, size, 0, PixelFormat.Rgba, PixelType.Float, IntPtr.Zero); } Texture.Deactivate(); //Bind texture to framebuffer Activate(); for (int i = 0; i < 6; i++) { GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, FramebufferAttachment.ColorAttachment0 + i, TextureTarget.TextureCubeMapPositiveX + i, Texture.ID, 0); } string status = GetStatusMessage(); Deactivate(); if (!string.IsNullOrEmpty(status)) { throw new FBOException(status); } //Attach depth Activate(); _depth = new RenderBuffer(RenderbufferStorage.DepthComponent32, _size, _size); _depth.Attach(FramebufferAttachment.DepthAttachment); status = GetStatusMessage(); Deactivate(); if (!string.IsNullOrEmpty(status)) { throw new FBOException(status); } int linMin = (int)TextureMinFilter.LinearMipmapLinear; int linMag = (int)TextureMagFilter.Linear; int clampToEdge = (int)TextureWrapMode.ClampToEdge; Texture.Activate(); GL.TexParameterI(TextureTarget.TextureCubeMap, TextureParameterName.TextureMinFilter, ref linMin); GL.TexParameterI(TextureTarget.TextureCubeMap, TextureParameterName.TextureMagFilter, ref linMag); GL.TexParameterI(TextureTarget.TextureCubeMap, TextureParameterName.TextureWrapS, ref clampToEdge); GL.TexParameterI(TextureTarget.TextureCubeMap, TextureParameterName.TextureWrapT, ref clampToEdge); GL.TexParameterI(TextureTarget.TextureCubeMap, TextureParameterName.TextureWrapR, ref clampToEdge); Texture.Deactivate(); }
private void Render() { bool doPostProcessing = !Keyboard.GetState()[Key.Space]; if (doPostProcessing) { postProcessing.Start(); } GL.Color3(Color.White); //draw background texBackground.Activate(); background.DrawTexturedRect(Box2D.BOX01); texBackground.Deactivate(); //draw player texBird.Activate(); bird.DrawTexturedRect(Box2D.BOX01); texBird.Deactivate(); if (doPostProcessing) { postProcessing.EndAndApply((float)globalTime.Elapsed.TotalSeconds); } }
public void Render() { GL.Disable(EnableCap.CullFace); _shader.Activate(); _texture.Activate(); _geometry.Draw(); _texture.Deactivate(); _shader.Deactivate(); GL.Enable(EnableCap.CullFace); }
private static void DrawTexturedRect(Box2D rect, Texture tex, Box2D texCoords) { tex.Activate(); GL.Begin(PrimitiveType.Quads); GL.TexCoord2(texCoords.X, texCoords.Y); GL.Vertex2(rect.X, rect.Y); GL.TexCoord2(texCoords.MaxX, texCoords.Y); GL.Vertex2(rect.MaxX, rect.Y); GL.TexCoord2(texCoords.MaxX, texCoords.MaxY); GL.Vertex2(rect.MaxX, rect.MaxY); GL.TexCoord2(texCoords.X, texCoords.MaxY); GL.Vertex2(rect.X, rect.MaxY); GL.End(); tex.Deactivate(); }
private static void DrawTexturedRect(Box2D Rectangle, Texture tex) { GL.Color3(Color.White); tex.Activate(); GL.Begin(PrimitiveType.Quads); GL.TexCoord2(0.0f, 0.0f); GL.Vertex2(Rectangle.X, Rectangle.Y); GL.TexCoord2(1.0f, 0.0f); GL.Vertex2(Rectangle.MaxX, Rectangle.Y); GL.TexCoord2(1.0f, 1.0f); GL.Vertex2(Rectangle.MaxX, Rectangle.MaxY); GL.TexCoord2(0.0f, 1.0f); GL.Vertex2(Rectangle.X, Rectangle.MaxY); GL.End(); tex.Deactivate(); }
static void DrawSprite(float x, float y, Texture tex, float radius = 0.5f, float repeat = 1.0f) { tex.Activate(); GL.Color3(Color.White); GL.Begin(PrimitiveType.Quads); GL.TexCoord2(0.0f, 0.0f); GL.Vertex2(x - radius, y - radius); GL.TexCoord2(repeat, 0.0f); GL.Vertex2(x + radius, y - radius); GL.TexCoord2(repeat, repeat); GL.Vertex2(x + radius, y + radius); GL.TexCoord2(0.0f, repeat); GL.Vertex2(x - radius, y + radius); GL.End(); tex.Deactivate(); }
private static void DrawTexturedRect(Box2D Rect, Texture tex) { //the texture has to be enabled before use tex.Activate(); GL.Begin(PrimitiveType.Quads); //when using textures we have to set a texture coordinate for each vertex //by using the TexCoord command BEFORE the Vertex command GL.TexCoord2(0.0f, 0.0f); GL.Vertex2(Rect.X, Rect.Y); GL.TexCoord2(1.0f, 0.0f); GL.Vertex2(Rect.MaxX, Rect.Y); GL.TexCoord2(1.0f, 1.0f); GL.Vertex2(Rect.MaxX, Rect.MaxY); GL.TexCoord2(0.0f, 1.0f); GL.Vertex2(Rect.X, Rect.MaxY); GL.End(); //the texture is disabled, so no other draw calls use this texture tex.Deactivate(); }
private void DrawEnvironment(Shader shader, CameraOrbit camera) { // camera var cam = camera.CalcMatrix().ToOpenTK(); GL.Uniform3(shader.GetUniformLocation("cameraPosition"), camera.CalcPosition().ToOpenTK()); GL.UniformMatrix4(shader.GetUniformLocation("camera"), true, ref cam); // environment // different ids to differentiate spheres in fragment shader var id = 1; // variable that excludes object from shadow throwing envMap_tex.Activate(); GL.Uniform1(shader.GetUniformLocation("id"), id); this.environment.SetAttribute(shader.GetAttributeLocation("instancePosition"), new Vector3[] { new Vector3(0, 0, 0) }, VertexAttribPointerType.Float, 3, true); this.environment.Draw(); envMap_tex.Deactivate(); }
private void DrawField(IGameState gameState) { //background var field = new Box2D(0, 0, gameState.GridWidth, gameState.GridHeight); texTable.Activate(); field.DrawTexturedRect(new Box2D(0, 0, 8, 8)); texTable.Deactivate(); //grid GL.Color3(Color.Black); GL.LineWidth(3.0f); GL.Begin(PrimitiveType.Lines); for (int i = 0; i <= gameState.GridWidth; ++i) { GL.Vertex2(i, 0.0); GL.Vertex2(i, gameState.GridHeight); } for (int i = 0; i <= gameState.GridHeight; ++i) { GL.Vertex2(0.0, i); GL.Vertex2(gameState.GridWidth, i); } GL.End(); //chips GL.Enable(EnableCap.Blend); GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); for (int x = 0; x < gameState.GridWidth; ++x) { for (int y = 0; y < gameState.GridHeight; ++y) { var type = gameState[x, y]; if (FieldType.EMPTY == type) { continue; } DrawSprite(x + 0.5f, y + 0.5f, FieldType.BLACK == type ? texBlack : texWhite, 0.45f); } } GL.Disable(EnableCap.Blend); DrawSelection(gameState.LastMoveX, gameState.LastMoveY); }
private static void DrawTexturedRect(Box2D rect, Texture tex, Box2D texCoords) { tex.Activate(); rect.DrawTexturedRect(texCoords); tex.Deactivate(); }