Native OpenGL code inside Ogre

Anything and everything that's related to OGRE or the wider graphics field that doesn't fit into the other forums.
marinogiuse
Gnoblar
Posts: 9
Joined: Fri Jul 25, 2008 11:53 am

Native OpenGL code inside Ogre

Post by marinogiuse »

It's my first post inside this forum, so Hello to all the community! :)

I'm a totally newbye of Ogre, and I'm getting crazy because of this problem.
Is there the possibility of making use of the native OpenGL functions (glVertex, glColor, and so on) inside an Ogre application? I searched deeply inside the documentation and the wiki, and I've found out that using the ManualObject class is possibile to draw an object in a GL-like way.
What if I need to insert some native OpenGL code?

I'm sorry if similar questions has arisen in the past, but I was not able to find anything related.

Thanks a lot
Giuseppe
User avatar
nullsquared
Old One
Posts: 3245
Joined: Tue Apr 24, 2007 8:23 pm
Location: NY, NY, USA
x 11

Post by nullsquared »

glVertex and such are the slow immediate-mode functions which Ogre does not use - you can't use them. Why do you need OpenGL-specific calls? You can do pretty much everything and anything just by using Ogre::RenderSystem (and then you can use the same code for Direct3D, too).
marinogiuse
Gnoblar
Posts: 9
Joined: Fri Jul 25, 2008 11:53 am

Post by marinogiuse »

The reason is that I'developed a DLL capable of receiving, via network, an OpenGL command stream (generated by an OpenGL application) and execute it. So I'd like to import the dll from the Ogre application, in order to draw a mix of what my dll is receiving and what I'm drawing using ogre. My dll's functions execute the native OpenGL commands, and I cannot change this feature.
User avatar
JamesKilton
Halfling
Posts: 87
Joined: Tue Jun 14, 2005 8:21 pm
x 1

Post by JamesKilton »

Highly doubtful you'll be able to have that work with Ogre.

When you say "command stream", do you mean glVertex, glColor, glBegin / glEnd type commands?

Of course the other questions is: why do you want to send drawing commands over the network? That's going to make things even slower than GL immediate mode.
Ogre.rb Project Lead
marinogiuse
Gnoblar
Posts: 9
Joined: Fri Jul 25, 2008 11:53 am

Post by marinogiuse »

Yes, I mean glVertex, glColor, glBegin / glEnd, and so on...
I'd like to visualize part fo the geometry drawn by a generic openGL application, using a tool that intercept and sends the opengl commands performed by that application.
Of course it's slower, but since I don't know a priori how the openGL stream is composed, I'm afraid I cannot act in a different way.

As an idea, is it possible to set a callback on the draw function of an entity, and to perform the native openGL calls inside that callback?

Thanks a lot
Giuseppe
User avatar
Assaf Raman
OGRE Team Member
OGRE Team Member
Posts: 3092
Joined: Tue Apr 11, 2006 3:58 pm
Location: TLV, Israel
x 76

Post by Assaf Raman »

@marinogiuse: This can be done.
I will create a simple demo for you this weekend.
Watch out for my OGRE related tweets here.
marinogiuse
Gnoblar
Posts: 9
Joined: Fri Jul 25, 2008 11:53 am

Post by marinogiuse »

Thanks a lot, really kind! :)
User avatar
cdleonard
Goblin
Posts: 266
Joined: Thu May 31, 2007 9:45 am

Post by cdleonard »

Assaf Raman wrote:@marinogiuse: This can be done.
I will create a simple demo for you this weekend.
Wow!
User avatar
Assaf Raman
OGRE Team Member
OGRE Team Member
Posts: 3092
Joined: Tue Apr 11, 2006 3:58 pm
Location: TLV, Israel
x 76

Post by Assaf Raman »

The trick is how to integrate your openGL code into an existing scene.
You need to add a "Render Queue Listener" to the "Scene Manager".
At the end of the "Render Queue" - you can draw with your own native code.
You need to make sure that the "Render Queue" is not empty - else nothing will be drawn.
I wanted to create a sample for you that demonstrate how to integrate to an existing scene. I inherited the SkyDome demo and added some native openGL code.
I used a "Manual Object" as a reference point to place the native drawing in the scene.
here is my code: NativeRenderSystemCommands.zip. To compile - add to the samples folder like the other samples and add to the ogre solution.

