PDA

View Full Version : Multiple OpenGL windows and textures



Majestik
09-22-2005, 02:17 PM
Hi,

I have a quite weird problem in my openGL application under win32 , the App creates multiple windows each one with its own hdc,hglrc,etc...
Each window loads texture for the GUI (widgets maps,etc), for that I do a glGenTexture in the current context for each window (which means I'll have a texture Id of 1 in every window for the first
texture), but when I kill a window and then destroying the texture (using glDeleteTexture),
it deletes EVERY texture using the Id 1, even if the map is relative to another window ...

Anyone had this problem before ?

Thanks !
Francois

tamlin
09-22-2005, 06:06 PM
Is that even a valid operation? I mean, if you already have deleted your window, there obviously is no DC for it anymore, hence there can't be a valid RC, right?

Have you tried the other way around - to first delete the texture while the RC is valid, and then destroy the window?

Majestik
09-22-2005, 07:09 PM
sorry maybe i wasn't very clear ...
the app works this way :
- Create Window 1
Create texture Id 1 for Window 1
Create texture Id 2 for Window 1
- Create Window 2
Create texture Id 1 for Window 2
..do stuff..
- Delete texture Id 1 for Window 2
- Delete Window 2

at this point the Texture with Id 1 in the Window 1 is not working anymore (white frame) ...

tamlin
09-22-2005, 10:56 PM
sorry maybe i wasn't very clear ...
[explanation snipped]

OK, I got the impression of the opposite (wrong) order from "but when I kill a window and then destroying the texture".

A follow-up question: Is texture 1 in window 1 (visually) different from texture 1 in window 2? I'm just trying to find out if the error is indeed when deleting, so it's not wrong already when created.

Another problem could be if not running all windows in their own thread, and forgetting a wglMakeCurrent. However, considering you already got creation working that seems less likely.

I'd suspect a driver bug. What can't be explained by knowledge or logic, must be a driver bug. :)
Another argument pointing in that direction could be that code-path might not be very much used, and therefore perhaps not too well-tested.

++luck;

Zulfiqar Malik
09-23-2005, 05:29 AM
Make sure you are not sharing textures using wglShareLists(...). Also, before deleting textures of window2 (and then the window) make sure to make its context current by calling wglMakeCurrent(...), otherwise you will delete the texture for whatever context is current at that time.

Hope that helps.

Majestik
09-23-2005, 10:27 PM
I checked all that (cause i will need to share textures later) but right now i'm not using wglShareLists and yes i'm settings my context before ...
very weird ...

rgpc
09-24-2005, 04:21 PM
Are you using glGenTextures()?

Majestik
09-24-2005, 06:10 PM
sorry ... just found out what my problem was ...
I was deleting the window (and thus HRC) before
deleting my textures ...
so the delete texture was deleting textures from the
wrong Context ...

Thanks a lot anyway !