#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'
> 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
--
> 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?
> 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?
> 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
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.
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.
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
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
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?
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."
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.