Jump to content
  • Advertisement
Sign in to follow this  
mengha

Including OpenGL in a header?

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

How would I include OpenGl in a header file? At the moment my project looks like (I'm tryin to keep things seperate so its better organised): main.cpp - Included win32window.h here and call the functions. win32window.h - Windows Header Included here. win32window.cpp - Functions: RegisterWindow, CreateWindow I want to add (for example) openglstuff.h and openglstuff.cpp and include gl.h in this header. However when I do so the gl.h errors (Is this because it can't see the window.h stuff?) So how could I do it? Thanks.

Share this post


Link to post
Share on other sites
Advertisement
A comment on your organization:

Don't organize your code by what it uses or what it references. Organize your code by what it does or what it is. Putting all code that references Win32 in one file and all code that references OpenGL in another won't get you very far (as you can see, you have already run into a problem).

Header files should be considered as an API for the source files they are associated with. Do not use them as repositories for other header files or a place to put declarations of private/internal types, functions, and data. That kind of organization will lead to problems.

Read this article: Organizing Code Files in C and C++

Share this post


Link to post
Share on other sites
Thanks for the replies.

I was planning to have a structure such as:

win32window
linuxwindow
macwindow
openglsetup
openglwhateverelse
openglwhateverelse2
... and so on ...

Would this be a bad way to do it? I wanted to keep things seperate so its easier to maintain and don't have lots of code in main.

Share this post


Link to post
Share on other sites
Why not just use a wrapper for your windowing code that way you won't have to write out for each seporate os in my opinion that would be a pain.

Something like Glut maybe? Not sure if it will work with OSX though. I think it will. That will remove some overhead then you can implement the OpenGL stuff inside a seperate file and call the opengl stuff from the file that handles all the glut calls.

Share this post


Link to post
Share on other sites
Yes but it is very involved and takes away from time that could be spent coding other things, was just trying to help but then also splitting it up using different sections for windows, linux, osx is kind of pointless if your using glut. If you want to learn windows api and other api's then I would suggest not using glut.

But I would stick it into one set of files (.c and .h) and depending on the implementation use the same function names that way your code will be universal and allow the same functions in the header files for the windows/linux/osx code instead of putting it all into a seperate file like you had planned on. Look at source code for other projects that do the same thing and see how they do it exactly. Using pre-processor commands will help too.

Hope this helps a little.

Share this post


Link to post
Share on other sites
So can I use OpenGL commands in a different CPP file if I include it where windows.h is included?

EDIT:

So how do engines handle openGL? Do they just stick it all in the main file with windows.h? I'm just trying to keep as much out of main s I can change sperate bits around.

[Edited by - mengha on January 27, 2006 6:12:01 AM]

Share this post


Link to post
Share on other sites
Quote:
Original post by rick_appleton
Yes, this is indeed because the gl.h header file needs windows.h. So just include that above the place you include gl.h


Also gl.h does not need windows.h that would completely defeat the purpose of opengl...which is being os independent.

To answer your question usually there is a main.c and then glrender.h and glrender.c or something where ever you want to put your draw_scene() function and maybe some initialization code.

Share this post


Link to post
Share on other sites
Quote:
Original post by DreamGhost
Quote:
Original post by rick_appleton
Yes, this is indeed because the gl.h header file needs windows.h. So just include that above the place you include gl.h


Also gl.h does not need windows.h that would completely defeat the purpose of opengl...which is being os independent.

The OpenGL code is platform independent, but everything around that is not. The gl.h that belongs to Microsofts implementation of OpenGL present on virtually all installation of Windows does requires windows.h to be included*. Nothing wrong with that, as you would need platform dependent calls anyway to even get to the point where you can start using OpenGL (create a window, create a rendering context and so on, which is not OpenGL's job to deal with).

* - Actually, it just needs a few symbols to define which are defined in windows.h. You can define them manually if you like and skip windows.h.

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!