OpenGL on Mac OS X

Started by
12 comments, last by bronxbomber92 17 years, 6 months ago
Hello, I have been reading the the red book, and I would like to use OpenGL on my mac. But I don't want to use objective-c with cocoa. I would like to use c/c++... I've tried using GLUT then using nehe's tutorials, but it just gives me a black screen. Can anyone help me?
Advertisement
Well, I have used OpenGL successfully on MacOSX -- both using Glut and SDL. Can you post your code? (or send it to me in a PM if it is long?)
Quote:Original post by bronxbomber92
Hello, I have been reading the the red book, and I would like to use OpenGL on my mac. But I don't want to use objective-c with cocoa. I would like to use c/c++... I've tried using GLUT then using nehe's tutorials, but it just gives me a black screen. Can anyone help me?
SDL. No Objective-C or Cocoa required (at least not that you have to deal with).

That said, the 'black screen' is likely just an error in your code, and it might be good (just as an excercise) to try to get things working with GLUT first (unless there's a support problem with GLUT and OS X that I'm not aware of). If your code is short, you might post it here and see if someone can spot the problem.

In the long run though, I think you'll be happier with SDL.
You can use c++ with a cross platform library and opengl with OS X. I have never tried it with GLUT, as glut is deprecated, and no longer used. I have used it with SDL, and that works fine. Nehe's tutorials should also work fine. So yes, you can do it. Have you tried downloading and using the project files for the os x initialization tutorial?
Ok, I'l try SDL and OpenGL together, instead of glut. Where can I learn how to implement the two together? And soryy, but I cannot post the code as I kinda was messing with it and its beyond repair :p
Quote:Have you tried downloading and using the project files for the os x initialization tutorial?
No I have not.

Thanks for the fast replies :)
Nehe's tutorials should have some SDL examples.
Also SDL's site should have something.
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
Ok, thanks everyone. I'll check it all out!
Sorry for double post. But I got SDL with OpenGL working :)

Now I just have an error that I don't understand.
Quote:main.c:71: error: nested functions are disabled, use -fnested-functions to re-enable
main.c:127: error: nested functions are disabled, use -fnested-functions to re-enable
main.c:151: error: parse error at end of input
These are my errors, and this is my code
#include "SDL.h"#include <OpenGL/gl.h>#include <math.h>#include <stdio.h>	#include <stdlib.h>#define MAX_PARTICLES 100typedef struct PARTICLES_ {	float life;	float fade;	float x;	float y;	float z;	float xi;	float yi;	float zi;} PARTICLES;PARTICLES particle[MAX_PARTICLES];int loop;float V;float Angle;float red = 0;float green = 0;float blue = 0;void InitGL();void Display();void InitGL() {		glClearColor( 0, 0, 0, 0 );		glLoadIdentity();									// Reset The Projection Matrix    glEnable(GL_TEXTURE_2D);    glEnable(GL_BLEND);    glShadeModel(GL_SMOOTH);    glBlendFunc(GL_SRC_ALPHA, GL_ONE);		for( loop = 0; loop < MAX_PARTICLES; loop++) {		particle[loop].life = 1.0;		particle[loop].fade = (rand()%100)/1000.0 + 0.05;		V = rand()%25;		Angle = rand()%360;				particle[loop].x = 0;		particle[loop].y = 0;		particle[loop].z = 0;				particle[loop].xi = sin(Angle)*V;		particle[loop].yi = cos(Angle)*V;		particle[loop].zi = (((rand()%10)-5)/10)*V;	    glViewport( 0, 0, 640, 480 );	    glOrtho( 0, 640, 480, 0, -1, 1 );    }void Display() { //LINE 71	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);		// Clear The Screen And The Depth Buffer	glLoadIdentity();				// Reset The View		glTranslatef(0,0,1);			for(loop = 0; loop < MAX_PARTICLES; loop++) {				float x;		float y;		float z;				x = particle[loop].x;		y = particle[loop].y;		z = particle[loop].z;				glColor4f(.5f,.5f,1.f,particle[loop].life);				glBegin(GL_TRIANGLE_STRIP);		glTexCoord2f(1,1); glVertex3f( x + 0.2f, y + 0.2f, z );		glTexCoord2f(0,1); glVertex3f( x - 0.2f, y + 0.2f, z );		glTexCoord2f(1,0); glVertex3f( x - 0.2f, y - 0.2f, z );		glTexCoord2f(0,0); glVertex3f(x-0.2f,y-0.2f,z);		glEnd();				particle[loop].x += (particle[loop].xi/250);		particle[loop].y += (particle[loop].yi/250);		particle[loop].z += (particle[loop].zi/250);				// Slow down the particles		particle[loop].xi*=.975;  		particle[loop].yi*=.975;		particle[loop].zi*=.975;				particle[loop].life-=particle[loop].fade;	 // Reduce Particles Life By 'Fade'				if (particle[loop].life<0.05f)	 // If Particle Is Burned Out		{			particle[loop].life=1.0f;	 // Give It New Life			particle[loop].fade= (float)(rand()%100)/7500 + 0.0075f;	// Random Fade Value			particle[loop].x= 0;	 // Center On X Axis			particle[loop].y= 0;	 // Center On Y Axis			particle[loop].z= 0;	 // Center On Z Axis			V = ((float)((rand()%9))+1);			Angle = (float)(rand()%360);						particle[loop].xi = sin(Angle) * V;			particle[loop].yi = cos(Angle) * V;			particle[loop].zi = ((rand()%10)-5)/5;		} 	}    SDL_GL_SwapBuffers();}	   int main(int argc, char *argv[]){ //LINE 127    SDL_Surface *screen;	    // Slightly different SDL initialization    if ( SDL_Init(SDL_INIT_VIDEO) != 0 ) {        printf("Unable to initialize SDL: %s\n", SDL_GetError());        return 1;    }	    SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); // *new*	    screen = SDL_SetVideoMode( 640, 480, 16, SDL_OPENGL ); // *changed*    if ( !screen ) {		printf("Unable to set video mode: %s\n", SDL_GetError());		return 1;	}		while(1) {				InitGL();		Display();	}    	return 0;} //LINE 151

Thanks for any help :)
Looks like you're missing a closing bracket in your for () loop in InitGL().
Thanks, it worked (but now how I intended it to >.>)

This topic is closed to new replies.

Advertisement