Newbie trying to understand NeHe's Tutorials

Member
Posts: 281
Joined: 2009.04
Post: #1
OK, after AnotherJake's kind advice, I set off looking for Neon Helium. Wasn't hard to find. Huh

I think, OK, lets do the first tutorial, - and yes I did read "If you're running Mac OSX 1.0" LOLBlinkWacko - and I compile it in Xcode 3.1 and It gives me 3 errors!
Quote:Building target “OpenGL Tests” of project “OpenGL Tests” with configuration “Debug” — (3 errors)
mkdir "/Users/michael_mac_i/Desktop/OpenGL Tests/build/Debug/OpenGL Tests.app/Contents/MacOS"
cd "/Users/michael_mac_i/Desktop/OpenGL Tests"
setenv MACOSX_DEPLOYMENT_TARGET 10.5
/Developer/usr/bin/gcc-4.0 -arch i386 -isysroot /Developer/SDKs/MacOSX10.5.sdk "-L/Users/michael_mac_i/Desktop/OpenGL Tests/build/Debug" "-F/Users/michael_mac_i/Desktop/OpenGL Tests/build/Debug" -filelist "/Users/michael_mac_i/Desktop/OpenGL Tests/build/OpenGL Tests.build/Debug/OpenGL Tests.build/Objects-normal/i386/OpenGL Tests.LinkFileList" -mmacosx-version-min=10.5 -framework Cocoa -framework GLUT -framework OpenGL -o "/Users/michael_mac_i/Desktop/OpenGL Tests/build/Debug/OpenGL Tests.app/Contents/MacOS/OpenGL Tests"
Undefined symbols:
"_DrawGLScene", referenced from:
_DrawGLScene$non_lazy_ptr in main.o
"_InitGL", referenced from:
_main in main.o
"_ReSizeGLScene", referenced from:
_ReSizeGLScene$non_lazy_ptr in main.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
"_DrawGLScene", referenced from:
_DrawGLScene$non_lazy_ptr in main.o
"_InitGL", referenced from:
_main in main.o
"_ReSizeGLScene", referenced from:
_ReSizeGLScene$non_lazy_ptr in main.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
Build failed (3 errors)

Am I doing something wrong? Very unlike me RolleyesLOLLOLWackoSmile

If I'm not, could someone point me towards some newer OpenGL with C tutorials?
Quote this message in a reply
Moderator
Posts: 3,579
Joined: 2003.06
Post: #2
Oh man... I just went to NeHe and checked out some of the tutorials. Yeah, they're getting pretty old. I would suggest that perhaps the best approach might be to stick to the GLUT examples (don't do the OS X ones). You can get started with GLUT using onesadcookie's GLUT tutorial. Then you might be able to use the GLUT code from the other NeHe tutorials.
Quote this message in a reply
Member
Posts: 67
Joined: 2006.06
Post: #3
Hah, I just went and did the same. And was just thinking about that tutorial but couldn't find it. Thats what I learned OpenGL with, its much much more clear and gooderful and concise and informative.

The machine does not run without the coin.
Quote this message in a reply
Moderator
Posts: 3,579
Joined: 2003.06
Post: #4
Hehe.. "gooderful"... That is mighty truthy of you!
Quote this message in a reply
Moderator
Posts: 613
Joined: 2004.09
Post: #5
Apple has some more up to date OpenGL Sample code, granted its rather hard for a beginner to understand it is still a pretty good start.

http://developer.apple.com/samplecode/Gr...-date.html

On a similar note, why is it almost impossible to find Mac OpenGL stuff that compiles with no warnings/errors?

Kyle Richter
DragonForged.com
Twitter: @kylerichter
Quote this message in a reply
Moderator
Posts: 3,579
Joined: 2003.06
Post: #6
kodex Wrote:On a similar note, why is it almost impossible to find Mac OpenGL stuff that compiles with no warnings/errors?

Good question. It is probably due to all the changes that have occurred to OS X over the years, and the original authors not bothering to update things. Can't say I blame them though since examples are usually free.
Quote this message in a reply
Member
Posts: 281
Joined: 2009.04
Post: #7
Thanks much.

