objarni's picture

First entry - TexImage is complicated!

This is my first blog entry here! Fun feature Fiddler...

Anyway - believe it or not but today was the first time I tried texturing using OpenTK. I stumbled on the TexImage2D method - I had forgot how cumbersome that method is to get right.

So I gave up for the day, but just got an idea - maybe some OpenTK user has written a Bitmap-to-texture utility function..?


Comment viewing options

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

This is the first blog entry ever! How does it feel being a beta tester? :p

You have to thank JTalton for the idea, actually.

Regarding your question, check out the texture example. This is the relevant code:

            GL.GenTextures(1, out texture);
            GL.BindTexture(TextureTarget.Texture2D, texture);
            BitmapData data = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height),
                ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, data.Width, data.Height, 0,
                OpenTK.Graphics.PixelFormat.Bgra, PixelType.UnsignedByte, data.Scan0);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);

It's a little ugly, but fortunately you can tuck it all into a Texture2D class and forget about it. As it happens, I've written several such classes for textures, shaders, VBOs, FBOs etc that I intend to clean them up and post in due time. Have to get the project database going first, though.

Edit: just found that every blog comes with an RSS feed out of the box. Nice!

objarni's picture

Cool, I'll check that out tomorrow... and when the projects/utilities database is up, some of those classes would be great there!

BTW the "Latest commits"-box is another great idea, maybe you can take credit for that instead Fiddler ??

Thanks JTalton for the blog idea - this site does seem to be more "alive" already ;)

the Fiddler's picture

Actually I came across the "latest commits" idea while reading your "Producing open source software" link. :)

The book has a section about version control best-practices and how to facilitate code review (http://producingoss.com/en/vc.html#commit-emails).

I think blogs will work nicely as an avenue to talk about projects or anything, really. It's too early to tell, but they should compliment the project database nicely.