Introduction

This sample demonstrates how to load and display a simple texture.

Controls

Press Esc or click the close button to exit.

Implementation

1. The OnLoad event handler constructs a new texture object with GL.GenTextures(). It then uses System.Drawing.Bitmap to load an image from the hard drive and uploads the image data to OpenGL via GL.TexImage2D().

2. The OnRenderFrame event handler uses immediate mode to render a simple textured quad.

Note 1: System.Drawing.Bitmap stores its image data in BGRA order. This means we must use Bgra as our PixelFormat in GL.TexImage2D().

Note 2: In GL.TexImage2D(), PixelInternalFormat defines the storage format of texels ("texel elements") in video memory. PixelFormat defines the format of the image data we will upload to video memory. If these do not match, OpenGL will automatically convert our image data from PixelFormat to PixelInternalFormat, which will incure a slight performance penalty.

Note 3: In this sample, we explicitly disable mipmaps by setting TextureMinFilter to Linear (via GL.TexParameter()). Alternatively, we could enable mipmaps (set TextureMinFilter to LinearMipmapNearest or LinearMipmapLinear) and generate mipmaps for our source image using GL.GenerateMipmap().

Note 4: Do not forget to enable texturing via GL.Enable(EnableCap.Texture2D) prior to rendering. Without this, textures will show up white!