private static void DrawSpriteBatch(IEnumerable <IReadOnlyBox2D> bounds, ITexture texture) { texture.Activate(); foreach (var enemy in bounds) { Draw(enemy); } texture.Deactivate(); }
/// <summary> /// Draws the specified texture. /// </summary> /// <param name="texture">The texture.</param> /// <param name="setUniformsHandler">The set uniforms handler.</param> public void Draw(ITexture texture, SetUniforms setUniformsHandler = null) { shaderProgram.Activate(); texture.Activate(); setUniformsHandler?.Invoke(shaderProgram); GL.DrawArrays(PrimitiveType.Quads, 0, 4); texture.Deactivate(); shaderProgram.Deactivate(); }
private static void DrawTexturedRect(IReadOnlyBox2D rect, ITexture tex, IReadOnlyBox2D texCoords) { tex.Activate(); GL.Begin(PrimitiveType.Quads); GL.TexCoord2(texCoords.MinX, texCoords.MinY); GL.Vertex2(rect.MinX, rect.MinY); GL.TexCoord2(texCoords.MaxX, texCoords.MinY); GL.Vertex2(rect.MaxX, rect.MinY); GL.TexCoord2(texCoords.MaxX, texCoords.MaxY); GL.Vertex2(rect.MaxX, rect.MaxY); GL.TexCoord2(texCoords.MinX, texCoords.MaxY); GL.Vertex2(rect.MinX, rect.MaxY); GL.End(); tex.Deactivate(); }
private void RenderSsao(ITexture depthTexture) { _ssaoShader.Activate(); GL.Uniform2(_ssaoShader.GetResourceLocation(ShaderResourceType.Uniform, "iResolution"), new OpenTK.Vector2(_width, _height)); GL.Uniform1(_ssaoShader.GetResourceLocation(ShaderResourceType.Uniform, "iGlobalTime"), _time); GL.ActiveTexture(TextureUnit.Texture0); depthTexture.Activate(); GL.DrawArrays(PrimitiveType.Quads, 0, 4); _ssaoShader.Deactivate(); depthTexture.Deactivate(); }
private static void DrawTexturedRect(IReadOnlyBox2D Rectangle, ITexture tex) { GL.Color3(Color.White); tex.Activate(); GL.Begin(PrimitiveType.Quads); GL.TexCoord2(0.0f, 0.0f); GL.Vertex2(Rectangle.MinX, Rectangle.MinY); GL.TexCoord2(1.0f, 0.0f); GL.Vertex2(Rectangle.MaxX, Rectangle.MinY); GL.TexCoord2(1.0f, 1.0f); GL.Vertex2(Rectangle.MaxX, Rectangle.MaxY); GL.TexCoord2(0.0f, 1.0f); GL.Vertex2(Rectangle.MinX, Rectangle.MaxY); GL.End(); tex.Deactivate(); }
private static void DrawTexturedRect(IReadOnlyBox2D Rect, ITexture texture) { //the texture has to be enabled before use texture.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.MinX, Rect.MinY); GL.TexCoord2(1.0f, 0.0f); GL.Vertex2(Rect.MaxX, Rect.MinY); GL.TexCoord2(1.0f, 1.0f); GL.Vertex2(Rect.MaxX, Rect.MaxY); GL.TexCoord2(0.0f, 1.0f); GL.Vertex2(Rect.MinX, Rect.MaxY); GL.End(); //the texture is disabled, so no other draw calls use this texture texture.Deactivate(); }
private void RenderGround(Vector3 cameraPosition, float[] cam) { _geometryShader.Activate(); GL.ActiveTexture(TextureUnit.Texture0); _groundTexture.Activate(); GL.Uniform1(_geometryShader.GetResourceLocation(ShaderResourceType.Uniform, "tex"), TextureUnit.Texture0 - TextureUnit.Texture0); GL.UniformMatrix4(_geometryShader.GetResourceLocation(ShaderResourceType.Uniform, "camera"), 1, false, cam); GL.Uniform3(_geometryShader.GetResourceLocation(ShaderResourceType.Uniform, "cameraPosition"), cameraPosition.ToOpenTK()); GL.Uniform3(_geometryShader.GetResourceLocation(ShaderResourceType.Uniform, "ambientLightColor"), new OpenTK.Vector3(0.1f, 0.1f, 0.1f)); GL.Uniform3(_geometryShader.GetResourceLocation(ShaderResourceType.Uniform, "lightDirection"), new OpenTK.Vector3(1f, 1.5f, -2f).Normalized()); GL.Uniform3(_geometryShader.GetResourceLocation(ShaderResourceType.Uniform, "lightColor"), new OpenTK.Vector3(1f, 1f, 1f)); _groundGeometry.Draw(); _groundTexture.Deactivate(); _geometryShader.Deactivate(); }
private void RenderAddedTextures(ITexture texture1, ITexture texture2, float opaque) { _addShader.Activate(); GL.ActiveTexture(TextureUnit.Texture0); texture1.Activate(); GL.Uniform1(_addShader.GetResourceLocation(ShaderResourceType.Uniform, "image1"), TextureUnit.Texture0 - TextureUnit.Texture0); GL.ActiveTexture(TextureUnit.Texture1); texture2.Activate(); GL.Uniform1(_addShader.GetResourceLocation(ShaderResourceType.Uniform, "image2"), TextureUnit.Texture1 - TextureUnit.Texture0); GL.Uniform1(_addShader.GetResourceLocation(ShaderResourceType.Uniform, "opaque"), opaque); GL.DrawArrays(PrimitiveType.Quads, 0, 4); texture1.Deactivate(); texture2.Deactivate(); _addShader.Deactivate(); }
private void RenderGui(int materialId, int materialAmount, Voxel raytracedVoxel) { GL.Color3(Color.White); float crosshairsSize = 70.0f; _crosshairs.Activate(); RenderFunctions.DrawRect(-crosshairsSize / (2 * (float)_width), -crosshairsSize / (2 * (float)_height), crosshairsSize / (float)_width, crosshairsSize / (float)_height); _crosshairs.Deactivate(); float centerPos = -CalculateVoxelContentGuiTextWidth(materialId, materialAmount, 0.07f) / _aspect / 2; RenderVoxelContentGui(materialId, materialAmount, 0.07f, new Vector2(centerPos, -1.0f), "Selected:"); if (raytracedVoxel != null && raytracedVoxel.MaterialId != Constant.MaterialAir) { centerPos = -CalculateVoxelContentGuiTextWidth(raytracedVoxel.MaterialId, raytracedVoxel.Amount, 0.07f) / _aspect / 2; RenderVoxelContentGui(raytracedVoxel.MaterialId, raytracedVoxel.Amount, 0.07f, new Vector2(centerPos, 0.79f), "Looking at:"); } }
public void Render() { // Relevant for non shader pipelines // Got from: https://github.com/danielscherzer/Framework/blob/72fec5c85e6f21b868c41141ed1c8105f5252e5e/CG/ // ... Examples/TextureExample/TextureExample.cs GL.Enable(EnableCap.Texture2D); // Enable blending for transparency in textures GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); GL.Enable(EnableCap.Blend); // Color is multiplied with the texture color // White means no color change in the texture will be applied GL.Color4(ColorFilter); var matrix = GameObject?.Transform?.GetTransformationMatrixCached(!GameObject.IsUiElement) ?? System.Numerics.Matrix3x2.Identity; var minXminY = FastVector2Transform.Transform(Rect.MinX, Rect.MinY, matrix); var maxXminY = FastVector2Transform.Transform(Rect.MaxX, Rect.MinY, matrix); var maxXmaxY = FastVector2Transform.Transform(Rect.MaxX, Rect.MaxY, matrix); var minXmaxY = FastVector2Transform.Transform(Rect.MinX, Rect.MaxY, matrix); texture.Activate(); GL.Begin(PrimitiveType.Quads); GL.TexCoord2(0.0f, 0.0f); GL.Vertex2(minXminY); GL.TexCoord2(1.0f, 0.0f); GL.Vertex2(maxXminY); GL.TexCoord2(1.0f, 1.0f); GL.Vertex2(maxXmaxY); GL.TexCoord2(0.0f, 1.0f); GL.Vertex2(minXmaxY); GL.End(); texture.Deactivate(); GL.Disable(EnableCap.Blend); GL.Disable(EnableCap.Texture2D); }
private void DrawObject(VAO geom, ITexture envMap, ITexture materialTex, Transformation3D camera, Vector3 cameraPosition) { shaderProgram.Activate(); GL.ActiveTexture(TextureUnit.Texture0 + 0); envMap.Activate(); shaderProgram.Uniform("envMap", 0); GL.ActiveTexture(TextureUnit.Texture0 + 1); materialTex.Activate(); shaderProgram.Uniform("materialTex", 1); shaderProgram.Uniform("camera", camera.CalcLocalToWorldColumnMajorMatrix()); shaderProgram.Uniform("cameraPosition", cameraPosition); geom.Draw(); GL.ActiveTexture(TextureUnit.Texture0 + 0); envMap.Deactivate(); GL.ActiveTexture(TextureUnit.Texture0 + 1); materialTex.Deactivate(); shaderProgram.Deactivate(); }
public static void ActivateTexture(this IShaderProgram shader, string name, int id, ITexture texture) { GL.ActiveTexture(TextureUnit.Texture0 + id); texture.Activate(); shader.Uniform(name, id); }
private static void DrawTexturedRect(IReadOnlyBox2D rect, ITexture tex, IReadOnlyBox2D texCoords) { tex.Activate(); rect.DrawTexturedRect(texCoords); tex.Deactivate(); }