Jump to content
  • Advertisement
Sign in to follow this  
  • entries
    260
  • comments
    948
  • views
    176051

Open! Gee, Elle!

Sign in to follow this  
Pouya

297 views

So today's post is "Open! Gee, Elle!" if you remember Elle from the "Elle! Oh, Elle!" post.

Note: This is slightly a more professional post than the other ones.

So I have started working on my new game/engine, named LOL. This is a convert of Har engine that I might have talked about at some point before. Except that this one is using Tao.OpenGL instead of Managed DX.

A few points of interest in converting:

  • There's no need for Tao.DevIL and it's 500 dependent dlls. Use GDI+ to load a bitmap from a file, it loads bmp, jpg, gif, png, and a few other formats, which should satisfy everyone. Converting to an OpenGL texture with alpha channel is easy (though it took some trial and error), lock the bitmap with a PixelFormat.Format32bppArgb, and load it into glTexImage2D with a GL_BGRA_EXT format.

  • Graphics.MeasureString and DrawString in GDI+ will never have the same size unless you're using a monospaced font. No matter how much you follow the documentation for fixing overhanging glyphs, they will never be the same. Fortunately in the .NET 2.0 they have added a TextRenderer class (in Windows.Forms) that actually gives you the right answer.

  • Deleting textures is a little bit ugly. If you make the textures within a class, the texture is still there remaining on the video memory after the object has been garbage collected. You will have to implement IDisposable interface and override Disposing method to delete the texture. Unfortunately, you will definitly get an access violation error if you try this. Because OpenGL keeps the context on threads, not process, so the dispose method is called from the GC's thread, which makes the texture name invalid in the process. So the way to fix it is to have a texture pool class, and tell it that you want texture name x marked for deleting. Then in your render cycle (from the thread that initialised opengl) you should tell this pool to clear up any pending resources.



I think that's all I have to say for now.
Sign in to follow this  


2 Comments


Recommended Comments

Depending on your video card driver, it may page unused/unreferenced textures out of VRAM and onto the HDD. It's one of the secrets of OpenGL that nobody speaks of, lest they anger the SGI.

Share this comment


Link to comment
Run into a similar thing with standard images in .NET too. Fortunately I had the ability to dispose of the images manually in the right context. The program itself had to process through a few thousand images, loading each one in sequence and then loading up the next into the same object (so in theory it should dispose each time). However the garbage collector only saw the few bytes for the image description, not the unmanaged image bitmap, so it went around saying "hmm, 2KB, not worth my time". Meanwhile the entire 32bit Windows address range is exhausted by 3mp+ images sitting in unmanaged memory.

Share this comment


Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!