Getting started with OpenGL
I just signed up for an Open GL course on Ed2Go.com.
The instructors posts a lot of examples, buut I can't get anything to compile. For example:
I know I don't need the #include windows, but what would I need to do to just paste the rest of the code and have it run on my Mac?
The instructors posts a lot of examples, buut I can't get anything to compile. For example:
Code:
// First Try: a first OpenGL graphics program
#include <windows.h> // include windows header file
#include <GL/glut.h> // include OpenGL header file
void myInit(); // function prototype for my initialization function
void myDisplay(); // function prototype for my display function
void main(int argc, char* argv[]) // main program function
{
glutInit(&argc, argv); // initialize the GLUT toolkit
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); // set display mode
glutInitWindowSize(640, 480); // set window size
glutInitWindowPosition(50, 100); // set window position on the screen
glutCreateWindow("First Try"); // title and open the window
glutDisplayFunc(myDisplay); // register my display function
myInit(); // call my initialization function
glutMainLoop(); // begin endless main loop
}
void myInit() // initialize Open GL state
{
glClearColor(1.0, 1.0, 1.0, 0.0); // set background color to white
glColor3f(0.0, 0.0, 0.0); // set drawing color to black
glPointSize(4.0); // set dot size to 4 pixels
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, 640.0, 0.0, 480.0);
}
void myDisplay() // draw my image
{
glClear(GL_COLOR_BUFFER_BIT); // clear the screen
glBegin(GL_POINTS); // draw four points
glVertex2i(150, 150);
glVertex2i(200, 200);
glVertex2i(150, 200);
glVertex2i(200, 150);
glEnd();
glColor3f(0.0, 1.0, 0.0); // set drawing color to green
glBegin(GL_POLYGON); // draw triangle
glVertex2f(10.0, 10.0);
glVertex2f(100.0, 10.0);
glVertex2f(10.0, 100.0);
glEnd();
glFlush(); // send output to display
}I know I don't need the #include windows, but what would I need to do to just paste the rest of the code and have it run on my Mac?
#include <GLUT/glut.h>
Sir, e^iπ + 1 = 0, hence God exists; reply!
http://onesadcookie.com/Tutorials is a quick intro to setting up GLUT on Mac OS X. Aside from <GLUT/glut.h> vs. <GL/glut.h> it should mostly work just fine.
You should use GLUT_DOUBLE where they have GLUT_SINGLE and glutSwapBuffers() where they have glFlush() -- and they should, too.
You should use GLUT_DOUBLE where they have GLUT_SINGLE and glutSwapBuffers() where they have glFlush() -- and they should, too.
OneSadCookie Wrote:http://onesadcookie.com/Tutorials is a quick intro to setting up GLUT on Mac OS X. Aside from <GLUT/glut.h> vs. <GL/glut.h> it should mostly work just fine.
You should use GLUT_DOUBLE where they have GLUT_SINGLE and glutSwapBuffers() where they have glFlush() -- and they should, too.
Your tutorial is very nice. I followed the instructions, and aside from the difference in XCode versions, it works very well.
I was pretty much able to follow the same instructions for the homework file above, but here's a couple differences:
1) I have to name the file main.cpp - We're using C++ for this class
2) main has to be of return type int. Does anybody know why that is? I get an error if I try return type void for main.
You're still compiling with a C compiler, and C requires that main returns an int. You need to change the compiler to C++ iirc.
[EDIT] Oops, I didn't. Other way round. Misinformation. See Keith's post.
[EDIT] Oops, I didn't. Other way round. Misinformation. See Keith's post.
You have it backward -- C doesn't care what main returns, C++ does.
OneSadCookie Wrote:You have it backward -- C doesn't care what main returns, C++ does.
Why does
Code:
void main()
'cos GCC (which Xcode uses) is much stricter about C++ than Visual Studio is.
Basically, if your code compiles with GCC, it will almost certainly compile with Visual Studio. If your code compiles with Visual Studio, that's no guarantee that it'll compile with GCC.
Basically, if your code compiles with GCC, it will almost certainly compile with Visual Studio. If your code compiles with Visual Studio, that's no guarantee that it'll compile with GCC.
Quote:work on Visual Studio (c++ console project), but not on Xcode?
Because as Keith says, Visual Studio is absolutely ridiculous about what it will accept. Other compilers are much better about adhering to the standards and will do something useful (like generate an error) when you do something incorrect.
I can't count the number of bugs that I've found in our cross-platform code by XCode (or Codewarrior back in the day) generating an error where MSVC++ happily compiled.
Wade
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| Getting Started with OpenGL - Mac | ThrottleMonkey | 35 | 10,519 |
Mar 18, 2003 03:07 PM Last Post: xDexx |
|

