Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Sat Sep 19, 2020 2:40 pm
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 20 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: OpenGLSurface Sample Code
PostPosted: Thu Oct 22, 2009 3:25 pm 
Offline

Joined: Wed May 10, 2006 1:27 pm
Posts: 68
Hi-
I'm wondering if anyone else is having difficulty making the sample project from tinrocket.com work when built from the IDE. The compiled apps that came with the download work great, but when I choose Run in the IDE the window is blank.

Am I missing something?

Running REALstudio 2009r4 on Mac OSX 10.6- but have had the same problem since the debut of OpenGLSurface in 2009r3 and 10.5

_________________
-Sean


Top
 Profile  
Reply with quote  
 Post subject: Re: OpenGLSurface Sample Code
PostPosted: Thu Oct 22, 2009 9:55 pm 
Offline

Joined: Fri Sep 30, 2005 8:39 pm
Posts: 364
Location: Arlington, TX
Are you getting an error of some sort? There are quite a few reasons it may not be working correctly.

_________________
Open Source OpenGL Classes:
Camera (1.1), Light (1.0), Texture (1.2), Font (1.2), Mesh (1.7), Models (1.0)


Top
 Profile  
Reply with quote  
 Post subject: Re: OpenGLSurface Sample Code
PostPosted: Thu Oct 22, 2009 10:16 pm 
Offline

Joined: Wed May 10, 2006 1:27 pm
Posts: 68
No error, just a blank window. Dragging other windows or rolling over the dock (so the icons grow) to force a redraw makes it work in that moment, its working, just not drawing to the window/screen.

_________________
-Sean


Top
 Profile  
Reply with quote  
 Post subject: Re: OpenGLSurface Sample Code
PostPosted: Fri Oct 23, 2009 11:01 am 
Offline

Joined: Fri Sep 30, 2005 8:39 pm
Posts: 364
Location: Arlington, TX
It sounds like you need to put a timer in the window and call the Refresh/Update/Draw method that will draw the actual OpenGL buffer to the screen. I'm not sure which one it is since I don't know the exact details of the control you are using.

_________________
Open Source OpenGL Classes:
Camera (1.1), Light (1.0), Texture (1.2), Font (1.2), Mesh (1.7), Models (1.0)


Top
 Profile  
Reply with quote  
 Post subject: Re: OpenGLSurface Sample Code
PostPosted: Fri Nov 06, 2009 9:23 am 
Offline

Joined: Fri Nov 06, 2009 5:20 am
Posts: 11
The only way I could get it to run was to put an 'OpenGL.glFlush()' call as the last line in the 'Render' method of the 'OpenGLSurface1' control. This 'Render' method is called from inside a loop by the 'FluidField.Run' metehod. glFlush() flushes the pipeline to the display.

There is, though, a big However to this solution... While adding the glFlush() to the Render method makes it run beautifully on a Mac, it give only very slooooooooow frame rates (2 sec/frame) output when compiled for Windows (without the glFlush() Windows gave a total blank.) So something is not exactly right with how OpenGLSurface is configuring its Windows run time. I tried to contact John at TinRocket who basically said to contact RB support. I did open a case about this a couple of days ago and haven't heard back.

Barry


Top
 Profile  
Reply with quote  
 Post subject: Re: OpenGLSurface Sample Code
PostPosted: Fri Nov 06, 2009 1:47 pm 
Offline

Joined: Wed May 10, 2006 1:27 pm
Posts: 68
Actually what fixed it for me is turning on the double buffering property, which was false by default. I'm no expert on OpenGL, but I have to imagine though that this is equally inefficient.

Did you open the case in the Feedback system? I couldn't find much of anything about OpenGLSurface there; aside from a report that the documentation sucks.

_________________
-Sean


Top
 Profile  
Reply with quote  
 Post subject: Re: OpenGLSurface Sample Code
PostPosted: Fri Nov 06, 2009 3:11 pm 
Offline

