Jump to content

[SOLVED] Drawing lines using FFP


photo

Recommended Posts

Posted

Hi, I'm trying to draw line primitives using FFP.

 

I've been following the FFP demo under the systems folder, so I made a plugin, added it to my engine.

 

It seems the best I can do is to get a white box to draw for one frame and then they go away.

 

Help?  Thanks

 

I replaced the ::render method in the FFP demo with the code below.  Like I said, I see a white box for one frame or so and then its gone...like it's overdrawn by my scene or something.

 

void render(float time) {
 
App *app = App::get();
Ffp *ffp = Ffp::get();
 
// screen size
int width = app->getWidth();
int height = app->getHeight();
 
ffp->enable(Ffp::MODE_SOLID);
ffp->setOrtho(width, height);
 
ffp->beginLines();
ffp->addLines(4);
 
ffp->addVertex(0, 0, 0);
ffp->setColor(1.0f, 1.0f, 1.0f, 1.0f);
ffp->addVertex(0, 100, 0);
ffp->addVertex(100, 100, 0);
ffp->addVertex(100, 0, 0);
ffp->addIndex(0);
ffp->addIndex(1);
ffp->addIndex(1);
ffp->addIndex(2);
ffp->addIndex(2);
ffp->addIndex(3);
ffp->addIndex(3);
ffp->addIndex(0);
 
ffp->endLines();
 
ffp->disable();
}
Posted

Also trying out ObjectDynamic after further research indicates that this class is also supposed to help draw lines.  However, I don't see any documentation or examples anywhere.  And the only forum entries I see say something like "Use ObjectDynamic" so I really have no idea how to do this.  After poking around for a while, this is what I came up with.  

 

However, once again, it doesn't work.  Am I doing something wrong here?  For now, I'm simply trying to draw a square at the origin.

 

linesNode = ObjectDynamic::create(0);
linesNode->setMaterial("ice_matte", "*");
linesNode->setProperty("surface_base", "*");
 
// points rendering mode
linesNode->setSurfaceMode(ObjectDynamic::MODE_LINES, 0);
linesNode->setInstancing(0);
 
ObjectDynamic::Attribute * attributes = new ObjectDynamic::Attribute[1]
{ { 0, ObjectDynamic::TYPE_FLOAT, 3 }
};
// vertex format
linesNode->setVertexFormat(attributes, 1);
 
// indices
linesNode->addLineStrip(4);
 
linesNode->addVertex(&vec3(0, 0, 0));
linesNode->addVertex(&vec3(0, 0, 1));
linesNode->addVertex(&vec3(1, 0, 1));
linesNode->addVertex(&vec3(1, 0, 0));
linesNode->addVertex(&vec3(0, 0, 0));
 
// bounding box
linesNode->setBoundBox(Unigine::BoundBox(vec3(-1, -1, -1), vec3(1, 1, 1)));
Posted

Hi Joseph,

 

I replaced the ::render method in the FFP demo with the code below.  Like I said, I see a white box for one frame or so and then its gone...like it's overdrawn by my scene or something.

It seems that I can't reproduce such behavior on my side. I can see the white 2D box at the top left corner all the time.

 

For lines rendering you also can use built-in profiler functions (renderLine2D() / renderLine3D and so on): https://developer.unigine.com/en/docs/2.1.1/cpp_api/reference/api_visualizer_class

 

Also trying out ObjectDynamic after further research indicates that this class is also supposed to help draw lines.  However, I don't see any documentation or examples anywhere.

You can check C++ API sample at Nodes -> Objects sample. It shows how to consturct and modify mesh in runtime. Also, there are bunch of UnigineScript samples available in <SDK>/data/samples/objects/dynamic_**.

 

Thanks!

How to submit a good bug report
---
FTP server for test scenes and user uploads:

Posted

Ok, this is interesting.  If I make the box move -- it shows up, but if it's still it disappears.  It looks to me like the color buffer is getting cleared, but not the depth buffer.  Why wouldn't the depth buffer get cleared?  I'm not talking about the depth buffer for the regular 3D scene, just for 2D lines.

 

 

We are calling this in our update loop:

 

engine->update();

engine->render();

engine->swap();

 

Am I missing something?  This seems to be how the demos are doing it.

 

Note also, everything in 3d shows up fine, it's just the lines that have this strange behavior.

 

Also, I imagine using a mesh is best for lines instead of Ffp or the Visualizer.  Are there performance drawbacks to using Ffp or the Visualizer?  In then end, I'll probably need to draw anywhere between 0 and several hundred lines in 3D.

 

-- Update --

 

I've also tried drawing lines in 3D using the visualizer, both in c++ and in script.  Neither seem to draw anything at all.  The only success I've had so far is with 2D lines using Ffp, but as I said, that only works when you draw where you haven't drawn before.  (The depth buffer clearing problem).

 

Here is my update function from my script code where I'm drawing a few lines at the origin.  Nothing is showing up at the origin.  I could really use some help with this.

 

int update()
{
Player player = engine.game.getPlayer();
if (player != NULL)
{
 
// 1. Get the player's projection and model-view matrices for the current frame.
mat4 projection = player.getProjection();
mat4 modelview = player.getModelview();
 
// 2. Update the projection and model-view matrices used by the visualizer.
engine.visualizer.setProjection(projection);
engine.visualizer.setModelview(modelview);
 
// 3. Call a rendering function.
engine.visualizer.renderLine3D(dvec3(0,0,0), dvec3(1.0, 0.0, 0.0), dvec4(1,1,1,1));
engine.visualizer.renderLine3D(dvec3(1, 0, 0), dvec3(1.0, 0.0, 1.0), dvec4(1, 1, 1, 1));
engine.visualizer.renderLine3D(dvec3(1, 0, 1), dvec3(1.0, 1.0, 1.0), dvec4(1, 1, 1, 1));
engine.visualizer.renderLine3D(dvec3(1, 1, 1), dvec3(0.0, 1.0, 1.0), dvec4(1, 1, 1, 1));
}
 
return 1;
}
Posted

Hi Joseph,

 

I've also tried drawing lines in 3D using the visualizer, both in c++ and in script. 

 

Please, make sure that visualizer is enabled: type show_visualizer 1 command in console and press Enter.

How to submit a good bug report
---
FTP server for test scenes and user uploads:

Posted

Ah ha!  That works!  Probably should put that in the Visualizer documentation where I copied that code from.

 

Oh, and back to a question I posted earlier.  Wouldn't it still be better to use ObjectDynamic?  I imagine that uses a vertex buffer and so is faster.  I imagine using this for line drawing is kind of slow, especially if I'm going to draw a lot of lines.

 

--Update--

 

One more question.  This works from script, but if I move the same code to the C++ side it doesn't work.  From script, I added the line engine.visualizer.setEnabled(1), however, in C++, if I have the same code but call visualizer->setEnabled(1), it doesn't show.  However, it does work if I execute the console command show_visualizer 1.  So what's up with that?

 

Visualizer *visualizer = Visualizer::get();
// visualizer->setEnabled(1);  //doesn't work in c++, but does work from script
Console::get()->run("show_visualizer 1");  //does work in c++
visualizer->renderLine3D(dvec3(0, 0, 0), dvec3(1, 1, 1), vec4(1, 1, 1, 1));
×
×
  • Create New...