Horde3D

Next-Generation Graphics Engine
It is currently 24.11.2024, 05:23

All times are UTC + 1 hour




Post new topic Reply to topic  [ 13 posts ] 
Author Message
PostPosted: 11.12.2009, 21:29 
Offline

Joined: 11.12.2009, 12:59
Posts: 19
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?


Top
 Profile  
Reply with quote  
PostPosted: 13.12.2009, 22:24 
Offline
Engine Developer

Joined: 10.09.2006, 15:52
Posts: 1217
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.


Top
 Profile  
Reply with quote  
PostPosted: 13.12.2009, 22:33 
Offline

Joined: 11.12.2009, 12:59
Posts: 19
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..


Top
 Profile  
Reply with quote  
PostPosted: 14.12.2009, 01:01 
Offline
Engine Developer

Joined: 10.09.2006, 15:52
Posts: 1217
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.


Top
 Profile  
Reply with quote  
PostPosted: 15.12.2009, 09:48 
Offline

Joined: 11.12.2009, 12:59
Posts: 19
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


Top
 Profile  
Reply with quote  
PostPosted: 15.12.2009, 16:00 
Offline
Tool Developer

Joined: 13.11.2007, 11:07
Posts: 1150
Location: Germany
Have you checked the GLWidget source code of the editor? It is also capable of drawing the bounding box of a node.


Top
 Profile  
Reply with quote  
PostPosted: 15.12.2009, 16:11 
Offline

Joined: 11.12.2009, 12:59
Posts: 19
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?


Top
 Profile  
Reply with quote  
PostPosted: 15.12.2009, 16:25 
Offline
Tool Developer

Joined: 13.11.2007, 11:07
Posts: 1150
Location: Germany
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?


Top
 Profile  
Reply with quote  
PostPosted: 15.12.2009, 16:31 
Offline

Joined: 11.12.2009, 12:59
Posts: 19
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...


Top
 Profile  
Reply with quote  
PostPosted: 19.12.2009, 12:15 
Offline

Joined: 11.12.2009, 12:59
Posts: 19
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();


Top
 Profile  
Reply with quote  
PostPosted: 18.04.2010, 17:36 
Offline

Joined: 11.12.2009, 12:59
Posts: 19
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?


Top
 Profile  
Reply with quote  
PostPosted: 01.10.2018, 14:55 
Offline

Joined: 01.10.2018, 00:10
Posts: 1
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?


Top
 Profile  
Reply with quote  
PostPosted: 03.10.2018, 12:05 
Offline

Joined: 17.11.2009, 17:00
Posts: 205
Location: Russia, Moscow
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.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 21 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group