Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


MFC/Windows header problem

This topic is 5400 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

Just started work on a map editor for my tile-based RPG and have run into a major stumbling block. The game itself is using the standard Win32 API (to get fullscreen and a tight game loop), but it has been my intent to build all the core game files into a static library so that I can then use MFC to build a map making GUI on top of my engine. The problem is, many of the classes in this static library need to #include the OpenGL headers, and thus (as far as I can figure) also need to #include <windows.h> so that OpenGL works correctly. This works fine, until I try to use this library with MFC. The MFC headers DO NOT play nicely with windows.h, which is to be expected. I''ve even hacked some solutions together so that it will build, but then I run into the problem of my textures not loading/binding correctly (this is probably related, but I''ll save this discussion for another thread.) Has anyone attempted somthing similar and can shed some light on an elegant workaround? I''m still not entirely clear on why I''m unable to make OpenGL calls without also including a windows header file. It''d be nice if I only had to include a windows header file once, in the class that creates the rendering context etc, then use OpenGL freely elsewhere, without being bound to other header files.

Share this post

Link to post
Share on other sites
That's strange, because I have an MFC editor, and in all the classes which need OpenGL, I just include the header files in the class's implementation file, and it works fine. Actually, I created a small file called shared.h (see below), and put all my custom includes like math.h and gl.h in there. That's then included in the class implementation file, right at the top, after stdafx.h. Don't forget that MFC is just an OOP wrapper around the Win32 API. Therefore, all the files in your application have windows.h included by default when you include stdafx.h (which is required in all MFC files, as stdafx.h contains all the MFC header #includes).

// Shared.h

#if !defined(__SHARED_H__)
#define __SHARED_H__

#include <gl\glut.h>
#include <gl\glu.h>
#include <gl\gl.h>

// Other includes and globals...

#endif // !defined(__SHARED_H__)

I'm not sure if you actually need windows.h included to use OpenGL; you probably do, though. If you #include the OpenGL headers after stdafx.h, you should be OK. You should even be able to include them in the class definition file, because stdafx.h will be #included in the class implementation file, and will #include windows.h...

Windows 95 - 32 bit extensions and a graphical shell for a 16 bit patch
to an 8 bit operating system originally coded for a 4 bit microprocessor,
written by a 2 bit company that can't stand 1 bit of competition.

[edited by - iNsAn1tY on February 26, 2004 10:14:55 PM]

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!