Horde3D

Next-Generation Graphics Engine
It is currently 28.03.2024, 10:10

All times are UTC + 1 hour




Post new topic Reply to topic  [ 9 posts ] 
Author Message
PostPosted: 21.10.2012, 15:38 
Offline

Joined: 21.10.2012, 15:32
Posts: 18
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.


Top
 Profile  
Reply with quote  
PostPosted: 22.10.2012, 17:53 
Offline

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



Top
 Profile  
Reply with quote  
PostPosted: 23.10.2012, 13:15 
Offline

Joined: 21.10.2012, 15:32
Posts: 18
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



Top
 Profile  
Reply with quote  
PostPosted: 23.10.2012, 19:25 
Offline

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


Top
 Profile  
Reply with quote  
PostPosted: 24.10.2012, 04:23 
Offline

Joined: 21.10.2012, 15:32
Posts: 18
Thanks again for your patient explanation.


Top
 Profile  
Reply with quote  
PostPosted: 24.10.2012, 06:42 
Offline

Joined: 21.10.2012, 15:32
Posts: 18
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.


Top
 Profile  
Reply with quote  
PostPosted: 24.10.2012, 06:49 
Offline
Tool Developer

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


Top
 Profile  
Reply with quote  
PostPosted: 24.10.2012, 10:42 
Offline

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


Top
 Profile  
Reply with quote  
PostPosted: 24.10.2012, 14:49 
Offline

Joined: 21.10.2012, 15:32
Posts: 18
Thanks for your help! Irdis and Volker

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


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

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 30 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