Solved

Combination of an OpenGL CView, and OpenGL CWnd, and GDI

Posted on 2003-11-07
2
628 Views
Last Modified: 2013-12-06
This is my first actual question to the site but I have lurked long enough and am ready to join.  I've got an open source game that's a port of the board game Settlers of Catan, and it uses OpenGL in a CView for the game rendering and GDI over that for information display and user interaction.  The game is available at http://www.settlers3d.net and the source is all at SourceForge.net under the project 'settlers3d'.

I am now in the process of adding a brand-new expansion to the game and I want to have a separate 3D rendering of the progress of a certain ship piece over a certain tile (called the 'barbarian attack' in the game).  This rendering will be informational only and totally static, meaning the users can't interact with it like they do the main CView OpenGL window.

I'm trying to create a new CWnd based OpenGL window for this barbarian attack that is displayed in its own area that overlays the OpenGL CView.  (It actually slides in and out from the side of the game window, but that's extemperaneous to the problem.)  I have created the new OpenGL CWnd and gotten it to display what I want, however, all of the Windows GDI drawing is now very messed up.  Here is a screenshot: http://www.settlers3d.net/images/gdiproblem.jpg
 
It seems that with the OpenGL CWnd turned on, all of the rendering contexts for the GDI drawing are incorrect.  If I comment out the Create() call for the CWnd, everything works properly again.  If I move the application window around, the GDI snaps back into correct drawing, but as soon as I do something in the game that changes the GDI information displays, nothing updates properly.

Does anyone have any idea what would cause this?  I don't want to clutter up the question with massive source code pastes, but I can post some links to the files on SourceForge if it would help.
0
Comment
Question by:jmfugate
2 Comments
 

Accepted Solution

by:
jmfugate earned 0 total points
ID: 9703352
I figured out my own answer.  In the OnPaint handler for the CWnd derived class, you need the following calls:

/////////////////////////////////////////////////////////////////////////////
// drawing
/////////////////////////////////////////////////////////////////////////////
void CGLBaseWnd::OnPaint()
{
      PAINTSTRUCT ps;

      //prepare painting region
      BeginPaint(&ps);

      ... your code ...

      EndPaint(&ps);
}

The BeginPaint and EndPaint set the clipping regions properly for the window being drawn.  It wasn't actually related to the OpenGL code at all.

0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently, in one of the tech-blogs I usually read, I saw a post about the best-selling video games through history. The first place in the list is for the classic, extremely addictive Tetris. Well, a long time ago, in a galaxy far far away, I was…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question