UnholySpirit's picture

Create a square, put a PNG texture on it, write the square on my window. That's all I need.

Hello guys, I'm from XNA develop and I can't handle with OpenTK.

I read the tutorials but is hard for me understand how to make 3 simple things:

  1. Create a rectangle o a surface where i can write
  2. Put a texture on it, png obv. with transparencies
  3. Write my textured surface to the screen

I want only make a little 2D game, I think the ORTO mode is my mode but I can't setup it correctly.
Thanks guys :)



Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
the Fiddler's picture

As you've seen XNA is a higher-level API than OpenGL or Direct3D. Things that are very easy to do in XNA are a little more work in straight OpenGL/D3D.

OpenTK comes with a "texture mapping" example. Run the Example Browser and go to "GL" -> "1.x - Texture Mapping" to see the source code.

There are three different concepts you need to learn here:

  1. Loading an image from disk.
  2. Uploading this image to an OpenGL texture.
  3. Rendering the OpenGL texture to screen.

Only #2 and #3 are specific to OpenGL. #1 would be the same regardless of the drawing API you are using.

For #1, you create a new System.Drawing.Bitmap(filename) and call the "LockBits()" method to access the internal image data.

For #2, you generate a new OpenGL texture object, bind it, set its parameters and, finally, upload the image data from step 1. (GL.GenTexture(), GL.BindTexture(), GL.TexParameter() and GL.TexImage2D()).

For #3, you enable texturing (GL.Enable(EnableCap.Texture2d)), bind the texture object (GL.BindTexture()) and, finally, render a quad.

For the exact code, check out the "Texture Mapping" example in the Example Browser (you can find that in your start menu, if you are using windows).