Jump to content
  • Advertisement
Sign in to follow this  
Woltan

100 * 100 = crash

This topic is 4278 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey folks, I once again programmed myself into a dead end. This time concerning the loading of textures for multiple windows. During that approach I got tackled by a somewhat awkward behavior. What I want to do: I want two windows, that share the same textures. Like that I dont need to load textures twice. To accomplish that I use the wglShareLists function. It worked pretty well untill I tried to load a 100 * 100 bitmap. As strange as it may sound but any other size works just fine! The only time my program crashes is when I call the wglShareLists and try to load a 100 * 100 bitmap. It crashed when I call the glTexImage2D function. The next strange thing is, that if I load load a different size bitmap (for example 101 * 101) and after that the 100 * 100 bitmap it again works just fine. It is hard to believe I know, and I debugged that for 4 hours until I found the "problem". My question to the community: What is going on? Am I doing something wrong? Is there another way to share textures between windows? I hope you can help me with that! cherio Woltan

Share this post


Link to post
Share on other sites
Advertisement
What is the exact order that you're doing things?

eg.

// note: rc = rendering context
rc1=wglCreateContext
rc2=wglCreateContext
wglMakeCurrent(rc1);
// loads all textures into rc1's display list space
LoadAllTexturesIntoRC1();
// share all rc1's lists (textures, resources etc) with rc2.
wglShareLists(rc1, rc2);



1.) One of the things to watch out for here is: don't create any resources when your second context is current, make sure that first context is bound before creating any objects (eg. with glNewList, glGenTextures, etc...)

2.) Are you binding your textures to GL_TEXTURE_RECTANGLE_ARB target?
eg. glBindTexture(GL_TEXTURE_RECTANGLE_ARB, pTexture->iHandle);
If your texture sizes are not powers of 2 (eg. 1,2,4,8,16,32,64,128...) you should use the GL_TEXTURE_RECTANGLE_ARB target and not the GL_TEXTURE_2D. This applies also for glEnable, glTexImage2D function or any function which you might use GL_TEXTURE_2D for. (you can find this extension's specification here: http://oss.sgi.com/projects/ogl-sample/registry/ARB/texture_rectangle.txt)
I suspect this might be your real problem - the OpenGL driver behaviour may be undefined if you ignore any errors that it gives you.

3.) do you ever check your opengl error codes after function calls? Adding a function that asserts that there opengl error codes is a great way to track down errors in your code. Simply put a call to EGraphicsAssertNoGLError() after every time you call an opengl function eg.


#ifdef EGRAPHICS_DEBUG
#define _EGraphicsAssertNoGLError(pcFilename, iLine) { GLint iGLError; iGLError = glGetError(); if (iGLError != GL_NO_ERROR) { OutputDebugString("%s(%i): OpenGL error occurred: %i (%s)\n", pcFilename, iLine, iGLError, _GetOpenGLErrorString(iGLError)); assert(0); } }
#else
#define _EGraphicsAssertNoGLError(pcFilename, iLine)
#endif
#define EGraphicsAssertNoGLError() _EGraphicsAssertNoGLError(__FILE__, __LINE__)



So, using the above function, the first example I had would look something like this. You'd also add the assert after binding a texture to a target etc..

eg.

// note: rc = rendering context
rc1=wglCreateContext
EGraphicsAssertNoGLError();
rc2=wglCreateContext
EGraphicsAssertNoGLError();
wglMakeCurrent(rc1);
EGraphicsAssertNoGLError();
LoadAllTexturesIntoRC1();
// share all rc1's lists (textures, resources etc) with rc2.
wglShareLists(rc1, rc2);
EGraphicsAssertNoGLError();

Share this post


Link to post
Share on other sites
Hey FReY,
first of all, thank you very much, for this very detailed posting.
I solved the problem of that weird behavior. My first error was that I was using wglShareLists befor loading the textures. Having that solved I moved on to the 100 * 100 problem. I copied the source how to load a texture in opengl from some tutorial and somehow i ended up using both gluBuild2DMipmaps and glTexImage2D. Now I know that gluBuild2DMipmaps calles glTexImage2D after resizing the image a little. At least i hope that this is what it is doing.
I also have a lettle exception class thank to your recommendation.
And everything seems to be working how it is supposed to. At least I hope it does somehow I still feel not too comfortable with opengl.

Well thx again for your help!
cherio Woltan

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!