Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Dec 31, 2005, 05:45 AM   #1
Soulstorm
macrumors 68000
 
Soulstorm's Avatar
 
Join Date: Feb 2005
Help! Beginner in OpenGL Programming

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", 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)

Code:
#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:
Code:
#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.

Last edited by Soulstorm; Dec 31, 2005 at 06:05 AM.
Soulstorm is offline   0 Reply With Quote
Old Dec 31, 2005, 11:40 AM   #2
HiRez
macrumors 601
 
HiRez's Avatar
 
Join Date: Jan 2004
Location: Western US
Quote:
Originally Posted by Soulstorm
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:
Code:
#import <OpenGL/OpenGL.h>
#import <OpenGL/gl.h>
#import <OpenGL/glu.h>
#import <OpenGL/glext.h>
#import <OpenGL/CGLRenderers.h>
#import <GLUT/glut.h>
HiRez is offline   0 Reply With Quote
Old Dec 31, 2005, 11:40 AM   #3
kainjow
Moderator emeritus
 
kainjow's Avatar
 
Join Date: Jun 2000
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.
kainjow is offline   0 Reply With Quote
Old Dec 31, 2005, 06:14 PM   #4
Jordan72
macrumors member
 
Join Date: Nov 2005
Chapter 29 of http://search.barnesandnoble.com/boo...sbn=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.
Jordan72 is offline   0 Reply With Quote
Old Jan 2, 2006, 02:08 AM   #5
slooksterPSV
macrumors 68030
 
Join Date: Apr 2004
Location: Nowheresville
Send a message via AIM to slooksterPSV Send a message via MSN to slooksterPSV Send a message via Yahoo to slooksterPSV
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.
__________________
AMD Phenom 9600, 2GB RAM, 250GB HDD, ATI Radeon 4850, Vista Home Premium 64-bit
Gateway NV53 with Windows 7 Home Premium 64-bit & Ubuntu 10.04 Lucid Lynx 64-bit
slooksterPSV is offline   0 Reply With Quote
Old Jan 2, 2006, 03:03 AM   #6
Soulstorm
Thread Starter
macrumors 68000
 
Soulstorm's Avatar
 
Join Date: Feb 2005
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!
Soulstorm is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Mac programming should be more like iOS programming. moonman239 Mac Programming 13 Feb 17, 2014 01:37 PM
Best way for a beginner to learn OpenGL? ThePiratkapten Mac Programming 7 Jan 1, 2014 10:29 PM
Best book to learn Objective-C for a complete beginner to programming? Rasta4i iPhone/iPad Programming 7 Dec 18, 2013 09:03 AM
Beginning OpenGL 3.0+ Programming (again) in OS X, targeting multiple platforms Soulstorm Mac Programming 6 Jul 10, 2012 09:34 AM

Forum Jump

All times are GMT -5. The time now is 06:53 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC