Question on GL_LINES
by Toks · in Torque Game Engine · 08/25/2007 (12:04 am) · 8 replies
Hi,
can someone explain me how GL_LINES work?
im trying to add some "bullet tracers" so to say. the catch is, I cant just add some lines in Projectile::renderObject (which i DID get to work). because i want to be able to see the line even when i cant see my projectile (in the first place because it looks a bit strange that when you are looking at a line, then the projectile leaves your screen and the line just disappears).
when i try to draw lines anywhere else than renderObject, nothing much seems to happen (or maybe the line disappears so quickly that I dont see it, i dont know). by the way, im trying to draw lines like this:
whereas start and end are valid points in the game world obviously.
Its not really a wonder its not working, since im not entirely sure what im doing (it just worked when i placed it in renderObject like the "Bullet Tracers" tutorial), but I cant find good documentation on this explaining how it works, and under what conditions it works.
can someone educated help me please ? :)
can someone explain me how GL_LINES work?
im trying to add some "bullet tracers" so to say. the catch is, I cant just add some lines in Projectile::renderObject (which i DID get to work). because i want to be able to see the line even when i cant see my projectile (in the first place because it looks a bit strange that when you are looking at a line, then the projectile leaves your screen and the line just disappears).
when i try to draw lines anywhere else than renderObject, nothing much seems to happen (or maybe the line disappears so quickly that I dont see it, i dont know). by the way, im trying to draw lines like this:
glLineWidth(2.5); glBegin(GL_LINES); glColor3f(1, 0, 0); glVertex3f(start.x, start.y, start.z); glVertex3f(end.x, end.y, end.z); glEnd(); glLineWidth(.1f);
whereas start and end are valid points in the game world obviously.
Its not really a wonder its not working, since im not entirely sure what im doing (it just worked when i placed it in renderObject like the "Bullet Tracers" tutorial), but I cant find good documentation on this explaining how it works, and under what conditions it works.
can someone educated help me please ? :)
#2
08/26/2007 (5:42 am)
Ok, so im rendering the lines (if anyone reads this ) from RenderObject now. Ive updated the mObjBox to ensure it begin drawn, but its not perfect. when I make the mObjBox even bigger the projectile (nor the lines) render AT ALL. why is this? (i heard someone talking about setting the box to infinite? how would i do that? when the values exceed 50 or something my object does not render anymore)
#3
08/26/2007 (10:15 am)
The reason you do not see the object when drawn from other objects is because it is getting overwritten before it is drawn. You need to draw during the functions that are designed for drawing. renderObject is one such function. You should be using flags or variables to determine if the line is drawn and where. Possibly you should create an entirely new object that is created and lives and dies according to some rules. That will make it so the object is drawn in its on renderObject function. If you make it a sim object then you can even script it into and out of existence.
#4
and I also tried making another object for this, but when I give this object a renderObject function, how does that get called? all that went through renderScene in sceneGraph right? how should I add this new object to the scene?
08/26/2007 (10:19 am)
Ok thank you, is there like a list telling me which functions are suitable for this, or can someone tell me?and I also tried making another object for this, but when I give this object a renderObject function, how does that get called? all that went through renderScene in sceneGraph right? how should I add this new object to the scene?
#5
I think the standard function is renderObject for rendering most any object. I would recommend you get familiar with the entire class hierarchy in the engine before you attempt to create your own object. There are also some example objects that will show you where to start with a visual only object. I want to say fxsunlight or some such, but am not sure if that is an example object or not.
Starting at the player object and working your way backwards should give you an idea of how things are built. When you get the player object look for its parent which is shapebase. Then look at the parent for shapebase and so forth. As you step backwards through the code pay attention to what is added at each step. This will help you understand how things are structured. This is very important to get this down if you are going to ever create a properly networked object. Don't be intimidated by it, just take it one step at a time.
Here is a resource:
tdn.garagegames.com/wiki/Torque_Game_Engine#coder
08/26/2007 (11:08 am)
There is a class hierarchy that defines what is called when. If you create an object based upon the gamebase or shapebase objects (maybe something further up for a visual object) the renderObject function will get called by the engine itself.I think the standard function is renderObject for rendering most any object. I would recommend you get familiar with the entire class hierarchy in the engine before you attempt to create your own object. There are also some example objects that will show you where to start with a visual only object. I want to say fxsunlight or some such, but am not sure if that is an example object or not.
Starting at the player object and working your way backwards should give you an idea of how things are built. When you get the player object look for its parent which is shapebase. Then look at the parent for shapebase and so forth. As you step backwards through the code pay attention to what is added at each step. This will help you understand how things are structured. This is very important to get this down if you are going to ever create a properly networked object. Don't be intimidated by it, just take it one step at a time.
Here is a resource:
tdn.garagegames.com/wiki/Torque_Game_Engine#coder
#6
08/27/2007 (8:21 am)
As a specific answer to the problem of the line disappearing when the bullet does, the thing is that the line is being drawn when the bullet is being rendered. If the bullet goes behind a hill or something, then it isn't being rendered, so your line isn't either. A solution might be to fin out where the engine code figures out what objects to render or not. When it checks bullets, check whether the line can be seen, instead of whether the bullet itself can be seen.
#7
also if you dont want to write a new object you can just enlarge the mObjBox, which should make it render even when you dont see the shape itself, as long as you can see the box around it. question about this though: when i set my box too large, the projectile doesnt render at all, why is that?
08/27/2007 (11:39 am)
Well, I kinda figured that the line disappears when the projectile does since i wrote it from projectile::renderObject(). my question was why I only can draw lines in specific functions. Though i havent really got an answer to that, the resource Frank posted the link of is very useful to get it render right.also if you dont want to write a new object you can just enlarge the mObjBox, which should make it render even when you dont see the shape itself, as long as you can see the box around it. question about this though: when i set my box too large, the projectile doesnt render at all, why is that?
#8
The reason you not see the object being drawn outside the onRender function is probably multiple reasons. One could be it is just overwritten by another objects information. Another could be writing to the wrong buffer in a double buffer scheme. Writing OpenGL applications is a pipeline process. Try to insert the data at the wrong time and it may not get into the pipe. The onRender function may have functions in the parent that setup the view space as well. To really tell you would probably have to go through all the onRender functions to determine what the order of operations the engine is performing before it finally flips the double buffer to make it viewable.
Another thing that may affect if an item is drawn correctly is where the data is coming from to draw the lines. If it is networked, but not being updated fast enough it will cause really strange glitches. I ran into this trying to visualize what my physics were doing in my hover vehicles.
08/27/2007 (8:48 pm)
Maybe the box leaves the current world space. I can't remember what it is called, but the world is divided up into chunks of areas that are searched to determine if they are going to be drawn or not. They also provide collision information to determine objects that could collide. If the object is really large it will be in a larger group that is kind of like a "all objects to big to fit into that space". So maybe it is moving to a different space even though it should be viewable it is not. The reason you not see the object being drawn outside the onRender function is probably multiple reasons. One could be it is just overwritten by another objects information. Another could be writing to the wrong buffer in a double buffer scheme. Writing OpenGL applications is a pipeline process. Try to insert the data at the wrong time and it may not get into the pipe. The onRender function may have functions in the parent that setup the view space as well. To really tell you would probably have to go through all the onRender functions to determine what the order of operations the engine is performing before it finally flips the double buffer to make it viewable.
Another thing that may affect if an item is drawn correctly is where the data is coming from to draw the lines. If it is networked, but not being updated fast enough it will cause really strange glitches. I ran into this trying to visualize what my physics were doing in my hover vehicles.
Torque Owner Toks
what conditions are there to this drawing?