PDA

View Full Version : Glfloat using problem



mini
10-19-2004, 11:16 PM
I can only declare variables of type GLfloat in global scope; if I try to
declare one in a function with limited scope, it says:

'GLfloat' : illegal use of this type as an expression
tournament@126.com

Orzech
10-20-2004, 07:34 AM
That's quite odd. Which compiler do you use? Could post some sample code maybe?

Anyway, you can always use "float" variables since they are exactly the same as "GLfloat". It's only a naming convention.

Hope it helps! :)

mini
10-20-2004, 07:40 PM
thanks for reply.compiler:vc++6,
code sample:
convert(int ii){
GLfloat p00, p10, p00u, p10u,
p01, p11, p01u, p11u,
p00w, p10w, p01w, p11w;
p00 = StartPt_u(ii,1);
p10 = EndPt_u(ii, 1);
p00u = StartTan_u(ii,1);
p10u = EndTan_u(ii,1);
p01 = StartPt_u(ii,2);
p11 = EndPt_u(ii, 2);
p01u = StartTan_u(ii,2);
p11u = EndTan_u(ii,2);

p00w = StartTan_w(ii,1);
p10w = EndTan_w(ii,1);

p01w = StartTan_w(ii,2);
p11w = EndTan_w(ii,2);

GLfloat D[] = {1.0f, 1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 1.0f,
0.0f, 0.33333333333333f, 0.0f, 0.0f,
0.0f, 0.0f, -0.33333333333333f, 0.0f};
glMatrixMode(GL_MODELVIEW);/*only to choose a random matrix to utilize the opengl matrix opertions.*/
glLoadMatrixf(&D[0]);

GLfloat C[] = {p00, p10, p00u, p10u,
p01, p11, p01u, p11u,
p00w, p10w, 0.0f, 0.0f,
p01w, p11w, 0.0f, 0.0f};
......}
here comes a new information:"convert" is a function called to generate the data required to define a Bezier surface using Glmap2.StartPt_u()and the simillar following funtions return a Glfloat element fetched from :
GLfloat P[4][4][3] = {
{{-1.5, -1.5, 4.0}, {-0.5, -1.5, 2.0},
{0.5, -1.5, -1.0}, {1.5, -1.5, 2.0}},
{{-1.5, -0.5, 1.0}, {-0.5, -0.5, 3.0},
{0.5, -0.5, 0.0}, {1.5, -0.5, -1.0}},
{{-1.5, 0.5, 4.0}, {-0.5, 0.5, 0.0},
{0.5, 0.5, 3.0}, {1.5, 0.5, 4.0}},
{{-1.5, 1.5, -2.0}, {-0.5, 1.5, -2.0},
{0.5, 1.5, 0.0}, {1.5, 1.5, -1.0}}
if I put the definition of D[] and C[] in adjacent to
GLfloat p00, p10, p00u, p10u,
p01, p11, p01u, p11u,
p00w, p10w, p01w, p11w;
then no error happens.but in the following code,if function like glMultMatrix is called .Such error info. is given:
warning C4013: 'glMultMatrix' undefined; assuming extern returning int.
while all the necessary header files have determinately been included.

mpan3
10-24-2004, 09:51 AM
So there is NO difference between GLFloat and float?

lgrosshennig
10-24-2004, 12:12 PM
Originally posted by mpan3:
So there is NO difference between GLFloat and float?In theory there could be a difference depending on the platform you are using.

In practice its a typedef to an float for any 32 bit system I ever came across.

lgrosshennig
10-24-2004, 12:18 PM
To the original poster:

I guess that you are "lost in closing parentheses" that means the number of opening brackets doesnt exactly match the number of closing brackets and hence the compiler thinks some of your code is outside of a function while you think its inside.

Carefully check if every opening bracket is matched with an closing bracket at the point you intended too.

mini
10-25-2004, 05:15 PM
I modified the definition as below,and it goes ok:
int i,j;
GLfloat p00 = StartPt_u(ii,1);
GLfloat p10 = EndPt_w(ii,1);
GLfloat p00u = StartTan_w(ii,1);
GLfloat p10u = StartTan_w(ii,2);
GLfloat p01 = EndPt_u(ii, 1);
GLfloat p11 = EndPt_w(ii,2);
GLfloat p01u = EndTan_w(ii,1);
GLfloat p11u = EndTan_w(ii,2);

GLfloat p00w = StartTan_u(ii,1);
GLfloat p10w = StartTan_u(ii,2);

GLfloat p01w = EndTan_u(ii,1);
GLfloat p11w = EndTan_u(ii,2);
GLfloat C[] = {p00, p10, p00u, p10u,
p01, p11, p01u, p11u,
p00w, p10w, 0.0f, 0.0f,
p01w, p11w, 0.0f, 0.0f};
odd enough,isn't it?
I built the work space in a "win32 comsole application" mode.and add a ".c" file to the workspace

mikael_aronsson
10-25-2004, 10:04 PM
Hi !

At the top you say you get a warning about glMultMatrix, this is expected as there is no such function in OpenGL, you have to use glMultMatrixf in your case or glMultMatrixd for doule's

Mikael

mini
10-26-2004, 04:46 AM
Though the question has been soluted ,i still don't know why.

Deiussum
10-26-2004, 09:49 AM
You said you used a ".c" file? In pure C all variables must be declared at the start of a block. In other words, you cannot do the following:


void SomeFunction()
{
CallSomeOtherFunction();

float f = 0.0; // error, not at the start of a block
}Using C++ the above is valid, but it isn't for C. If your file has a .c extension, it will be compiled as C, not C++.

mini
10-26-2004, 09:25 PM
So it is, thank you!
Please refer to
http://www.opengl.org/discussion_boards/cgi_directory/ultimatebb.cgi?ubb=get_topic;f=3;t=012649
for further discussion.