Here is how it looks:
Image

As you can see - the openGL code draws quads.

Hope it helps you.

Post a replay if you need any more help.

If anyone has a better way to do this - I will be happy for comments.

I didn't create the d3d9 and d3d10 part of the sample - does anyone need them also?
Watch out for my OGRE related tweets here.
User avatar
PolyVox
OGRE Contributor
OGRE Contributor
Posts: 1316
Joined: Tue Nov 21, 2006 11:28 am
Location: Groningen, The Netherlands
x 18
Contact:

Post by PolyVox »

Well I personally don't need this, but it's very interesting because I didn't know it could be done. And it's great you took the time to make a sample!

Maybe it belongs on the wiki?
User avatar
Assaf Raman
OGRE Team Member
OGRE Team Member
Posts: 3092
Joined: Tue Apr 11, 2006 3:58 pm
Location: TLV, Israel
x 76

Post by Assaf Raman »

PolyVox wrote:Maybe it belongs on the wiki?
Personally I don’t like code in wiki – I always prefer to have a project + h + cpp files.
But – if anyone wants to turn this into a wiki page – you are welcome.
Watch out for my OGRE related tweets here.
reptor
Ogre Magi
Posts: 1120
Joined: Wed Nov 15, 2006 7:41 pm
Location: Finland
x 5

Post by reptor »

Why not add it to the samples that come in the Ogre3D SDK?
User avatar
Assaf Raman
OGRE Team Member
OGRE Team Member
Posts: 3092
Joined: Tue Apr 11, 2006 3:58 pm
Location: TLV, Israel
x 76

Post by Assaf Raman »

:D too many samples - I don't remember the last time we added a sample to the sdk.
even my Stencil Glow Demo hasn't made it in.
Watch out for my OGRE related tweets here.
User avatar
SunSailor
Gnoll
Posts: 699
Joined: Sun Jan 02, 2005 5:45 pm
Location: Velbert, Germany
x 2
Contact:

Post by SunSailor »

If count is the problem, there surely is the one or other sample in the distribution, which could be removed in favor of such things ;). But in my opinion, there never can be too much samples.
User avatar
DanielSefton
Ogre Magi
Posts: 1235
Joined: Fri Oct 26, 2007 12:36 am
Location: Mountain View, CA
x 10
Contact:

Post by DanielSefton »

We should create a whole new area for storing and accessing demos. There's dozens of demos all over the place that aren't included with Ogre -- which, you can't expect them to be. It would be a nice idea to have them all in one place. :) Just an idea.

Great job btw, I always wondered how Ogre could be used with native code. :)
User avatar
madmarx
OGRE Expert User
OGRE Expert User
Posts: 1671
Joined: Mon Jan 21, 2008 10:26 pm
x 50

Post by madmarx »

This is extremely interesting (I mean the code from M Assaf Raman). I thougt an inherited scenemanager would have been needed. And I realise I was wrong.

Concerning the wiki / codesnippet thing, my suggestion would be to only add link to the corresponding forum thread in the wiki.

Example could be :
wiki -> code snippet -> how to do opengl calls -> put the link to this thread in the page.
marinogiuse
Gnoblar
Posts: 9
Joined: Fri Jul 25, 2008 11:53 am

Post by marinogiuse »

Thanks a lot to all the community!
I'm gonna try the application with my dll.
I'll show you a screenshot when I complete it :)
marinogiuse
Gnoblar
Posts: 9
Joined: Fri Jul 25, 2008 11:53 am

Post by marinogiuse »

It works perfectly!
Many thanks Assaf Raman!
Here's a screenshot of what I've done!

Image

The application on the right comtinuously sends geometry to ogre via an OpenGL stream
reptor
Ogre Magi
Posts: 1120
Joined: Wed Nov 15, 2006 7:41 pm
Location: Finland
x 5

