Reputation: 85
When I run this code, the console shows "invalid value" as error. I researched in my books but did not find how to solve it. They don't even mention what this value is about. I imagine that it would be address number stored in the pointer returned by gluNewQuadric
that can be out of range of the type GLUquadric, but have no way to make sure or either fix it
#include <stdio.h>
#include <stdlib.h>
#include <GL/glut.h>
#ifndef CALLBACK
#define CALLBACK
#endif
void CALLBACK erro(GLenum coderro)
{
const GLubyte *estring;
estring=gluErrorString(coderro);
fprintf(stderr, "Erro de quadrica: %s\n", estring);
exit(0);
}
void tela ()
{
GLUquadric *quadrica;
glClearColor(1.0, 1.0, 1.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-30.0, 30.0, -30.0, 30.0, 1, 100);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslated(0.0, 0.0, -20.0);
glColor3f(1.0, 0.0, 0.0);
quadrica=gluNewQuadric();
gluQuadricCallback(quadrica, GLU_ERROR, erro);
gluQuadricDrawStyle(quadrica, GLU_FILL);
gluDisk(quadrica, 0.0, 5.0, 1, 1);
glFlush();
}
int main (int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode( GLUT_SINGLE | GLUT_RGB );
glutInitWindowSize(500, 500);
glutCreateWindow("Tesselacao");
glutDisplayFunc(tela);
glutMainLoop();
}
Upvotes: 1
Views: 83
Reputation: 210968
See the specification of gluDisk
:
void gluDisk( GLUquadric* quad, GLdouble inner, GLdouble outer, GLint slices, GLint loops);
Parameters
[...]
slices
Specifies the number of subdivisions around the z axis.
This means slices
has to be at least 3, because to generate a shape, at least 3 points around the disk are necessary.
e.g.
gluDisk(quadrica, 0.0, 5.0, 3, 1);
will generate a triangle and
gluDisk(quadrica, 0.0, 5.0, 5, 1);
will generate a pentagon.
Upvotes: 2
Reputation: 19120
If you run this in a debugger and set a breakpoint at erro
, you'll find something like this (output from GDB):
Breakpoint 1, erro (coderro=100901) at test.c:12
12 estring=gluErrorString(coderro);
(gdb) bt
#0 erro (coderro=100901) at test.c:12
#1 0xf7dd7782 in gluQuadricError (qobj=0x81ddb70, which=100901) at src/libutil/quad.c:81
#2 0xf7dd85ad in gluPartialDisk (qobj=0x81ddb70, innerRadius=0, outerRadius=5, slices=1, loops=1, startAngle=0, sweepAngle=360) at src/libutil/quad.c:450
#3 0xf7dd84c8 in gluDisk (qobj=0x81ddb70, innerRadius=0, outerRadius=5, slices=1, loops=1) at src/libutil/quad.c:427
#4 0x08048af2 in tela () at test.c:36
#5 0xf7f72da8 in fghRedrawWindow () from /usr/lib/libglut.so.3
#6 0xf7f72df3 in fghcbDisplayWindow () from /usr/lib/libglut.so.3
#7 0xf7f77a90 in fgEnumWindows () from /usr/lib/libglut.so.3
#8 0xf7f72e47 in fghDisplayAll () from /usr/lib/libglut.so.3
#9 0xf7f73f39 in glutMainLoopEvent () from /usr/lib/libglut.so.3
#10 0xf7f73f97 in glutMainLoop () from /usr/lib/libglut.so.3
#11 0x08048b52 in main (argc=1, argv=0xffffd4e4) at test.c:48
So, the error comes from gluDisk
. Now a simple attempt to play with its parameters lets me guess that the culprit is slices=1
, which indeed doesn't make sense. Setting it to e.g. 2
avoids getting into the error callback.
Upvotes: 0