Horde3D
http://horde3d.org/forums/

HOW TO Draw primitives(lines, curves, spheres etc.)?
http://horde3d.org/forums/viewtopic.php?f=1&t=1027
Page 1 of 1

Author:  DIMEDROLL [ 11.12.2009, 21:29 ]
Post subject:  HOW TO Draw primitives(lines, curves, spheres etc.)?

I want to draw a bounding box of the object when the user clicks on it.
Also it is needed to draw 3d lines and basic 3d objects, like cube, sphere etc.
What is the best way to implement such functionality?

Author:  marciano [ 13.12.2009, 22:24 ]
Post subject:  Re: HOW TO Draw primitives(lines, curves, spheres etc.)?

You can directly use opengl commands after calling the horde rendering functions. See this thread for more information:
http://www.horde3d.org/forums/viewtopic.php?f=1&t=978

However, we are working on a solution that makes it possible to draw debug geometry in an graphics API independent way.

Author:  DIMEDROLL [ 13.12.2009, 22:33 ]
Post subject:  Re: HOW TO Draw primitives(lines, curves, spheres etc.)?

I've seen that thread, it is not helpfull..
can you give an example?
I've tried to modify Knight example like this:
Code:
void Application::mainLoop( float fps )
{
// ...
        h3dRender( _cam );

        glColor3f(1.0f, 1.0f, 1.0f);
   glBegin(GL_LINES);

   glVertex3f(0, 0, 0); // origin of the line
   glVertex3f(0, 10000, 0); // ending point of the line
   glEnd( );
}

and there is nothing visible..

Author:  marciano [ 14.12.2009, 01:01 ]
Post subject:  Re: HOW TO Draw primitives(lines, curves, spheres etc.)?

It is better to do your custom GL calls after h3dFinalizeFrame. You also need to setup the view and projection matrix of your camera, as is shown in Volker's post in the mentioned thread.

Author:  DIMEDROLL [ 15.12.2009, 09:48 ]
Post subject:  Re: HOW TO Draw primitives(lines, curves, spheres etc.)?

ok, I've copied the code from that thread, also I used a Picking tutorial.
What do I want is to click on the Knight(in Horde3d Sample Knight project) and to display its bounding box. I've added such method:
Code:
void Application::pick(float dX, float dY) {
   H3DNode node = h3dutPickNode(_cam, dX, dY);
   //h3dSetNodeActivation(node, false);
   curnode_ = node;
}

In the main loop I do the following:
Code:
void Application::mainLoop( float fps )
{
       // skipped sample code...
   h3dRender( _cam );

   DrawBoundingBox();
}
void Application::DrawBoundingBox() {
   if (curnode_) {
      const float* camera = 0;
      // Retrieve camera position...     
      h3dGetNodeTransMats(_cam, 0, &camera);   

      // In case of an invalid camera (e.g. pipeline not set) return   
      if ( !camera ) return;   

      // ... and projection matrix
      float projMat[16];
      h3dGetCameraProjMat( _cam, projMat );

      // ...

      // Set projection matrix
      glMatrixMode( GL_PROJECTION );
      glLoadMatrixf( projMat );
      // apply camera transformation
      glMatrixMode( GL_MODELVIEW );
      Matrix4f transMat( camera );
      glLoadMatrixf( transMat.inverted().x );

      // then later in e.g. drawGizmo

      glPushMatrix();

      const float *nodeTransform = 0;
      h3dGetNodeTransMats(curnode_, NULL, &nodeTransform);
      glMultMatrixf(nodeTransform);   // Load scene node matrix

      // ... draw code

      float minX, minY, minZ, maxX, maxY, maxZ;
      h3dGetNodeAABB(curnode_, &minX, &minY, &minZ, &maxX, &maxY, &maxZ);
      glColor3f(0.7f, 0.7f, 0.7f);
      glBegin(GL_LINE_STRIP);
      glVertex3f(minX, minY, minZ);
      glVertex3f(maxX, minY, minZ);
      glVertex3f(maxX, maxY, minZ);
      glVertex3f(minX, maxY, minZ);
      glVertex3f(minX, minY, minZ);
      glVertex3f(minX, minY, maxZ);
      glVertex3f(maxX, minY, maxZ);
      glVertex3f(maxX, maxY, maxZ);
      glVertex3f(minX, maxY, maxZ);
      glVertex3f(minX, minY, maxZ);
      glEnd();
      glBegin(GL_LINES);
      glVertex3f(minX, maxY, minZ);
      glVertex3f(minX, maxY, maxZ);
      glVertex3f(maxX, minY, minZ);
      glVertex3f(maxX, minY, maxZ);
      glVertex3f(maxX, maxY, minZ);
      glVertex3f(maxX, maxY, maxZ);
      glEnd();

      glPopMatrix();
   }
}