Post by reptor »

There could be separate sample packages.

You only include the most important samples in the Ogre3D package.

Then you can have

- Extra Samples I
- Extra Samples II
- Extra Samples III

et cetera. These would not be buried into the Wiki or into the forums but they would be directly accessible from the Ogre3D download page.

You could group the samples so that the samples that are closely related to each other are in the same package. Like "Lighting samples in package I" and "Animation samples in package II" etc. One package could have different types of samples of course.

You can have a rule that only the samples that come in the Ogre3D package are 'officially' supported and maintained, and the rest of the samples are not so actively maintained. It should probably be a community effort to keep the extra sample packages maintained. So that when compatibility is broken, then a call is made on the forums that "someone needs to fix this, please help to test where the problems are and submit patches" to reduce the burden on the Ogre3D team.

These extra samples should have a "do whatever you want with them" license.
User avatar
Assaf Raman
OGRE Team Member
OGRE Team Member
Posts: 3092
Joined: Tue Apr 11, 2006 3:58 pm
Location: TLV, Israel
x 76

Post by Assaf Raman »

marinogiuse wrote:It works perfectly!
Many thanks Assaf Raman!
Here's a screenshot of what I've done!
...
@Marinogiuse:I was happy to help; your nice screenshot made my day, I always love to see new ways you can use OGRE.
Watch out for my OGRE related tweets here.
User avatar
syedhs
Silver Sponsor
Silver Sponsor
Posts: 2703
Joined: Mon Aug 29, 2005 3:24 pm
Location: Kuala Lumpur, Malaysia
x 51

Post by syedhs »

I think this deserves a place in Ogre demos. It demonstrates a totally different aspect of using Ogre, as what many existing Ogre demos already do. :)

Well maybe few existing demos need to be removed as well - what do you say Sinbad? :wink:
A willow deeply scarred, somebody's broken heart
And a washed-out dream
They follow the pattern of the wind, ya' see
Cause they got no place to be
That's why I'm starting with me
marinogiuse
Gnoblar
Posts: 9
Joined: Fri Jul 25, 2008 11:53 am

Post by marinogiuse »

Just another question...if I swich focus on a different window than the Ogre's one, the Ogre appilication stops rendering. There's a way to disable this "optimization"?
Do I have to open a different thread for this question?

Thanks in advance
Giuseppe

EDIT: lurking into the forum I've seen that this problem has been solved earlier. I've tried to adopt suggested solution, but following the indications, I'm not able to give the focus again to my application...
What I've done is substuting, into the exampleapplication.h file, the line:

Code: Select all

mRoot->startRendering(); //inside the virtual void go(void) function
with

Code: Select all

for(;;){
  mRoot->_fireFrameStarted();
  mRoot->_updateAllRenderTargets();
  mWindow->update();
  mRoot->_fireFrameEnded();
}
did I make something wrong?
User avatar
DanielSefton
Ogre Magi
Posts: 1235
Joined: Fri Oct 26, 2007 12:36 am
Location: Mountain View, CA
x 10
Contact:

Post by DanielSefton »

Code: Select all

if (RenderWindow->isActive()) {
	mRoot->startRendering();
}
else if (RenderWindow->isVisible()) {
	mRoot->startRendering();
}
?
marinogiuse
Gnoblar
Posts: 9
Joined: Fri Jul 25, 2008 11:53 am

Post by marinogiuse »

This way nothing changes respect to the initial application.
AFAIK startRendering() doensn't return until the end of the application... am I worng? In any case I've tried, but nothing changes

Thanks
Giuseppe
User avatar
Assaf Raman
OGRE Team Member
OGRE Team Member
Posts: 3092
Joined: Tue Apr 11, 2006 3:58 pm
Location: TLV, Israel
x 76

Post by Assaf Raman »

I was surprised to discover this much interest in a single demo, so I decided to extend it to also include native d3d9 code in the hope it will help someone in the future.

Here it is: NativeRenderGLAndD3d9.zip
Watch out for my OGRE related tweets here.
Post Reply