Bytheway, I was 'playing with Scratch' (It's great for noobs to programming) and I thought, hey, I could make a 3D projection program! Smile

3 months later It was still not working MadMadMadWackoBoredZZZ
This made me think what a good job the OpenGL Programmers have done
Quote this message in a reply
Moderator
Posts: 3,579
Joined: 2003.06
Post: #8
Doing 3D graphics from the ground up is quite a massive undertaking, depending on how far you want to take it. OpenGL was built on the shoulders of giants so to speak. There has been much research and experimentation done by many folks which over the decades has led us to where we are now. OpenGL and Direct3D are the two most well-known results.

If you're really curious about how it all comes together, there are many sources of info. These guys have a large collection of resources, which is a companion site to the book. I got the first edition several years ago, but haven't kept up. It's pretty overwhelming.

An in-depth exercise in creating a full 3D software rasterizer is found in the book, Tricks of the 3D Game Programming Gurus. Looks like it's out of print, but available used. It's a massive tome of information on the subject which walks you through the whole process. I made it up to the texturing section.

A vastly simplified, but fun set of tutorials can be found here.

You can find all kinds of other info if you google for 3d software rasterization.
Quote this message in a reply
Member
Posts: 281
Joined: 2009.04
Post: #9
OK, I completed OneSadCookie's tutorial, and now I would like to make it, say, a circle.

Is this right?

Quote: glBegin(GL_QUADS);
// This calls a function to OpenGL telling it to draw a quad?
glVertex2f( 0.0f, 0.0f);
glVertex2f(128.0f, 0.0f);
glVertex2f(128.0f, 128.0f);
glVertex2f( 0.0f, 128.0f);
// and these are the points of the Quad?
glEnd();
// So that's like the end of the quad?
glPopMatrix();
// Pop? I've read about 'popping' things from the CPU stack ZZZ

So If that drew a square, should I replace "(GL_QUADS)" with say, "(GL_CIRCLE)"? and If I did, what should the 'glVertex2f(etc);' be? I mean, should I tell the function the centrepoint and diameter, or the four corners?
Oh yes, what's the 'glVertex2f' for?
Quote this message in a reply
Moderator
Posts: 3,579
Joined: 2003.06
Post: #10
At this point, now that you can get GLUT running, you should look to the NeHe tutorials and the "Red Book" for further guidance. There are a lot of questions you'll have, in addition to the ones you just asked.

I'll offer a few quick answers here:

glBegin(GL_QUADS);

Tells OpenGL that the next set of data you will be sending it will be for making quads. It expects that you will be sending data formatted so that there are four vertices for each quad.

glVertex2f( 0.0f, 0.0f);
glVertex2f(128.0f, 0.0f);
glVertex2f(128.0f, 128.0f);
glVertex2f( 0.0f, 128.0f);

Those are the four vertices. Next you call

glEnd();

To tell OpenGL that your done specifying data for the quad.

There is no GL_CIRCLE. If you hold down the command key and double click on GL_QAUDS, it will reveal the primitive types available to you in the gl.h header.

Code:
#define GL_POINTS                         0x0000
#define GL_LINES                          0x0001
#define GL_LINE_LOOP                      0x0002
#define GL_LINE_STRIP                     0x0003
#define GL_TRIANGLES                      0x0004
#define GL_TRIANGLE_STRIP                 0x0005
#define GL_TRIANGLE_FAN                   0x0006
#define GL_QUADS                          0x0007
#define GL_QUAD_STRIP                     0x0008
#define GL_POLYGON                        0x0009

What you would want to do to make a circle is probably use a triangle fan. Then you use a little trigonometry to specify vertices evenly spaced around the central vertex. It's pretty easy, but you should study up on how to use the other primitives first by studying up at NeHe or reading the Red Book. You can also use glu quadrics, although I don't personally use them myself.

glPopMatrix(); is what you would call somewhere after a call to glPushMatrix();. Yes, it is a stack, but it is a stack of matrices. The current matrix determines how all those vertices you specified will be transformed mathematically in 3D space. Calling push will copy the current matrix and push it onto a new layer in the stack. That way you can modify it by adding another transform to it or even clear it, and then pop it when your done to back up to where you were. You will need to study up some more to learn exactly how these transformations are handled.

The "2f" at the end of glVertex2f is an OpenGL notation standard which means 2 floats. If it were glVertex3f it would expect 3 floats. Again, reading the Red Book will explain this clearly.
Quote this message in a reply
Moderator
Posts: 3,579
Joined: 2003.06
Post: #11
I should add: You are at the beginning of the steepest part of the learning curve for OpenGL. This stuff is *really* hard for beginners to pick up, so don't feel bad about not "getting it" right now. Wink

Also, not to add to your confusion, but I should mention that most of the stuff you're learning right now with glBegin/glEnd and glPushMatrix/glPopMatrix (along with glTranslate, glRotate and glScale) will supposedly not be around in future versions of OpenGL. Further, many of those primitive types listed in my previous post aren't available in OpenGL ES, which is the version of OpenGL used on iPhone. Heck, iPhone doesn't even support glBegin/glEnd! Wuh?! You heard me right, you're learning stuff now that is already slated to be obsolete -- like as if it weren't hard enough to learn already!

Okay, so now you know that. But, I will say that it is good to learn what you're learning because there is an enormous amount of code out there using it, which you will need to reference in the future, so you'll need to know it anyway.

So my advice, as you're learning OpenGL is to be particularly enthusiastic about tutorials which explain how to use glDrawArrays and glDrawElements, and VBOs later too, since those are going to be standard moving forward.
Quote this message in a reply
Post Reply