Joined: Fri Sep 30, 2005 8:39 pm
Posts: 364
Location: Arlington, TX
If there is a double buffer property do turn it on, opengl draws to the screen with the aglSwapBuffer function, of which you will need to have double buffering turned on for agl context creation. This switches the background (drawing) buffer with the front (viewing) buffer and allows smoother frame transitions.

_________________
Open Source OpenGL Classes:
Camera (1.1), Light (1.0), Texture (1.2), Font (1.2), Mesh (1.7), Models (1.0)


Top
 Profile  
Reply with quote  
 Post subject: Re: OpenGLSurface Sample Code
PostPosted: Fri Nov 06, 2009 4:48 pm 
Offline

Joined: Fri Nov 06, 2009 5:20 am
Posts: 11
Sean-

No, I sent it through customer support with my support ID number. They usually respond within a few days, so I'll give it a little while longer. However, a 'response' isn't necessarily synonymous with a fix :(

Barry


Top
 Profile  
Reply with quote  
 Post subject: Re: OpenGLSurface Sample Code
PostPosted: Fri Nov 06, 2009 4:59 pm 
Offline

Joined: Fri Nov 06, 2009 5:20 am
Posts: 11
Blake,

That worked for me in both Win7 and Mac!!! Thanks :D
I hereby nominate you to the esteemed office of: RB Forum OpenGL Guru

Barry


Top
 Profile  
Reply with quote  
 Post subject: Re: OpenGLSurface Sample Code
PostPosted: Fri Nov 06, 2009 10:46 pm 
Offline

Joined: Fri Sep 30, 2005 8:39 pm
Posts: 364
Location: Arlington, TX
I wouldn't say I am a guru, I know how it works and what does what but not everything about it :)

I'm glad I could help though, if you get really serious about it you should think about just writing the opengl code from scratch instead of using a plugin.

_________________
Open Source OpenGL Classes:
Camera (1.1), Light (1.0), Texture (1.2), Font (1.2), Mesh (1.7), Models (1.0)


Top
 Profile  
Reply with quote  
 Post subject: Re: OpenGLSurface Sample Code
PostPosted: Sat Nov 07, 2009 10:24 am 
Offline

Joined: Fri Nov 06, 2009 5:20 am
Posts: 11
Thanks to a hidden gem in one of Blake's comments, I dug a bit deeper into the Fluid demo and noticed that the 'Render' method has a return value. The RB documentation for Render says it's a Sub, when in fact it's a Function. This must have changed when RB took over support for the control from TinRocket. What I have discovered:
Function Render() As Boolean

Const P1x = 0.0
Const P1y = 0.0
Const P2x = 25.0
Const P2y = 3.0
Const P3x = 19.0
Const P3y = 10.0
Const P4x = 3.0
Const P4y = 15.0

// CLEAR THE CURRENT BUFFER PAGE
//
// NOTE: The OpenGLSurface control needs to typically
// have 'DoubleBuffer' TRUE!!!
//
OpenGL.glClear( OpenGL.GL_COLOR_BUFFER_BIT )

// RENDER POLYGON INTERIOR
//
OpenGL.glColor3f( 1.0, 1.0, 0.0 )

OpenGL.glBegin( OpenGL.GL_POLYGON )
OpenGL.glVertex2f( P1x, P1y )
OpenGL.glVertex2f( P2x, P2y )
OpenGL.glVertex2f( P3x, P3y )
OpenGL.glVertex2f( P4x, P4y )
OpenGL.glEnd()

// RENDER POLYGON OUTLINE (LINE_LOOPs)
//
OpenGL.glColor3f( 0.0, 0.0, 0.0 )
OpenGl.glLineWidth( 2.5 )

OpenGL.glBegin( OpenGL.GL_LINE_LOOP )
OpenGL.glVertex2f( P1x, P1y )
OpenGL.glVertex2f( P2x, P2y )
OpenGL.glVertex2f( P3x, P3y )
OpenGL.glVertex2f( P4x, P4y )
OpenGL.glEnd()

// RENDER POLYGON VERTICES
//
OpenGL.glColor3f( 0.0, 0.0, 0.0 )
OpenGL.glPointSize( 10.0 )

OpenGL.glBegin( OpenGL.GL_POINTS )
OpenGL.glVertex2f( P1x, P1y )
OpenGL.glVertex2f( P2x, P2y )
OpenGL.glVertex2f( P3x, P3y )
OpenGL.glVertex2f( P4x, P4y )
OpenGL.glEnd()

If (NOT Me.DoubleBuffer) Then
OpenGL.glFlush()
Return True
End If

Return False

That is, if the OpenGLSurface control IS doubled buffered, then returning False will allow event processing to continue (a la KeyDown return logic) and the buffer pages will be swapped. If the control IS NOT double buffered, then you must do your own pipeline flush and return True so event processing will not continue. If the return value from the Render event is not matched to the DoubleBuffer property, then unpredictable results will occur.

Just for completeness, here is sample code for the Open and Resized Events

Sub Open()

// Set Orthogonal (non-perspective) View
OpenGL.glMatrixMode( OpenGL.GL_PROJECTION )
OpenGL.glOrtho( -1.5, 31.5, -1.5, 20.0, -1.0, 1.0 )
OpenGl.glMatrixMode( OpenGL.GL_MODELVIEW )

// Flat Lighting and Background Color
OpenGL.glShadeModel( OpenGL.GL_FLAT ) // Simple 2D lighting
OpenGL.glClearColor( 0.85, 1.0, 0.85, 1.0 ) // Green like engineer's pad

// Blending and Antialiasing
OpenGL.glEnable( OpenGL.GL_LINE_SMOOTH ) // Anti-aliased lines
OpenGL.glEnable( OpenGL.GL_POINT_SMOOTH ) // Smoth round vertices
OpenGL.glEnable( OpenGL.GL_BLEND ) // Blended primitives

OpenGL.glBlendFunc(OpenGL.GL_SRC_ALPHA, OpenGL.gl_ONE_MINUS_SRC_ALPHA)

// Miscellaneous Stuff
OpenGl.glDisable( OpenGL.GL_DEPTH_TEST ) // Not needed for 2D


Sub Resized()

OpenGL.glViewport( 0, 0, Me.Width, Me.Height )

Me.Render


This Open/Resized/Render code is all that's needed to draw a 2D triangle that will resize when the user resizes the window (assuming the window/control is set for resizing). The only other thing that's needed to do an OpenGlSurface1.Render from the main Open event. Also, don't confuse the OpenGLSurface 'Render' method with the 'Render' event. Maybe RB should change the Render event to Paint for consistency with other such controls.

Please give me any comments/corrections you may have as I'm only just beginning my OpenGL journey and covet any constructive input available. I'm presently exploring OpenGL as an alternative for our software (in interactive structural analysis package) that is presently using the RB built-in Canvas control. Canvas works ok on a Mac as a large graphics viewport, but it totally blows on Windows as it's too inefficient.


Top
 Profile  
Reply with quote  
 Post subject: Re: OpenGLSurface Sample Code
PostPosted: Sat Nov 07, 2009 2:06 pm 
Offline

Joined: Fri Sep 30, 2005 8:39 pm
Posts: 364
Location: Arlington, TX
The code does look like a basic setup for OpenGL, I noticed that GL_DEPTH_TEST is disabled, this will keep the depth buffer turned off, which is fine for 2D but if you move into 3D you will need to get it turned on. It also doesn't look like there is any stencil buffer support, you may want to look into the stencil buffer as it does have some uses in 2D graphics.

_________________
Open Source OpenGL Classes:
Camera (1.1), Light (1.0), Texture (1.2), Font (1.2), Mesh (1.7), Models (1.0)


Top
 Profile  
Reply with quote  
 Post subject: Re: OpenGLSurface Sample Code
PostPosted: Sat Nov 07, 2009 6:13 pm 
Offline

Joined: Fri Sep 30, 2005 8:39 pm
Posts: 364
Location: Arlington, TX
Here is an example of using the Stencil Buffer w/ 2D graphics, the controls borders are rendered as a solid quad with the stencil buffer filled in the middle (size - border width). This gives us a nice smooth border that isn't really obtainable with GL_LINES.

Image

_________________
Open Source OpenGL Classes:
Camera (1.1), Light (1.0), Texture (1.2), Font (1.2), Mesh (1.7), Models (1.0)


Top
 Profile  
Reply with quote  
 Post subject: Re: OpenGLSurface Sample Code
PostPosted: Sun Nov 08, 2009 11:33 pm 
Offline

Joined: Fri Nov 06, 2009 5:20 am
Posts: 11
Has anyone been able to get the depth buffer working? It's just not happening for me. Here is the code I've placed in the Open event:

// Flat Lighting and Background Color
OpenGL.glShadeModel( OpenGL.GL_FLAT ) // Simple 2D lighting
OpenGL.glClearColor( 0.8, 1.0, 0.8, 0.0 ) // Green engineer's pad

// Blending and Antialiasing
OpenGL.glEnable( OpenGL.GL_LINE_SMOOTH ) // Anti-aliased lines
OpenGL.glEnable( OpenGL.GL_POINT_SMOOTH ) // Smoth round vertices
OpenGL.glEnable( OpenGL.GL_BLEND ) // Blended primitives
OpenGl.glEnable( OpenGL.GL_DEPTH_TEST ) // Used for 2.5D clipping

OpenGL.glDepthMask( OpenGL.GL_TRUE )
OpenGL.glDepthFunc( OpenGL.GL_LESS )

OpenGL.glBlendFunc( OpenGL.GL_SRC_ALPHA, OpenGL.gl_ONE_MINUS_SRC_ALPHA )

flag = OpenGL.glIsEnabled( OpenGL.GL_DEPTH_TEST )

At this point <flag> comes back as 1 which shows depth test enabled. However, when drawing flat, simple polygons in (x,y) with differing values z values for each polygone, the polygons are still only displayed in "last drawn" order rather than z-order.

Prior to drawing I'm setting up as follows:
OpenGL.glMatrixMode( OpenGL.GL_PROJECTION )
OpenGL.glLoadIdentity

OpenGL.glOrtho( wxmin, wxmax, wymin, wymax, 1.0, 10.0 )

OpenGl.glMatrixMode( OpenGL.GL_MODELVIEW )

If, for example, polygon A is drawn with all z-values as 3.0 while all polygon B is draw with all its z-values at, say 4.0, then it would seem to me that polygon A should obscure the overlapping portions of polygon B since it's z-depth is closer (GL_LESS). However, no matter what values of z are used for each polygon, the final display order is always last drawn rather than z-buffered pixels. Also, I've tried the same code using glFrustum rather than glOrtho with no difference other than viewing perspective.

What am I missing here?


Top
 Profile  
Reply with quote  
 Post subject: Re: OpenGLSurface Sample Code
PostPosted: Sun Nov 08, 2009 11:41 pm 
Offline

Joined: Fri Sep 30, 2005 8:39 pm
Posts: 364
Location: Arlington, TX
What parameters are you using with glClear()?

Also the lowest z value is the one that will be drawn in the background, if you want z=3 to be drawn infront of z=4 then use negatives, z=-3 will be drawn infront of z=-4

_________________
Open Source OpenGL Classes:
Camera (1.1), Light (1.0), Texture (1.2), Font (1.2), Mesh (1.7), Models (1.0)


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 20 posts ]  Go to page 1, 2  Next

All times are UTC - 5 hours


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

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group