PDA

View Full Version : Help! Beginner in OpenGL Programming




Soulstorm
Dec 31, 2005, 05:45 AM
Hello. I am willing to learn programming Using C++ and OpenGL. I have knowledge of C++, but I know nothing about OpenGL.

I bought a book to start learning OpenGL, but is seems that I can't work with it...

Firstly, the book is called "OpenGL Superbible, Third Edition (http://www.starstonesoftware.com/OpenGL/index.htm)", by Richard S. Wrightm and Benjamin Lipchak.

I want to know what type of project must I create in xCode and what headers must I include in order to make my OpenGL programs to work. I tried this program (which is an example of the book)

#include <OpenGL.h>

void renderscene(){
glClear(GL_COLOR_BUFFER_BIT);
glFlush();
}

void SetupRC(){
glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
}

int main(){
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutCreateWindow("Simple");
glutDisplayFunc(RenderScene);
SetupRC();
glutMainLoop();

}

but it doesn't work. It can't even find the OpenGL.h file! What can I do? Can you give me specific instructions on how to make my programs work? I thought that OpenGL language was cross-platform. Why aren't the same commands used in this case?

The book comes with a cd in it, which includes the code of some of the programs, written in both xCode and Visual Studio for Microsoft. But it seems that these examples are old news, since they are tested with OS X 10.3.3 and xCode 1.1, therefore some of them can be compiled and some can't. What can I do? Must I obtain another book?
EDIT: Found the sample program included in the CD:
#include <OpenGL/OpenGL.h> // System and OpenGL Stuff
#include <Carbon/Carbon.h>

///////////////////////////////////////////////////////////
// Called to draw scene
void RenderScene(void)
{
// Clear the window with current clearing color
glClear(GL_COLOR_BUFFER_BIT);


// Flush drawing commands
glFlush();
}

///////////////////////////////////////////////////////////
// Setup the rendering state
void SetupRC(void)
{
glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
}

///////////////////////////////////////////////////////////
// Main program entry point
void main(int argc, char* argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(800,600);
glutCreateWindow("Simple");
glutDisplayFunc(RenderScene);

SetupRC();

glutMainLoop();
}

Doesn't compile. It get's me warnings about implicit function declarations everywhere and it says that GLUT_SINGLE, GLUT_RGB, GL_COLOR_BUFFER_BIT are undeclared. I use OS X Tiger 10.4.3 and xCode 2.1.



HiRez
Dec 31, 2005, 11:40 AM
I want to know what type of project must I create in xCode and what headers must I include in order to make my OpenGL programs to work.Just create any normal C or Objective-C based project (Cocoa, Carbon, etc.), but you need to include the OpenGL framework. Choose Add to Project... from the Project menu then navigate to /System/Library/Frameworks and add the OpenGL.framework and GLUT.framework (if you are coding a Carbon application I think you need to add AGL.framework instead). Normally you put these somewhere in the Frameworks section of your project hierarchy. You might have to include some of (but not necessarily all of) these headers for a Cocoa project, not sure how it works for Carbon:#import <OpenGL/OpenGL.h>
#import <OpenGL/gl.h>
#import <OpenGL/glu.h>
#import <OpenGL/glext.h>
#import <OpenGL/CGLRenderers.h>
#import <GLUT/glut.h>

kainjow
Dec 31, 2005, 11:40 AM
You have to add OpenGL.framework and GLUT.framework to your project. By default it doesn't know about these magically. They are located at /System/Library/Frameworks. Just go to Project (in the menu bar) > Add to Project and select both these frameworks.

Jordan72
Dec 31, 2005, 06:14 PM
Chapter 29 of http://search.barnesandnoble.com/booksearch/isbnInquiry.asp?isbn=0321213149

will atleast get you started being able to type in your OpenGL commands. This is a no-hassle brief intro to get you started using OpenGL on a Mac.

As far as learing OpenGL. I don't know about the SuperBible. I have The Official OpenGL Library, which is from the OpenGL Architecture Review Board. These two books are very well written, but assume you did all your math (I'm not done). The examples, assume you are using GLUT, but you can still progress through the book reasonabley without using GLUT.

I would suggest you get those books and start out with the book at the link above to get started. If there are other ways, I don't know of them.

slooksterPSV
Jan 2, 2006, 02:08 AM
I was able to compile the application but I kept receiving error 1002 when I tried to run it. That was using a basic carbon app and removing everything from it and copying all the header files into the project, and copying the frameworks into it too.

Soulstorm
Jan 2, 2006, 03:03 AM
Actually, I got this working after all. I added OpenGL.framework and GLUT.framework to my project, changed the headers so that these frameworks were used, and it worked fine.

But it wasn't a carbon application. It was just a C++ tool application that only had these frameworks in it. And it worked as expected.

Thanks a lot guys!