Horde3D
http://www.horde3d.org/forums/

How to use the basic OpenGL function with the Horde3D?
http://www.horde3d.org/forums/viewtopic.php?f=1&t=1734
Page 1 of 1

Author:  jacmy [ 21.10.2012, 15:38 ]
Post subject:  How to use the basic OpenGL function with the Horde3D?

I need to do some basic opengl operation in Horde3D, and as the topic preciously, i add some opengl function like this:

h3dFinalizeFrame();

...//opengl function

h3dClearOverlays();

but it doesn't work, Why?

Could anyone show the details? Thanks.

Author:  Irdis [ 22.10.2012, 17:53 ]
Post subject:  Re: How to use the basic OpenGL function with the Horde3D?

Hi jacmy!
Horde modifies internal OpenGL states to its own needs, so you need to save OpenGL states, draw your stuff and then restore GL states for horde. You can see this in Horde's Editor in GLWidget.cpp (renderEditorInfo function).
Here is a quick ripoff of the file:
Code:
const float* camera = 0;
   // Retrieve camera position...      
   h3dGetNodeTransMats(m_activeCameraID, 0, &camera);   

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

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

   // Save OpenGL States
   glPushAttrib(GL_COLOR_BUFFER_BIT | GL_CURRENT_BIT | GL_DEPTH_BUFFER_BIT | GL_ENABLE_BIT | GL_HINT_BIT | GL_LIGHTING_BIT);
   glDisable(GL_LIGHTING);      
   glDisable(GL_BLEND);
   glMatrixMode( GL_PROJECTION );
   glLoadMatrixf( projMat );
   glMatrixMode( GL_MODELVIEW );
   QMatrix4f transMat( camera );
   glLoadMatrixf( transMat.inverted().x );

// your gl drawing - for example, grid drawing
   glEnable(GL_DEPTH_TEST);       
   if (m_debugInfo & DRAW_GRID)
      drawBaseGrid(camera[12], camera[13], camera[14]);

   glDisable(GL_DEPTH_TEST);       
...
   glPopAttrib(); // Restore old OpenGL States


Author:  jacmy [ 23.10.2012, 13:15 ]
Post subject:  Re: How to use the basic OpenGL function with the Horde3D?

Thanks a lot!

by the way, is it necessary to add some initialization for the extra openGL function?
i add the code, but the shape didn't appear.

Irdis wrote:
Hi jacmy!
Horde modifies internal OpenGL states to its own needs, so you need to save OpenGL states, draw your stuff and then restore GL states for horde. You can see this in Horde's Editor in GLWidget.cpp (renderEditorInfo function).
Here is a quick ripoff of the file:
Code:
const float* camera = 0;
   // Retrieve camera position...      
   h3dGetNodeTransMats(m_activeCameraID, 0, &camera);   

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

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

   // Save OpenGL States
   glPushAttrib(GL_COLOR_BUFFER_BIT | GL_CURRENT_BIT | GL_DEPTH_BUFFER_BIT | GL_ENABLE_BIT | GL_HINT_BIT | GL_LIGHTING_BIT);
   glDisable(GL_LIGHTING);      
   glDisable(GL_BLEND);
   glMatrixMode( GL_PROJECTION );
   glLoadMatrixf( projMat );
   glMatrixMode( GL_MODELVIEW );
   QMatrix4f transMat( camera );
   glLoadMatrixf( transMat.inverted().x );

// your gl drawing - for example, grid drawing
   glEnable(GL_DEPTH_TEST);       
   if (m_debugInfo & DRAW_GRID)
      drawBaseGrid(camera[12], camera[13], camera[14]);

   glDisable(GL_DEPTH_TEST);       
...
   glPopAttrib(); // Restore old OpenGL States


Author:  Irdis [ 23.10.2012, 19:25 ]
Post subject:  Re: How to use the basic OpenGL function with the Horde3D?

