PDA

View Full Version : glut Initialization?



Beju
03-25-2007, 06:52 PM
Hello, I've just started to use OpenGL and I have some problems with GLUT. Here is my piece of code (straight from some tutorial):

void GLCanvas::Render(void)
{
int a;
char b[10][10];

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0.0, 0.0, -15.0);
glRotatef(30.0, 1.0, 0.0, 0.0);
glColor4f(0.3, 0.3, 0.3, 1.0);

glutWireTeapot(3.0);
}The problem is: when I compile this code I'm getting:

freeglut ERROR: Function <glutWireTeapot> called without first calling 'glutInit'.So I've thought I just to use that glutInit function:

glutInit(&amp;a, (char **)b);(My program doesn't use arc or argv and I don't pass any glut command-line arguments so I think it makes no difference what will I use as parameters?)

And now I'm getting this error:

freeglut illegal glutInit() reinitialization attemptAnd I am completely lost here :( So was the glut already initialized or not :confused:

I'll be grateful for any advice.

thinks
03-26-2007, 04:22 AM
You had better show us the code that does the initializing.

Beju
03-26-2007, 07:57 AM
OK. I believe initialization is being done by this piece of code:

void GLCanvas::OnPaint(wxPaintEvent & event)
{

wxPaintDC dc(this);
#ifndef __WXMOTIF__
if (!GetContext()) return;
#endif

SetCurrent();
//init OpenGL once, but after SetCurrent
if (!init)
{
InitGL();
init = true;
}
Render();
glFlush();
SwapBuffers();
event.Skip();
}

Beju
03-26-2007, 08:06 AM
OK, I think I've fixed that by adding GlutInit into this part of code:) But now I have another question: I've tried glutSolidTeapot and it looks ugly, just like a flat bitmap - is it normal (looking at my "settings" above) or something is broken again in my OpenGL?

predaeus
03-27-2007, 12:27 AM
The problem is that the teapot has the same color value everywhere. You can enable lighting to make it appear 3 dimensional, because different areas of the teapot will then be lit in different color tones. You need to specify normals so that OpenGL or you own shader can compute the color value depending on the light's direction. glutSolidTeapot() does automatically provide the normal vectors for this. So just search the web for lighting. Or maybe somebody else here can point you to some good tutorial.