floats and glVertex3f()

i have a doubt about to use floats and glVertex3f().

i have a simple function like this :

void disegna_cubo ( float height)
{
glBegin(GL_QUADS);
glVertex3f(0.0f,0.0f,0.0f);
glVertex3f(1.0f,0.0f,0.0f);
glVertex3f(1.0f,height,0.0f);
glVertex3f(0.0f,height,0.0f);
glEnd();
}

in the header its declared as :
void disegna_cubo ( float height) ;

If from main i call :
disegna_cubo (10.0f);

nothing is drawn.

BUT if i change the type parameter “height” from float to int ( both in header and source --> so i have “void disegna_cubo ( int height)”) and call the function like :

disegna_cubo (10);

all works correctly.

so someone can suppose where is my fault or point me in the right direction ?

NOTE : im under mandrake 9.2 and im compiling with gcc and standard flags after putting my source files:
sdl-config --cflags --libs -lSDL_net -lSDL_mixer -lGL -lm -lGLU -I/usr/X11R6/include/ -L/usr/X11R6/lib

thanks in advance.

Alberto Glarey

Ciao Alberto,

the code you posted seems correct to me. BTW, are you rendering the cube under Perspective or Ortho View?

Cheers,
CeccO

im using gluPerspective(…)

I would be curious what happens if you write

glVertex3f(1.0f, float(height), 0.0f);
glVertex3f(0.0f, float(height) ,0.0f);

and then use the int variety.

unfortunatly nothing happen.
i mean no compile errors, but nothing is drawn.

i have already tried that.
(usually i use , (float)myvar , )

Originally posted by honny:
[b] i have a doubt about to use floats and glVertex3f().

i have a simple function like this :

void disegna_cubo ( float height)
{
glBegin(GL_QUADS);
glVertex3f(0.0f,0.0f,0.0f);
glVertex3f(1.0f,0.0f,0.0f);
glVertex3f(1.0f,height,0.0f);
glVertex3f(0.0f,height,0.0f);
glEnd();
}

in the header its declared as :
void disegna_cubo ( float height) ;

If from main i call :
disegna_cubo (10.0f);

nothing is drawn.

BUT if i change the type parameter “height” from float to int ( both in header and source --> so i have “void disegna_cubo ( int height)”) and call the function like :

disegna_cubo (10);

all works correctly.

so someone can suppose where is my fault or point me in the right direction ?

NOTE : im under mandrake 9.2 and im compiling with gcc and standard flags after putting my source files:
sdl-config --cflags --libs -lSDL_net -lSDL_mixer -lGL -lm -lGLU -I/usr/X11R6/include/ -L/usr/X11R6/lib

thanks in advance.

Alberto Glarey[/b]

Shot in the dark but if it were interpreting 10.f as a negative number, your winding would be clockwise instead of counter clockwise.

Originally posted by honny:
BUT if i change the type parameter “height” from float to int ( both in header and source --> so i have “void disegna_cubo ( int height)”) and call the function like :

And then you use glVertex3i, right?..

to JRW :
height is always a positive number between 0.0f and 100.0f

to Orzech :
no, i change only the input paramenter type function:

//from original (not working ):
void disegna_cubo ( float height ) ;

//to the new ( currently working ):
void disegna_cubo ( int height ) ;

inside the function “disegna_cubo” ( and inside ALL the rendering code ) i use glVertex3f(…)

[This message has been edited by honny (edited 01-04-2004).]

honny your code looks ok to me so I suspect a compiler fault.

Have you checked http://gcc.gnu.org/bugzilla/ yet?

For instance this bug sounds similar to yours:
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12007

Have you printed out the value of height in the function or looked at it with a debugger ? is it correct or messed up ?

Mikael

Originally posted by honny:
[b]to Orzech :
no, i change only the input paramenter type function
inside the function “disegna_cubo” ( and inside ALL the rendering code ) i use glVertex3f(…)
B]

Hmmm… Does OpenGL cast from float to integer automatically?

OpenGL does not cast anything, the compiler does.

Originally posted by Orzech:
Hmmm… Does OpenGL cast from float to integer automatically?

Since GLFloat is just a typedef of float (on all systems I know) the compiler will do the conversion for you.

Originally posted by mikael_aronsson:
OpenGL does not cast anything, the compiler does.

Ah yes! I see… I rememered about it just after posting the message. Nevermind.