I still don't see any lines drawn..

May be it's my lack of OpenGL knowledge? Please suggest me good books here:http://www.horde3d.org/forums/viewtopic.php?f=5&t=1032

Author:  Volker [ 15.12.2009, 16:00 ]
Post subject:  Re: HOW TO Draw primitives(lines, curves, spheres etc.)?

Have you checked the GLWidget source code of the editor? It is also capable of drawing the bounding box of a node.

Author:  DIMEDROLL [ 15.12.2009, 16:11 ]
Post subject:  Re: HOW TO Draw primitives(lines, curves, spheres etc.)?

yes,
I've created a Qt Application and made inserted my code there, it works for now, here is it:

Code:
paintGL()
{
    h3dRender(_cameraNode); // Render scene   

    if (cur_) {

        const float* camera = 0;
        h3dGetNodeTransMats(_cameraNode, 0, &camera);   
        if ( !camera ) return;
        float projMat[16];
        h3dGetCameraProjMat( _cameraNode, projMat );
        Matrix4f cam_matrix( camera );
        const float *nodeTransform = 0;
        h3dGetNodeTransMats(cur_, &nodeTransform, NULL);
       
        glMatrixMode( GL_MODELVIEW );
        glPushMatrix();
        glLoadMatrixf(cam_matrix.inverted().x);
        glMultMatrixf(nodeTransform);   // Load scene node matrix
       
        glMatrixMode( GL_PROJECTION );
        glPushMatrix();
        glLoadMatrixf( projMat );

        // ... draw code

        glPopMatrix();
        glMatrixMode( GL_MODELVIEW );
        glPopMatrix();
        }
}


Knight example doesn't work with this code, why?

P.S. Do I correctly push and pop matrices in the code above?

Author:  Volker [ 15.12.2009, 16:25 ]
Post subject:  Re: HOW TO Draw primitives(lines, curves, spheres etc.)?

Depends on what you are doing in your draw code, but it seems to me, that you don't need a push and pop at all. Does the Horde3D rendering part work, if you don't try to render something yourself?
Did you save and restore the OpenGL states?

Author:  DIMEDROLL [ 15.12.2009, 16:31 ]
Post subject:  Re: HOW TO Draw primitives(lines, curves, spheres etc.)?

Horde3D rendering part works fine.
In my draw code I'm drawing the bounding box of the scene node:
Code:
       float minX, minY, minZ, maxX, maxY, maxZ;
        h3dGetNodeAABB(cur_, &minX, &minY, &minZ, &maxX, &maxY, &maxZ);
        glColor3f(0.7f, 0.7f, 0.7f);
        glBegin(GL_LINE_STRIP);
        glVertex3f(minX, minY, minZ);
        glVertex3f(maxX, minY, minZ);
        glVertex3f(maxX, maxY, minZ);
        glVertex3f(minX, maxY, minZ);
        glVertex3f(minX, minY, minZ);
        glVertex3f(minX, minY, maxZ);
        glVertex3f(maxX, minY, maxZ);
        glVertex3f(maxX, maxY, maxZ);
        glVertex3f(minX, maxY, maxZ);
        glVertex3f(minX, minY, maxZ);
        glEnd();
        glBegin(GL_LINES);
        glVertex3f(minX, maxY, minZ);
        glVertex3f(minX, maxY, maxZ);
        glVertex3f(maxX, minY, minZ);
        glVertex3f(maxX, minY, maxZ);
        glVertex3f(maxX, maxY, minZ);
        glVertex3f(maxX, maxY, maxZ);
        glEnd();

