Simple C++ OpenGL program.

Member
Posts: 89
Joined: 2005.06
Post: #1
Ok. All I want, is a window to open, with and openGL frame inside of it, that I can load anything or whatever once I start learning the OpenGL and C++ language. (already know C++) but I cant seem to do this. I want it to be entirely C++ for easy porting. But as of yet, I haven't discovered how to open up a window in C++. Can someone help me or suggest an alternative. The absolute thing which cannot be changed is the fact that the program will be written in C++. Thanks.
Quote this message in a reply
Moderator
Posts: 691
Joined: 2002.04
Post: #2
C++ is just a language, and has no capabilities for opening windows or creating OpenGL contexts without using an API; if you're coding in C++, and want the code to be cross-platform, your best bet for creating the window/OGL context is SDL (small SDL with OGL tutorial here); if you don't care for cross-platform code, you could also investigate Carbon.

Mark Bishop
Quote this message in a reply
Member
Posts: 89
Joined: 2005.06
Post: #3
Hey thanks a lot for the reply. Very helpful. Now I ran it, (also downloaded the SDL.framework) but It simply compiles (no errors) executes (no errors) and exits (no errors). Yet nothing visual happens. Could you explain this? I used the full tutorial from the page you posted. (BTW your link is wrong, forgot an r in .org)
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #4
Quote this message in a reply
Moderator
Posts: 691
Joined: 2002.04
Post: #5
I'm not familiar with the first example, but from a quick read it seem you won't see anything because the first example only opens the window/creates the OpenGL context; it doesn't have an event loop, and so it quits as soon as the window has been opened/OGL context has been created.

If you want the window/OGL context to remain on screen until you close the window, insert the following quick, dirty, and untested code at the end...

Code:
SDL_Event e;
for(;;)
{
  while( SDL_PollEvent( &e ))
  {
    if( e.type == SDL_QUIT )
    {
      return 0;
    }
  }
}

Mark Bishop
Quote this message in a reply
Member
Posts: 89
Joined: 2005.06
Post: #6
Hey I got it to work, for other people who might eventually come across a similar problem, this is what you do. First you have to include OpenGL.framework into your project, Download the SDL.framework and place it in your System/Library/Frameworks folder. Then return to your C++ program and Add that framework to your project. Then you need to copy the SDLMain.h and SDLMain.m to your project (under Sources) and you need to change the line in SDLMain.m that looks like this (at the top)
#import "SDL.h"
to
#import "SDL/SDL.h"

That should about do it. put all your code in main.cpp or main.c depending on which language you are using, and then compile. Should work. Thats all I've got for now.
Quote this message in a reply
Member
Posts: 89
Joined: 2005.06
Post: #7
WHoa Keith, I didnt see your post before. That's really helpful, thanks.
Quote this message in a reply
Member
Posts: 111
Joined: 2002.06
Post: #8
I wrote a tutorial on AGL a few years ago for iDevGames. You can download the tutorial here:

http://www.meandmark.com/articles.html

The tutorial covers fullscreen AGL, not drawing into a window, but the code is in C++. It should provide a good starting point for writing OpenGL programs in C++.

Mark Szymczyk
http://www.meandmark.com
Quote this message in a reply
Member
Posts: 89
Joined: 2005.06
Post: #9
yours however, i failed to get working. the stdlibc++.a is nowhere to be found, not even online. I suppose I need a C++ framework, however the last even related thing that I found was MacApp and that was discontinued in 2001. I suppose apple doesn't even support C++?
Quote this message in a reply
Moderator
Posts: 691
Joined: 2002.04
Post: #10
@Volte: Project Builder/Xcode quite happily supports C++; the problems you're encountering are probably related to the (fixable) incompatibility Apple introduced to C++ apps/libraries compiled with Mac OS X 10.4.x with any earlier version of OS X...

Mark Bishop
Quote this message in a reply
Member
Posts: 89
Joined: 2005.06
Post: #11
Ah! Thanks for the clear and concise speculation. I believe that makes sense, and my general knowledge of the platform as far as that of a developers viewpoint is ever increasing.
Quote this message in a reply
Member
Posts: 111
Joined: 2002.06
Post: #12
The project I created is about three years ago, which could be causing problems. I would suggest creating a new Carbon Application project and adding the OpenGL and AGL frameworks to the project as well as the source code files and the resource file.

You're going to have to add a Build Resource Manager Resources build phase to the new project to build the resource file properly. Choose Project > New Build Phase to add the build phase. The resource file will probably be in the Copy Bundle Resources build phase. Move it to the Build Resource Manager Resources build phase.

Mark Szymczyk
http://www.meandmark.com
Quote this message in a reply
Post Reply