Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

calling glGetString ( GL_VERSION ) on mac OS X tiger in c xcode project

340 views
Skip to first unread message

anne001

unread,
Jul 26, 2006, 10:06:52 AM7/26/06
to
I can't figure out what include I need to put in to access glGetString

#include <stdio.h>
#include <OpenGL/gl.h>
#include <OpenGL/OpenGL.h>

int main (int argc, const char * argv[]) {
const GLubyte * strVersion = glGetString ( GL_VERSION );
printf("Hello, World!\n");
printf(strVersion);
return 0;
}

runs with a message
unknown symbol '_glGetString'

Wolfgang Draxinger

unread,
Jul 26, 2006, 10:29:39 AM7/26/06
to
anne001 wrote:

> I can't figure out what include I need to put in to access
> glGetString
>
> #include <stdio.h>
> #include <OpenGL/gl.h>
> #include <OpenGL/OpenGL.h>

The Path is not ${includepath}/OpenGL it's ${includepath}/GL

#include <GL/gl.h>

> int main (int argc, const char * argv[]) {
> const GLubyte * strVersion = glGetString ( GL_VERSION );
> printf("Hello, World!\n");
> printf(strVersion);
> return 0;
> }

That won't work. You need a valid OpenGL context to use
glGetString.

Wolfgang Draxinger
--

Rolf Magnus

unread,
Jul 26, 2006, 10:49:00 AM7/26/06
to
anne001 wrote:

> I can't figure out what include I need to put in to access glGetString
>
> #include <stdio.h>
> #include <OpenGL/gl.h>
> #include <OpenGL/OpenGL.h>

Usually, it's <GL/gl.h>

> int main (int argc, const char * argv[]) {
> const GLubyte * strVersion = glGetString ( GL_VERSION );
> printf("Hello, World!\n");
> printf(strVersion);
> return 0;
> }
>
> runs with a message
> unknown symbol '_glGetString'

This looks like a linker error to me. Maybe you forgot to link to the OpenGL
library?

anne001

unread,
Jul 26, 2006, 12:23:47 PM7/26/06
to
my computer does not find GL/gl.h. But for that short code,
#include </Developer/SDKs/MacOSX10.4u.sdk/usr/X11R6/include/GL/gl.h>
is accepted and still does not know glGetString

> That won't work. You need a valid OpenGL context to use

> glGetString.> --

what is a simple valid opengl context?
If I try to compile a more complex code like robot.c I get errors with
the GL/gl.h not found even when I give it the whole path.
what do I need to do to $PATH so opengl code from the red book will
compile in C?

Dave Eberly

unread,
Jul 26, 2006, 12:40:14 PM7/26/06
to
"anne001" <an...@wjh.harvard.edu> wrote in message
news:1153931027....@b28g2000cwb.googlegroups.com...

> If I try to compile a more complex code like robot.c I get errors with
> the GL/gl.h not found even when I give it the whole path.
> what do I need to do to $PATH so opengl code from the red book will
> compile in C?

What the responders have overlooked is that you are
on a *Macintosh OS X* machine. Yes, you access the
standard header files
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
The fact that you indicated your code compiled but had
a linker error is already evidence that you have the
correct #includes :)

I suppose you could try setting up a symbolic link to
create a "GL" folder but it is not clear to me how Apple's
Framework system plays nicely with that.

Since you are probably using Apple-specific information, you
can instead use
#include <AGL/agl.h>
#include <OpenGL/glu.h>
If you are instead planning on using GLUT, you would use
#include <GLUT/glut.h>

The fact that you have a linker error probably means you have
not included the OpenGL (and possibly AGL) frameworks
in your Xcode project.

> what is a simple valid opengl context?

You need to create a rendering context *before* making
calls to OpenGL functions.

For an example of creating a window/renderer using AGL, see
http://www.geometrictools.com/Renderers/OpenGLRenderer/Wm3AglRenderer.cpp
http://www.geometrictools.com/Applications/Wm3AglApplication.cpp
It is quite complicated code, but the relevant portion in the renderer
file is the section with comment "Create an OpenGL context". After
that block of code it is safe to call OpenGL functions, including
glGetString.

--
Dave Eberly
http://www.geometrictools.com


anne001

unread,
Jul 26, 2006, 7:00:20 PM7/26/06
to
Thank you for this information, I will try to get a c code snipet to
run.

I was able to get the ruby opengl hello.c to run, with the glGetString
inbedded in one of the methods running GL fxs.

def init
p "GL::VERSION"
p GL.GetString(GL::VERSION);
GL.ClearColor(0.0, 0.0, 0.0, 0.0);
GL.MatrixMode(GL::PROJECTION);
GL.LoadIdentity();
GL.Ortho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);

end

it printed
"GL::VERSION"
"1.5 ATI-1.4.18"

I was told to use an application called OpenGL Extensions Viewer,
Core features for version 1.5 100% (3/3)
Core features for version 2.0 77% (7/9).