I don't do anything else...

Author:  DIMEDROLL [ 19.12.2009, 12:15 ]
Post subject:  Re: HOW TO Draw primitives(lines, curves, spheres etc.)?

at last, here is the final code for setting up OpenGL matrices:
Code:
const float* camera = 0;

        h3dGetNodeTransMats(_cameraNode, 0, &camera);   
        if ( !camera ) return;
        Matrix4f cam_matrix( camera );

        glMatrixMode( GL_MODELVIEW );
        glPushMatrix();
        glLoadMatrixf(cam_matrix.inverted().x);

        float projMat[16];
        h3dGetCameraProjMat( _cameraNode, projMat );
       
        glMatrixMode( GL_PROJECTION );
        glPushMatrix();

        glLoadMatrixf( projMat);
        glMatrixMode( GL_MODELVIEW );

// opengl drawing code

        glMatrixMode( GL_PROJECTION );
        glPopMatrix();

        glMatrixMode( GL_MODELVIEW );
        glPopMatrix();

Author:  DIMEDROLL [ 18.04.2010, 17:36 ]
Post subject:  Re: HOW TO Draw primitives(lines, curves, spheres etc.)?

hi,
everything was good for drawing lines. But there is a problem with an array of vertices/triangles, here is code:

Code:
static float gPlaneData[]={
    -1.0f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f,
    1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, -1.0f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f,
    1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f
};

Code:
   glPushMatrix();
    glScalef(100,100,100);
    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_NORMAL_ARRAY);
    glVertexPointer(3, GL_FLOAT, 2*3*sizeof(float), gPlaneData);
    glNormalPointer(GL_FLOAT, 2*3*sizeof(float), gPlaneData+3);
    glDrawArrays(GL_TRIANGLES, 0, 6);
    glDisableClientState(GL_VERTEX_ARRAY);
    glDisableClientState(GL_NORMAL_ARRAY);

    glBegin(GL_LINES);
    glVertex3f(0,0,0);
    glVertex3f(1,1,1);
    glEnd();

    glPopMatrix();


the line here is drawn correctly, but the plane is invisible

I tried this code on the Qt4 OpeGL Gears example and the plane is visible.

How can I draw arrays of vertices?

Author:  jacwilso [ 01.10.2018, 14:55 ]
Post subject:  Re: HOW TO Draw primitives(lines, curves, spheres etc.)?

I know this is a super old thread, but I've been trying to implement primitives in my version of Horde. I've been using the GLWidget as an example, however the GLWidget is a Qt program and I don't plan on or want to use Qt. I was hoping to do just raw GL. I am using glad (in another part of the software so the GL functions should be loaded -- unless I understand that wrong).

I am able to get the background to change color with the below code, so I know opengl has the context. But when I try calling glBegin/glEnd, the glError returns invalid operator.
Code:
glClearColor(1, 0, 0, 1);
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);


Has anyone done raw gl with horde before if so how?

Author:  Irdis [ 03.10.2018, 12:05 ]
Post subject:  Re: HOW TO Draw primitives(lines, curves, spheres etc.)?

Hi. Horde modifies OpenGL states for itself, so you have to save opengl states and reset them to default before drawing and restore states after drawing. You can find it in void GLWidget::renderEditorInfo() in Horde3D Editor.
Also, Horde is getting pointers to OpenGL functions itself, so, if you are using glad in another part of your program it probably can lead to some problems.

Page 1 of 1 All times are UTC + 1 hour
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/