PDA

View Full Version : floats and glVertex3f()



honny
01-03-2004, 01:56 AM
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

CeccOman
01-03-2004, 07:08 AM
Ciao Alberto,

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

Cheers,
CeccO

honny
01-03-2004, 07:17 AM
im using gluPerspective(...)

JanHH
01-03-2004, 08:42 AM
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.

honny
01-03-2004, 01:25 PM
unfortunatly nothing happen.
i mean no compile errors, but nothing is drawn.

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

JRW
01-03-2004, 02:23 PM
Originally posted by honny:
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

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

Orzech
01-04-2004, 06:56 AM
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?...

honny
01-04-2004, 08:28 AM
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).]

Honk
01-04-2004, 08:58 AM
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

mikael_aronsson
01-04-2004, 10:11 AM
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

Orzech
01-05-2004, 08:32 AM
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?

mikael_aronsson
01-05-2004, 10:08 AM
OpenGL does not cast anything, the compiler does.

Honk
01-05-2004, 10:11 AM
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.

Orzech
01-05-2004, 11:53 AM
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. http://www.opengl.org/discussion_boards/ubb/smile.gif