I'm sorry, but what do you mean by initialization of the function?
If you use qt then you can draw only in selected functions (initializeGL, paintGL, etc.) and qt adds all necessary headers.
If you use some other drawing framework like sfml then you have to include sfml files like sfmlgraphics.
If you draw with raw gl then you have to include gl.h (and probably glext.h) to your cpp file and, if you are on windows and use functionality higher than opengl 1.1, then you have to get function pointers from opengl.dll. You can see how this is done in horde (utOpenGL.h). Something like:
Code:
// GL 1.2
PFNGLBLENDCOLORPROC glBlendColor = 0x0;
PFNGLBLENDEQUATIONPROC glBlendEquation = 0x0;
PFNGLDRAWRANGEELEMENTSPROC glDrawRangeElements = 0x0;
PFNGLTEXIMAGE3DPROC glTexImage3D = 0x0;
PFNGLTEXSUBIMAGE3DPROC glTexSubImage3D = 0x0;
PFNGLCOPYTEXSUBIMAGE3DPROC glCopyTexSubImage3D = 0x0;
...
void *platGetProcAddress( const char *funcName )
{
#if defined( PLATFORM_WIN )
   return (void *)wglGetProcAddress( funcName );
#elif defined( PLATFORM_WIN_CE )
   return (void *)eglGetProcAddress( funcName );
...
}
...
// GL 1.2
   r &= (glBlendColor = (PFNGLBLENDCOLORPROC) platGetProcAddress( "glBlendColor" )) != 0x0;
   r &= (glBlendEquation = (PFNGLBLENDEQUATIONPROC) platGetProcAddress( "glBlendEquation" )) != 0x0;
   r &= (glDrawRangeElements = (PFNGLDRAWRANGEELEMENTSPROC) platGetProcAddress( "glDrawRangeElements" )) != 0x0;
...


If you meant initialization as getting platform pointers of gl functions, then yes, you should initialize gl functions higher than specified in OpenGL v1.1.

Author:  jacmy [ 24.10.2012, 04:23 ]
Post subject:  Re: How to use the basic OpenGL function with the Horde3D?

Thanks again for your patient explanation.

Author:  jacmy [ 24.10.2012, 06:42 ]
Post subject:  Re: How to use the basic OpenGL function with the Horde3D?

Code:
const float* camera = 0;
   // Retrieve camera position...      
   h3dGetNodeTransMats(m_activeCameraID, 0, &camera);   

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

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

   // Save OpenGL States
   glPushAttrib(GL_COLOR_BUFFER_BIT | GL_CURRENT_BIT | GL_DEPTH_BUFFER_BIT | GL_ENABLE_BIT | GL_HINT_BIT | GL_LIGHTING_BIT);
   glDisable(GL_LIGHTING);      
   glDisable(GL_BLEND);
   glMatrixMode( GL_PROJECTION );
   glLoadMatrixf( projMat );
   glMatrixMode( GL_MODELVIEW );
   QMatrix4f transMat( camera );
   glLoadMatrixf( transMat.inverted().x );

// your gl drawing - for example, grid drawing
   glEnable(GL_DEPTH_TEST);       
   if (m_debugInfo & DRAW_GRID)
      drawBaseGrid(camera[12], camera[13], camera[14]);

   glDisable(GL_DEPTH_TEST);       
...
   glPopAttrib(); // Restore old OpenGL States



I have applied the horde3d with Qt, but after i add the code, it didn't work.

i don't know why..

and for the code
Code:
QMatrix4f transMat( camera );
glLoadMatrixf( transMat.inverted().x );

".x" means the first row? or column?
i found the Qt class QMatrix4x4 only. Thanks.

Author:  Volker [ 24.10.2012, 06:49 ]
Post subject:  Re: How to use the basic OpenGL function with the Horde3D?

Quote:

I have applied the horde3d with Qt, but after i add the code, it didn't work.

i don't know why..

and for the code
Code:
QMatrix4f transMat( camera );
glLoadMatrixf( transMat.inverted().x );

".x" means the first row? or column?
i found the Qt class QMatrix4x4 only. Thanks.

Considering the code for rendering I recommend to debug the code to check that there are valid values in the camera variables.
Regarding QMatrix4x4.x, its the whole matrix, not only a column or a row

Author:  Irdis [ 24.10.2012, 10:42 ]
Post subject:  Re: How to use the basic OpenGL function with the Horde3D?

m_activeCameraID should be your currently used camera id.
About QMatrix4f - it is not a base Qt class, it was created by Volker as a qt implementation of utMath.h Matrix4f class. So you should either copy this class from editor (HordeSceneEditorCore/CustomTypes.h), or use an array of float values. You can also import utMath.h file (Horde3D/Source/Shared) and work with Matrix4f class directly.
You should probably take a look at Qt sample that is in community repository, if you are trying to use horde with qt.

Author:  jacmy [ 24.10.2012, 14:49 ]
Post subject:  Re: How to use the basic OpenGL function with the Horde3D?

Thanks for your help! Irdis and Volker

I've solved the problem and got the right simulation.

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