Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Mac OS 9 and Open GL




In a message dated 12/19/04 1:55:44 PM, email@hidden writes:


Could someone give a link to a sample code that compiles with Code
Warrior into a Carbon CFM application, where I could see AGL
initialization? I tried googling for this, but for now I've not found
much.


I have Mac os 9 AGL initialization code...
sadly for MPW (not CodeWarrior)...
AND, it works fine on Mac os 9 and X...

Wait a second while I go get it...
.
Here it is:

#include <Carbon.h>
#include <agl.h> /* agl.h includes gl.h as well */
#include <glu.h> /* Not strictly necessary in this example, as no glu*
functions are called */

void main() {
   WindowRef window;
   Rect bounds;
   AGLContext context; /* Keep this around to reference the OpenGL
context in the window when swapping buffers, etc. */
   AGLPixelFormat pixelFormat; /* This specifies various attributes
about the OpenGL context: Color depth, double or single buffering, etc.
*/
   /* And the attributes themselves: */
   GLint attributes[] = {AGL_RGBA, /* Use RGBA mode, as opposed to color
index mode */
                         AGL_DOUBLEBUFFER, /* Enable double buffering */
                         AGL_PIXEL_SIZE, 32, /* 32-bit color */
                         AGL_DEPTH_SIZE, 32, /* 32-bit z-buffer */
                         AGL_NONE}; /* AGL_NONE ends the attribute list
*/

   SetRect(&bounds, 100, 100, 300, 300);
   window = NewCWindow(NULL, &bounds, "\pWindow", 1, noGrowDocProc,
(WindowRef) -1, 1, 0);
   InstallStandardEventHandler(GetWindowEventTarget(window));

   pixelFormat = aglChoosePixelFormat(NULL, 0, attributes);
   context = aglCreateContext(pixelFormat, NULL);
   aglDestroyPixelFormat(pixelFormat); /* Only needed for
aglCreateContext, so dispose of it */
   aglSetCurrentContext(context);
   aglSetDrawable(context, GetWindowPort(window));
/*************This is the init (so do this ONCE)*****************/



   /* Now that the AGL context is set up, we can do some drawing */
     /*****************************DoWhatever you drawing you need here*/
   glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
   glClear(GL_COLOR_BUFFER_BIT);
   glBegin(GL_QUADS);
   glColor3f(1.0, 1.0, 1.0);
   glVertex2f(-0.5, -0.5);
   glVertex2f(-0.5, 0.5);
   glVertex2f(0.5, 0.5);
   glVertex2f(0.5, -0.5);
   glEnd();

   /* Since this is a double buffered context, we need to swap the
buffers to see the results of drawing */
   aglSwapBuffers(context);

   RunApplicationEventLoop();
}


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Mac-opengl mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/mac-opengl/email@hidden

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.