Can someone help a 'noob'? What's wrong with this?
A crash occurs on the line I've indicated in bold - that's as much as I can figure out.
This is my first attempt at anything on the Mac - this would work okay in Windows but how come this doesn't work in xCode?
Someone please help, I'm going nuts!
Thanks
RagingAvatar
#include "defines.h"
#include <stdio.h>
#include <stdlib.h>
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBegin(GL_QUADS);
glVertex2f( 0.0f, 0.0f);
glVertex2f(128.0f, 0.0f);
glVertex2f(128.0f, 128.0f);
glVertex2f( 0.0f, 128.0f);
glEnd();
glutSwapBuffers();
}
void reshape(int width, int height)
{
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0, width, 0, height);
glMatrixMode(GL_MODELVIEW);
}
void idle(void)
{
glutPostRedisplay();
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
// Make a marker to indicate the start of output
printf("**********\n");
// Print out application name and version
printf(APP_NAME);
printf(" ");
char szTemp[100];
sprintf(szTemp, "%f", APP_VER);
printf(szTemp);
printf("\n");
// Print out OpenGL information
const GLubyte * glubTemp;
glubTemp = glGetString(GL_VERSION);
printf((char*)glubTemp);
//
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize(APP_WIDTH, APP_HEIGHT);
glutCreateWindow(APP_NAME);
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutIdleFunc(idle);
glutMainLoop();
return EXIT_SUCCESS;
}
This is my first attempt at anything on the Mac - this would work okay in Windows but how come this doesn't work in xCode?
Someone please help, I'm going nuts!
Thanks
RagingAvatar
#include "defines.h"
#include <stdio.h>
#include <stdlib.h>
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBegin(GL_QUADS);
glVertex2f( 0.0f, 0.0f);
glVertex2f(128.0f, 0.0f);
glVertex2f(128.0f, 128.0f);
glVertex2f( 0.0f, 128.0f);
glEnd();
glutSwapBuffers();
}
void reshape(int width, int height)
{
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0, width, 0, height);
glMatrixMode(GL_MODELVIEW);
}
void idle(void)
{
glutPostRedisplay();
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
// Make a marker to indicate the start of output
printf("**********\n");
// Print out application name and version
printf(APP_NAME);
printf(" ");
char szTemp[100];
sprintf(szTemp, "%f", APP_VER);
printf(szTemp);
printf("\n");
// Print out OpenGL information
const GLubyte * glubTemp;
glubTemp = glGetString(GL_VERSION);
printf((char*)glubTemp);
//
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize(APP_WIDTH, APP_HEIGHT);
glutCreateWindow(APP_NAME);
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutIdleFunc(idle);
glutMainLoop();
return EXIT_SUCCESS;
}
Hi, welcome to the forum and all that! 
You're hitting a subtle difference between Windows GLUT and Mac GLUT: on Mac, the GL context isn't created until the window is. So, when you call glGetString, the GL stack isn't active in your program. Move the glGetString calls to run after you call glutCreateWindow, and it runs.
Second, please do avoid the word 'noob' and the like.
We're trying (yeah, right...) to keep a professional (yeah, right) façade and to be welcoming to new people (yeah, right...).
No harm done, you couldn't know - just wanted to point it out. 
Please post back if you need a clarification or more help!

You're hitting a subtle difference between Windows GLUT and Mac GLUT: on Mac, the GL context isn't created until the window is. So, when you call glGetString, the GL stack isn't active in your program. Move the glGetString calls to run after you call glutCreateWindow, and it runs.

Second, please do avoid the word 'noob' and the like.
We're trying (yeah, right...) to keep a professional (yeah, right) façade and to be welcoming to new people (yeah, right...).
No harm done, you couldn't know - just wanted to point it out. 
Please post back if you need a clarification or more help!
Stick with Ivan (Fenris), he can help you out a lot, he did me. Also, listen to all the advice people give here.
[offtopic]
We should make a script that changes anytime someone writes "noob" to "beginner". Noob has negative connotations, and beginner is a better word to use.
[/offtopic]
[offtopic]
We should make a script that changes anytime someone writes "noob" to "beginner". Noob has negative connotations, and beginner is a better word to use.
[/offtopic]
Thank you for such a warm welcome!
I also agree that 'n00b' is a nasty term - I used it tongue-in-cheek - it's nice to find a serious forum!
Anyway, back to 'business'..
I changed the guts of Main() to look like this:
printf(szTemp);
printf("\n");
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize(APP_WIDTH, APP_HEIGHT);
glutCreateWindow(APP_NAME);
// Note GL context isn't created until after glutCreateWindow under Mac OS X.
// Referencing the context before here will cause a crash under Mac OS X.
// Print out OpenGL information
const GLubyte * glubTemp;
glubTemp = glGetString(GL_VERSION);
printf((char*)glubTemp);
//
But still I get a crash of EXC_BAD_ACCESS..
What gives?
Thanks for all the help so far guys!
I also agree that 'n00b' is a nasty term - I used it tongue-in-cheek - it's nice to find a serious forum!
Anyway, back to 'business'..
I changed the guts of Main() to look like this:
printf(szTemp);
printf("\n");
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize(APP_WIDTH, APP_HEIGHT);
glutCreateWindow(APP_NAME);
// Note GL context isn't created until after glutCreateWindow under Mac OS X.
// Referencing the context before here will cause a crash under Mac OS X.
// Print out OpenGL information
const GLubyte * glubTemp;
glubTemp = glGetString(GL_VERSION);
printf((char*)glubTemp);
//
But still I get a crash of EXC_BAD_ACCESS..
What gives?
Thanks for all the help so far guys!
Forgive me!
I indeed am a lowly beginner and have jumped the gun!
It works perfectly
Thanks guys
I indeed am a lowly beginner and have jumped the gun!
It works perfectly

Thanks guys
Quote:I used it tongue-in-cheekI realized that you did.

Quote:I indeed am a lowly beginner and have jumped the gun!Study hard and eat your vegetables, and you'll be like me in no-time! Err...

Jokes aside, happy to help. Good luck with your endavours!
Avatar: This is a problem I've had with OpenGL in general. A lot of times, instead of giving you a nice error, it just crashes or acts as if no error happened. It can lead to a lot of headaches...
A good tip in that case is to end your rendering loop with a line that checks for glGetError and logs it if it is non-zero. That way, when you do something illegal your log will be filled with error messages. By doing it this way, you'll see right away that the error is caused by whatever you did during this compile-run cycle, instead of "somewhere in the program".
Also, launch the application through the OpenGL Profiler with the breakpoint "On Error" turned on. This will stop the application and tell you where and why an error occurred.
Also, launch the application through the OpenGL Profiler with the breakpoint "On Error" turned on. This will stop the application and tell you where and why an error occurred.
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| What's wrong with my glutSolidTeapot? | TomorrowPlusX | 4 | 4,745 |
Aug 7, 2008 10:27 AM Last Post: arekkusu |
|
| What could be wrong here? | Jones | 5 | 2,534 |
Jul 1, 2006 08:52 PM Last Post: Jones |
|
| Dreaded noob questions: OpenGL in a Cocoa App | 5thPeriodProductions | 5 | 4,031 |
Apr 10, 2006 11:08 AM Last Post: 5thPeriodProductions |
|
| Texture Color is wrong | DesertPenguin | 7 | 3,511 |
Feb 14, 2006 09:04 PM Last Post: DesertPenguin |
|
| Whats wrong with my collision code? | Jake | 6 | 2,691 |
Sep 11, 2003 12:44 PM Last Post: MacFiend |
|