I am told that the limit is my ATI card, and that even with a tiger
upgrade to 4.7, I won't have 100% of opengl 2.0

Just thought I would pass this info on for other mac OS X users who
wondered what they had.

Dave Eberly

unread,
Jul 27, 2006, 12:27:00 AM7/27/06
to
"anne001" <an...@wjh.harvard.edu> wrote in message
news:1153954820.4...@h48g2000cwc.googlegroups.com...

> it printed
> "GL::VERSION"
> "1.5 ATI-1.4.18"

Version 1.5 is more than sufficient for most purposes.
I have a fully shader-based graphics engine that does
not use OpenGL 2.0, instead using previous extensions
that do the job.

anne001

unread,
Jul 27, 2006, 6:25:38 AM7/27/06
to
Yes it was for shaders that I wanted to know where I stand to know what
to try
the two modules that are not supported in 2.0 are
GL_ARB_draw_buffers, and GL_ARB_texture_non_power_of_two.
the GL2.0 GL_ARB_vertex_shader is supported.

Martin Steen

unread,
Jul 27, 2006, 6:07:14 AM7/27/06
to
> I am told that the limit is my ATI card, and that even with a tiger
> upgrade to 4.7, I won't have 100% of opengl 2.0

As long as you don't need vertex- or pixel-shaders, you do fine
with the basic OpenGL 1.2.
As it concerns me, version 1.2 provides everything I need for
my work ;)

Best regards, Martin

Martin Steen

unread,
Jul 27, 2006, 6:01:36 AM7/27/06
to

If "/Developer/SDKs/MacOSX10.4u.sdk/usr/X11R6/include" is the right
path to your include files, you can find the file that contains
glGetString with the command:

grep -r glGetString /Developer/SDKs/MacOSX10.4u.sdk/usr/X11R6/include

OR (shorter)

grep -r glGetString $INCLUDE
(if INCLUDE is set to the right path - type "echo $INCLUDE" to proof)

Use a unix command shell. Knowing some basic unix shell commands can
help solve many problems ;)

Best regards, Martin

anne001

unread,
Jul 28, 2006, 2:03:11 PM7/28/06
to
grep -r glGetString /usr/X11R6/include
/usr/X11R6/include/GL/gl.h:GLAPI const GLubyte* GLAPIENTRY glGetString(
GLenum name );

I am told that GL in X11R6 is just one library for X11, but that you
can use OpenGL with cocoa and some other ways of opening windows.

What do you do after grep?

anne001

unread,
Jul 28, 2006, 2:10:27 PM7/28/06
to
Do you know a good tutorial on how to use OpenGL on OS X.

I found
1. using makefiles
http://www.macdevcenter.com/pub/a/mac/2005/04/01/opengl.html
and I was able to run his example from emacs.

2. http://onesadcookie.com/Tutorials/
which explains how to load frameworks, which is what you were refering
to...

I am hoping to code in ruby, not C, but it would still be good for me
to know how to compile the C examples I find on the web... I had not
seen the AGL/agl.h mentioned... the first site claims that
"The coding examples for the Macintosh are primarily for Cocoa or the
old Mac OS."

Dave Eberly

unread,
Jul 28, 2006, 2:29:36 PM7/28/06
to
"anne001" <an...@wjh.harvard.edu> wrote in message
news:1154110227....@b28g2000cwb.googlegroups.com...

> Do you know a good tutorial on how to use OpenGL on OS X.

I believe Apple's developer web site has plenty of tutorials.

> I found
> 1. using makefiles
> http://www.macdevcenter.com/pub/a/mac/2005/04/01/opengl.html
> and I was able to run his example from emacs.

If you plan on developing in a Unix-like environment, then
sure, use makefiles. However, I recall running into some
problems with the fact that "executables" are really directories
with subdirectories corresponding to resources, having plist
file, and other such stuff. I also recall problems with getting
events hooked-up to the application when using Carbon rather
than Cocoa. Some of this might be my own inexperience with
the Macintosh, but in the end I found it easier just to use Xcode.

> 2. http://onesadcookie.com/Tutorials/
> which explains how to load frameworks, which is what you were refering
> to...
>
> I am hoping to code in ruby, not C, but it would still be good for me
> to know how to compile the C examples I find on the web... I had not
> seen the AGL/agl.h mentioned... the first site claims that
> "The coding examples for the Macintosh are primarily for Cocoa or the
> old Mac OS."

I believe the Macintosh GLUT distribution works with Cocoa for
windowing and events. My own applications and renderer use
Carbon. I know nothing about Ruby. If you want to see a lot
of examples for using OpenGL on Mac OS X, download my graphics
engine and sample applications. Go to my home page, select the
"Source Code" tab. Download the distribution "Wild Magic 3.9".
Read the installation notes. I do provide scripts to compile
everything. However, you can open the Xcode projects in the
order specified: Foundation, AglRenderer, AglApplication. After
you have built these, you can build and run any of the sample
applications. When you open the Xcode project, you will see a
folder that shows the Frameworks that the project uses.

0 new messages