Sign in to follow this  
Followers 0
MartinJ

Getting started with OpenGL

9 posts in this topic

Hi guys,

 

as some of you may know I'm currently working on my Airbus A310 project. A few days ago I decided to take the next big step in starting to develop the various cockpit displays which are PFD, ND, CDU, MEMO and STATUS. Thanks to the gizmo-API I have access to LuaGL which offers a wide range of displaying possibilities. After searching the internet for some good tutorials I finally found a good one with a lot of examples. Unfortunately the very first example doesn't work and I don't know why and this is where I'm counting on your knowledge.

 

My setup: In order to get started with OpenGL I created a plane in my virtual cockpit which covers the whole panel bitmap. I then coded the classic "hello world" example and it works just like it should. What doesn't work is drawing a simple primitive. Here's the code:

 

gl.ClearColor(0.0, 0.0, 0.0, 1.0) --set the color to which the window is cleared to
gl.Clear(gl.COLOR_BUFFER_BIT) --actually clear the window
gl.Color(1.0, 1.0, 1.0) --set the object color
gl.Ortho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0) --specify the coordinate system
gl.Begin(gl.POLYGON) --define the object to be drawn
gl.Vertex(0.25, 0.25, 0.0)
gl.Vertex(0.75, 0.25, 0.0)
gl.Vertex(0.75, 0.75, 0.0)
gl.Vertex(0.25, 0.75, 0.0)
gl.End()

gl.Flush() --execute the commands

 

Any hints are welcome!

 

 

0

Share this post


Link to post
Share on other sites

Martin,

 

Since you are using Gizmo, why not simplify things and use the gfx API? Several of the OpenGL calls you used are unnecessary as they are handled by X-Plane or within Gizmo.

 

Here's an example of the same thing you posted above, only using the Gizmo API calls....

 

gfx.setColor(1.0, 1.0, 1.0, 1.0)

gfx.drawFilledBox(25, 25, 50, 50)  -- Note:  This is a 25 pixel square

 

Done!

0

Share this post


Link to post
Share on other sites

http://www.xsquawkbox.net/xpsdk/mediawiki/OpenGLState

 

  • The front face will be defined as GL_CW, and GL_CULL_FACE will be enabled. (This is unusual for GL apps.)

 

 

Your polygon winding order is wrong. Examples given on the internet will typically be in Counter-Clockwise.

X-Plane defaults to Clockwise.

 

You can toggle this, but it's a waste of the GPU drivers time. Best to work in what everything else does.

 

 

How do you convert to clockwise winding order? I'll leave that as an exercise for you.  

 

OpenGL is a black art, literally. Winding order is the least of your challenges ahead. :)  :ph34r:

0

Share this post


Link to post
Share on other sites

Thank you both very much for your fast answers. 

 

@Jim: Well you are right about the gfx-api. It's definitely faster to code and easier to use. Though there're still two good reasons why I wanted to try the gl-api instead: personal interest and an outside temperature of 30 °C which makes me stay inside the house  :) You mentioned that some of my calls are unnecessary. Could you be more specific on this one please? And how do I know which calls are handled by gizmo?

 

@Ben: So thanks to my polygon winding order the primitive is facing backwards? Makes sense why I can't see it... What api do you suggests when it comes to performance optimization? The gfx-api or the gl-api?

Edited by MartinJ
0

Share this post


Link to post
Share on other sites

Correct. Your primitive is facing backwards.

Thanks to face-culling being turned on and polygons being single sided, it's invisible.

 

 

LuaGL is provided so you can do what you want. It's a good idea to learn and understand what's going on.

 

gfx and other related API's are provided so you can do more with less code.

These API's are subject to performance reviews and optimisations where LuaGL is not.

 

 

For performance optimisation, use the built-in API's where possible. (gfx, trimesh, shaders...)

 

For ultimate control, use LuaGL.

0

Share this post


Link to post
Share on other sites

Thank you Ben and I'll keep this in mind. I've just changed the order within the gl.begin() and gl.end() block so that the gl.vertex calls take place in the cw-order. Unfortunately that didn't change the result and I still can't see the primitve. I then tried the gfx-api with the code snipped posted by Jim. As it turns out there is still no box visible on the screen/panel texture. So I changed my event from OnDraw_Gauges_3D() to OnDraw_Windows(). Just like before the "hello world" text gets printed but still no visible primitive. Any idea what could prevent the primitive from being drawn? Could it have to do with the fact that I'm running Windows 10 on my machine?

 

Here's my code and what I see in X-Plane.

 

function OnDraw_Windows()

    gfx.setColor( 1,0,0,1 )

    gfx.drawString( "Hello World", 1024, 800 )

    gfx.drawFilledBox(0, 0, 500, 500)

end 

 

luagl.jpg?dl=1

0

Share this post


Link to post
Share on other sites

unction OnDraw_Windows()


    gfx.setColor( 1,0,0,1 )

gfx.texOff()

    gfx.drawString( "Hello World", 1024, 800 )


    gfx.drawFilledBox(0, 0, 500, 500)


end 


0

Share this post


Link to post
Share on other sites

GL is a black art because, well, you either get a black screen or nothing.

 

It is one of the most frustrating but delightful areas of programming.

 

And then you discover shaders.  :ph34r:

 

Want debug output? I hope you like hot pixels.

 

 

 

Turn on as many slow options as you can when stuff doesn't work.

(culling off, double sided, draw lots of stuff (sometimes camera angles do strange things, more geometry at different rotations can help), whatever it takes... working first, fast second. :) )

 

Turning textures off works because each vertex has a UV coords of undefined (probably 0,0) when texturing is on and the UV data is not explicitly given to GL.

 

This makes all the pixels use 0,0, all the pixels interpolate their texture data between 0,0 and 0,0 .... lots of blank, or sometimes a very faint hint of whatever texture was last.

 

 

Good luck. :)

Edited by Ben Russell
0

Share this post


Link to post
Share on other sites

 

unction OnDraw_Windows()

    gfx.setColor( 1,0,0,1 )
gfx.texOff()

    gfx.drawString( "Hello World", 1024, 800 )

    gfx.drawFilledBox(0, 0, 500, 500)

end 

 

 

Ugh.

 

texOff AFTER drawString and before drawFilledBox. Tired. Rushed. :)

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Recently Browsing   0 members

    No registered users viewing this page.