PDA

View Full Version : Lines



nergal
10-22-2002, 02:46 AM
if I write this code (last in post) in other file than main file and its header file is included in main file, why doesn't the code work in the included file but it works when it's written inside main file under the renderscene function.
::Code::
void createRoomLines(float langd, float hojd, float bredd)
{
int i;
float y=0.0;
glPushMatrix();
for(i =0;i<=20;i++){
glBegin(GL_LINES);
glColor3f(cos(i), cos(pow(i,2)), cos(sqrt(i)));
glVertex3f(sin(sqrt(i/100)), tan(i-10), tan(sqrt(i)));
glColor3f(cos(i), cos(i), cos(i));
glVertex3f(tan(i), i, i);
glEnd();
}
glPopMatrix();
}
::code_end::

If I call this function with parameters from the renderscene function (using glut), then it does not draw, but If I write the same code inside the renderscene function it works. why?

blood.angel
10-22-2002, 03:06 AM
HAve you included glut.h in the file as well as the main one?

coredump
10-22-2002, 03:16 AM
show your code from your render routine.

b

[This message has been edited by coredump (edited 10-22-2002).]

nergal
10-22-2002, 04:45 AM
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
createRoomLines(1.0f, 0.0f, 0.0f); //some value to pass to the function
glPopMatrix();
glutSwapBuffers();


The values that I send have nothing to do with the function above cause they are not implemented yet.

blood.angel
10-22-2002, 06:29 AM
Why are you bothering to pass parameters if they are not used?

coredump
10-22-2002, 08:41 AM
hmmm...that looks like some sketchy data you got there...are those trig operation correct? you're gonna get some values greather than 1.0f in your glColor3f calls. just what are you trying to draw anyway? and with the for loop encapsulating your glBegin/glEnd section, you'r just drawing 20 unconnected lines. this may be what you want...not sure :~

b

*Aaron*
10-22-2002, 09:17 AM
First, GL_LINES always draws disconnected lines unless you specify, say, the second and third points to be the same. It's LINE_STRIP and LINE_LOOP that produce connected lines. You could safely take the glBegin() and glEnd() out of the for loop (and this would probably be more efficient.)

Second, it is OK to pass color values out of the range [0,1]; they will just be clamped. Besides, this wouldn't cause a problem only when the function is called in a certain place.

What is the matrix mode (GL_PROJECTION, GL_MODEL_VIEW, etc.)? Implementations are only required to provide a stack depth of 2 for the PROJECTION, COLOR, and TEXTURE matrices. You are pushing the matrix in the render routine and again in createRoomLines. If you are indeed overflowing the PROJECTION matrix stack, you should be getting an error of GL_STACK_OVERFLOW when the function is not working. Also, there's no need to push and pop a matrix if you're not modifying it, and you are not modifying it in the code you posted.

Always check for GL errors once per render loop, and possibly more when debugging!

nergal
10-22-2002, 02:35 PM
Blood.angel: I used the parameters before I modified the func and are planing to use them later on.

The glColor3f(...); is not the problem (and I know u cant push values over 1.0 but the function takes values greater than 1.0 to be the same as 1.0, I think).
hm, so the problem is that I have glBegin() and glEnd in the loop? hm...but I just call the function, it should work like have it right under renderscene. I can create planes in this way, using function.
(the lines was just a test to get something render at all) :)

*Aaron*
10-22-2002, 06:16 PM
No, the glBegin and glEnd thing is not the problem. It is just bad programming style. I think the problem is that you are overflowing the projection matrix stack, but this is just a guess. Did you check this yet?


I know u cant push values over 1.0 but the function takes values greater than 1.0 to be the same as 1.0, I thinkThis is called clamping.

nergal
10-23-2002, 02:20 AM
hm, bad programming style. Maybe bad OpenGL programming, I'm pretty new on opengl as u see.
" I think the problem is that you are overflowing the projection matrix stack"

How do I check that? Does the matrix stack functions have return values?

Anitox
10-23-2002, 03:37 AM
Make sure you have texturing disabled when you draw the line, otherwise it will be drawn with a texture. This could cause it to not draw the lines.

glDisable(GL_TEXTURE_2D);
createRoomLines();


Anitox

*Aaron*
10-23-2002, 08:55 AM
Nergal, you check for all opengl errors by:

GLenum gl_error = glGetError();

If you overflow a matrix stack, the next call to glGetError will return GL_STACK_OVERFLOW. If there have not been any GL errors since the last call, it will return GL_NO_ERROR. Like I said in my first post, you should check this once per render loop.

I didn't mean that you were a bad programmer, but like you said, it is bad OpenGL programming style to include the glBegin() and glEnd() inside the for loop.

nergal
10-23-2002, 11:40 AM
ah ok....I'll try this.
But the problem I got was that I hadn't used glDisable(GL_TEXTURE_2D);, so now its working :) Thanks all people.