Beginner Carbon & OpenGL help

jo_shadow
Unregistered
 
Post: #1
I'm a complete beginner with most aspects of OpenGL programming, as well as having no experience to speak of with using either carbon or cocoa, having minor experience with C, and some with java and actionscript, having done more web oriented stuff than actual computer software, and being more of a graphic designer at heart than a programmer.

That being said, I just bought this book called OpenGL Proframming on Mac OS X, which seems to be the only recent book i've been able to find exclusively on the subject: http://www.amazon.com/dp/0321356527?tag=...F3A8N6X5H&

So far all I really want to do is create a window so I can start getting aquainted with how OpenGL works. I do have a friend who has alot of experience with OpenGL, but he is a windows enthusiast so until I can actually get stuff to show up he won't be much help to me.

In short, there is a small bit of AGL OpenGL code in the book, page 92-93 if anyone has it, for creating a full screen AGL OpenGL application, and I tried copying that to the letter. However I get a whole bunch of errors which leads me to believe I'm missing something crucial that's not outlined in the text, probably because most people reading the text would know enough before-hand to know how to begin before plugging in their code.

Here's what I did:
1. Created a new carbon C++ application project in Xcode (leopard version)
2. Added the OpenGL and AGL frameworks (screenshot: http://img526.imageshack.us/img526/5453/picture1gg4.png )
3. deleted the code in main.c, and replaced it with the following code from the book:
Code:
#include <Carbon/Carbon.h>
#include <OpenGL/OpenGL.h>
#include <AGL/agl.h>

int main(int argc, char **argv)
{
    AGLPixelFormat pixelFormat;
    GLint attribs[] =
    {
        AGL_DUBBLEBUFFER,
        AGL_ACCELERATED,
        AGL_NO_RECOVERY,
        AGL_RGBA,
        AGL_NONE
    };
    pixelformat = aglChosePixelFormat( NULL, 0, attribs);
    context = aglCreateContext( pixelFormat, NULL);
    aglDestroyPixelFormat( pixelFormat );
    aglSetCurrentContext( context );
    aglSetFullScreen( context, 0, 0, 0, 0 );
    
    initGLstate();
    draw();
    sleep( 3 );
    
    aglSetCurrentContext( NULL );
    aglDestroyContext( context );
    return 0;
}

void initGLstate()
{
    glMatrixMode( GL_PROJECTION);
    glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
    
    glClearColor(0.0, 0.5, 0.8, 1.0);
}

void draw(void)
{
    glClear(GL_COLOR_BUFFER_BIT);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glRotatef(5.0, 0.0, 0.0, 1.0);
    glColor4d(0.0, 1.0, 0.0, 1.0);
    glRectd(0.1, 0.1, 0.9, 0.9);
    
    aglSwapBuffers(context);
}
4. attempted to buld, and recieved 8 errors, 16 warnings ( screenshot: http://img185.imageshack.us/img185/1378/picture2ly3.png )

So here is my plea for help:
If anyone could tell me what I'm missing, or what you might do differently, please tell me so. Also keep in mind how much of a beginner with this stuff I am.

-Jo
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
C is case-sensitive, your code is trying to pretend it's not.

You shouldn't be using AGL/Carbon for new code anyway, switch to Cocoa.
Quote this message in a reply
Moderator
Posts: 3,579
Joined: 2003.06
Post: #3
OneSadCookie Wrote:You shouldn't be using AGL/Carbon for new code anyway, switch to Cocoa.

... or at least use GLUT instead if you want to jump right into OpenGL and get help from your friend at the same time, since GLUT works on Windows too. If your friend is familiar with SDL, that is also an option, but GLUT is simpler at first. Cocoa is the ultimate way to go, but there are more hoops to jump through to get it working for you. Whatever the case, yeah, AGL/Carbon is not recommended now -- at all.
Quote this message in a reply
Moderator
Posts: 1,562
Joined: 2003.10
Post: #4
The above advice aside, here are the things that are causing your compile errors:
  • AGL_DOUBLEBUFFER is misspelled as AGL_DUBBLEBUFFER
  • pixelFormat is mistyped as pixelformat
  • context is undeclared (add AGLContext context; at the top of the function)
  • initGLstate() and draw() are used before they're declared. Add function prototypes (void initGLstate(); and void draw(); ) somewhere before main().
Quote this message in a reply
Sage
Posts: 1,199
Joined: 2004.10
Post: #5
I agree with Jake: If you're just learning GL, the last thing you want to be doing is battling Carbon for god's sake.

Use GLUT. You'll get a lot for free ( windowing, keyboard, idle timer, etc ) and a lot of OpenGL books -- the Red Book in particular -- use GLUT for demoing. In fact, NVIDIA demos all seem to use GLUT as well.

Once you've learned enough about GL to feel confident, then experiment with writing your own app and context. And when you do, use Cocoa. You'll find it a lot easier.

Finally, Carbon is a dead end. Don't waste your time there.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Beginner-Intermediate level OpenGL tutorials Jones 7 4,522 Jan 9, 2006 12:40 AM
Last Post: AnotherJake
  is sdl+opengl slower than cocoa/carbon+opengl? Najdorf 9 4,875 Nov 16, 2005 09:45 PM
Last Post: WhatMeWorry
  Carbon vs Cocoa OpenGl Byron Clarke 2 2,885 May 31, 2005 05:47 PM
Last Post: maaaaark
  Carbon and OpenGL jonbryan 3 3,850 Feb 6, 2005 09:52 PM
Last Post: FCCovett
  loading a texture in opengl with carbon hyperutila 3 3,276 Nov 25, 2004 03:07 PM
Last Post: FCCovett