multiple rendering contexts

F923e021a633170fb10416df23dffddd
0
urika 101 Dec 07, 2003 at 10:31

i dont exactly know how to ask the question or if this is the right forum but i’ll try…
i made an MDI on mfc thatcan call 3 applications using openGL.
each application on its own looks ok but if i open a couple of apps the second will not load correctly and the first will become blank.
is this because i am trying to make another rendering context ?
any ideas?
thanks

19 Replies

Please log in or register to post a reply.

Aebe30cac3048af2b72eaf832b698755
0
Amithran 101 Dec 07, 2003 at 11:39

Perhaps you need to make sure your not using a global variable for the device context, and that your creating a brand new one and storing it in a different place.

I’ve tended to steer away from MFC apps (and apps with children) in preference to single windowed applications, so I dont know if this is (the/a) possible cause.

F7a4a748ecf664f189bb704a660b3573
0
anubis 101 Dec 07, 2003 at 11:54

interesting… i never tried MDI opengl apps. usually my editors have 4 views but they are all in the same window and use one gl context. in general it shouldn’t be a problem to have multiple rendering contexts open at the same time, afaik that is.

does the window go blank when you open several apps or several children in the MDI window ???

F923e021a633170fb10416df23dffddd
0
urika 101 Dec 07, 2003 at 12:35

does the window go blank when you open several apps or several children in the MDI window ???

both , each child window is an app.
i think it is the same rendering context they are trying to write to.
if i play with the size of the window i can see flickers of tow objects from two apps!

the thing is i am creating thePixelFormat and the GLcontext exactly the same.
-in the beginning the apps were SDI apps and each orked ok , the i made them into dll’s (the view and doc) and i am using them in an MDI.
perhaps the fact that they recreating the GLcontext over again is the problem ?

F7a4a748ecf664f189bb704a660b3573
0
anubis 101 Dec 07, 2003 at 14:53

well, use different contexts then. of course you will loose the old one if you recreate it

F923e021a633170fb10416df23dffddd
0
urika 101 Dec 07, 2003 at 16:26

but if i run tow applications they are ok !
only in an mdi there is a clash.
so how can fix it ? :wtf:

C24eb7e6aaefba78b94c831ddc7b4d0b
0
donBerto 101 Dec 07, 2003 at 16:33

the MDI approach, although theoretically logical, does not provide you with the effect you need. I am familiar with MDI but i don’t know the specifics of how EXACTLY the “children” work, but as far as i know, based on experience and behavior, what you draw in one context, of course, cannot be drawn in another one.

one way to approach this is to modularize your drawing function and then just pass the appropriate rendering context to your draw function… and keep your design [a la urika and amithran’s point]

or to just use one context and “split” them in whatever way you choose [a la anubis’ point]. you’ll have to mathematically divide each “window” but that’s not that hard. the trade off is that you’ll have just one rendering context which is faster than 1+n rendering contexts.

i hope that helps.

:yes:

F923e021a633170fb10416df23dffddd
0
urika 101 Dec 07, 2003 at 17:04

i need it to be an mdi!
in each app i use:

HWND hWnd = GetSafeHwnd();
HDC hDC = ::GetDC(hWnd);

is there a way to make the DC the child window ?
i think this may be the problem…

C24eb7e6aaefba78b94c831ddc7b4d0b
0
donBerto 101 Dec 08, 2003 at 04:12

your problem isn’t making the DC the child window, it’s knowing which child has the appropriate DC. i’m not in the mood to refresh myself with MDI + MFC but here’s the general approach:

// have all your drawing methods in one object
for all DC's you have
  draw to the current DC
  go to the next DC

so of course, this approach requires you to store in a container all the DCs you’ll use.

if each child will modify an abstract object [say, a 3D model or something], then you can further extend that drawing object mentioned above to have input functions to add vertices and such from each child.

I would go in and work out real code to provide a better example but I have no access to an ms box with the approriate programming tools/libraries. that and i’m cramming for finals now :D so… if you can post sample code… we might all be able to poke around with it.

:yes:

F923e021a633170fb10416df23dffddd
0
urika 101 Dec 08, 2003 at 09:58

would it be helpful to name the dc’s differently hDC1, hDC2 …?
i dont exactly understand what to post , please specify so i could post it

F7a4a748ecf664f189bb704a660b3573
0
anubis 101 Dec 08, 2003 at 11:59

donBerto : back to the boards ? yay !

urika : you need t ostore exactly one rendering context and hdc for each of your child windows. erm… if i remember correctly you can change the currently active rendering context with some wgl function… wglMakeCurrent ??? of course it’s pretty slow to always change contexts when rendering. at best you can batch up everything rendered in one window and process it in one pass.

F923e021a633170fb10416df23dffddd
0
urika 101 Dec 08, 2003 at 13:36

can i do something like :

wglMakeCurrent(pFirstView->hDC,pFirstView->m_hRC)

in the mdi in order to make the rendering context the relevant one ?

F7a4a748ecf664f189bb704a660b3573
0
anubis 101 Dec 08, 2003 at 15:17

yep

F923e021a633170fb10416df23dffddd
0
urika 101 Dec 08, 2003 at 17:45

i cant manage to do it correctly, can anyone post an example ?

F7a4a748ecf664f189bb704a660b3573
0
anubis 101 Dec 08, 2003 at 19:39

i never used multiple contexts, so i could only post an example for one. which wouldn’t be of any help to you

F923e021a633170fb10416df23dffddd
0
urika 101 Dec 11, 2003 at 09:39

ok, its official , i have NO idea why my child windows clash with each other,
i tried putting each on a different thread but i am not successful (yet).
the thing is i dont know if this is what i need to do..
here is a point i didnt tell u guys:
if i open a child window of a map (so far so good) and then i open a child window that loads 3DS objects , the program cant find them !! - i dont think its related to rendering context ,right?.
what could cause this ?????
please tell me your ideas , any ideas ,ANY.
thanks :nervous:

F7a4a748ecf664f189bb704a660b3573
0
anubis 101 Dec 11, 2003 at 10:20

the programm can’t find the 3ds models ?
there are only 2 potential sources of error. either they really aren’t there :) or you supply a wrong string to the loading routine.

F923e021a633170fb10416df23dffddd
0
urika 101 Dec 11, 2003 at 10:28

but that is exactly my point , if i open the childwindow with the 3DS FIRST it loads great, if i open it AFTER another child window it cant find the 3DS files
?!?!?!

F7a4a748ecf664f189bb704a660b3573
0
anubis 101 Dec 11, 2003 at 13:35

well, that sounds like some minor bug or typo somewhere…
i can’t say anything about that without code. usually i wouldn’t care but for the fun of it… would you send me your code ???

F923e021a633170fb10416df23dffddd
0
urika 101 Dec 11, 2003 at 14:01

i solved the 3ds files issue !
it was actually thanks to anubis’ remark

well, that sounds like some minor bug or typo somewhere…

i went back to the basics and realized that awhen opening the map i went to a different folder . so when i tried loading the 3ds files they werent there.
stupid stupid stupid
thanks
(i still have that clashing between 2 childwindows though)