Sign in to follow this  
Followers 0
LarsJ

OpenGL without external libraries

25 posts in this topic




It is a lot of work here. Thanks for share with us! Sample files are pretty nice, especially tunnel effect. I'm still dizzy. :lol:


When the words fail... music speaks

Share this post


Link to post
Share on other sites

You are welcome. I've probably spent most time on the context stuff and the image loading functions. I already had made several versions of the examples. But they were made with freeglut and SOIL. Some of the examples are just copies.

Share this post


Link to post
Share on other sites

Very well done

Nice examples, well written and well documented

I like that

Thanks for sharing

GreenCan


Contributions

CheckUpdate - SelfUpdating script ------- Self updating script

Dynamic input validation ------------------- Use a Input masks can make your life easier and Validation can be as simple

MsgBox with CountDown ------------------- MsgBox with visual countdown

Display Multiline text cells in ListView ---- Example of pop-up or ToolTip for multiline text items in ListView

Presentation Manager ---------------------- Program to display and refresh different Border-less GUI's on a Display (large screen TV)

USB Drive Tools ------------------------------ Tool to help you with your USB drive management

Input Period udf ------------------------------ GUI for a period input

Excel ColorPicker ---------------------------- Color pickup tool will allow you to select a color from the standard Excel color palette

Excel Chart UDF ----------------------------- Collaboration project with water 

GetDateInString ------------------------------ Find date/time in a string using a date format notation like DD Mon YYYY hh:mm

TaskListAllDetailed --------------------------- List All Scheduled Tasks

Computer Info --------------------------------- A collection of information for helpdesk

Shared memory Demo ----------------------- Demo: Two applications communicate with each other through means of a memory share (using Nomad function, 32bit only)

Universal Date Format Conversion -------- Universal date converter from your PC local date format to any format

Disable Windows DetailsPane -------------- Disable Windows Explorer Details Pane

Oracle SQL Report Generator -------------  Oracle Report generator using SQL

SQLite Report Generator -------------------  SQLite Report generator using SQL

SQLite ListView and BLOB demo ---------- Demo: shows how binary (image) objects can be recognized natively in a database BLOB field

DSN-Less Database connection demo --- Demo: ActiveX Data Objects DSN-Less Database access

Animated animals ----------------------------- Fun: Moving animated objects

Perforated image in GUI --------------------- Fun: Perforate your image with image objects

UEZ's Perforator major update ------------- Fun: Pro version of Perforator by UEZ

Visual Crop Tool (GUI) ----------------------- Easy to use Visual Image Crop tool

Visual Image effect (GUI) -------------------- Visually apply effects on an image

 

 

 

Share this post


Link to post
Share on other sites

thank you so much. Great job.  :thumbsup:

Share this post


Link to post
Share on other sites

The first zipfile included only a few OpenGL 3.3 examples. Added a new zipfile, OpenGL33.7z, that contains some more. You can probably run the examples if your video card supports OpenGL 3.1. You can find the zip in the bottom of post #1. Section 3.3 in post #1 contains a list and a description of the examples.

The text in section 1.5 and 2.4 is updated. Smaller updates to some of the other sections. Added a new section 4.0.

Parthenon

One of the new examples shows how to build a world of objects with a dynamic, moving camera. A building that should look like Parthenon (a temple on the Athenian Acropolis) is created in an area with some trees.

Parthenon1_zps86ab07bc.png

The building consists of 30 columns, each composed of 3 different parts. This provides 90 OpenGL objects. They are created in a loop. There are 98 trees which consists of 2 parts. This provides 196 objects created in a new loop. These two loops are executed for every single OpenGL drawing cycle. In order to ensure sufficiently good performance, it is necessary to optimize these loops. This is done with The Embedded Flat Assembler (FASM) UDF by Ward.

Share this post


Link to post
Share on other sites

Four of the new OpenGL 3.3 examples shows how to maneuver a spaceship or an airplane. In the first example the maneuvers are made with gimbals.

Gimbals1_zps9b0821a2.png

This means that the maneuvers are composed of rotations about the x-, y- and z-axes. A better way is to use yaw, pitch and roll transformations. This is shown in the three other examples.

1 person likes this

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Tomb has pointed out an error in the implementation of glCallLists (see OpenGL GlReadPixels post #6) in oglFunctions.au3. I have reviewed all functions with array parameters and found the same error in glVertex3fv. The two functions are corrected in this version:

Edit: The two functions are corrected in the update dated 2013-08-03.

Edited by LarsJ

Share this post


Link to post
Share on other sites

LarsJ,

I see you have done a lot of work. I'm here to ask you, if you want to participate in the AutoIt OpenGLCL Team. We (minx and Andy from Germany ;-) ) are currently adding OpenCL support to the most complete OpenGL UDF(s) for AutoIt ('?do=embed' frameborder='0' data-embedContent>>).

OpenCL, in case you don't know, is a language similar to GLSL, but you're actually accsessing the cores of the GPU, making it possible to do an crazy amount of parallel calculations (peformance beats Inline-ASM by far).

Yet we have a few examples running, but we are (or minx is) currently structuring the code. There are a few things missing in the SDK like GLSL or newer OpenGL extensions. Code, which you seem to work on.

We would be glad if you join us (I'm currently using chesstigers account, because twitter login is disbaled...). Please contact me at squarecode@web.de if your interested.

Share this post


Link to post
Share on other sites

Oh ok then...


I will answer every single PM, and you are free to ask anything anytime.

Share this post


Link to post
Share on other sites

Added a new chapter 4 about implementing a model loader for Wavefront (OBJ) 3D models.

This is a picture of one of the models. A Mitsubishi A6M Zero aircraft with and without a texture.

MitsubishiA6MZero_zps750b1173.jpg

This is a picture from a small example that shows how to use the models.

Aircrafts_zps025ef5ee.jpg

And this is a picture of the provisional only large model (Apollo Lunar Module, 300.000 vertices, 35 secs to load).

ApolloLunarModule_zpsdb0a578e.jpg

Added a new group of OpenGL 1.1 examples: SamplesOpenGL 1.1glCommands. See section 1.4.

1 person likes this

Share this post


Link to post
Share on other sites

Updates 2013-08-24.

These updates relates to 3D models only.

For a complete list of updates see section 4.9.

Most sections in chapter 4 in first post are updated.

Most important updates:

Optimizations

  • Texture coordinates will not be loaded, if no valid texture image exists
  • Added an option to prevent loading normal vectors, if they are not needed
This means that the loading function runs faster. More important is that you will not waste memory and processor time on data which are not used.

The Apollo Lunar Module large model (no valid texture images) now loads in 26.5 secs (old XP). 33.8 secs in the previous version. This is 20% faster. On a new laptop the model loads in 10 secs. See section 4.5 in first post.

Features

  • Multiple instances of a model can be handled
  • Material files can be loaded and applied dynamically
Viewers

The Models menu is expanded with a Materials item to load and apply material files.

New View menu with 2/3 items:

  • Wireframe to show a wireframe drawing of the model
  • Normal vectors to draw normal vectors. Only for sample models. Only the OpenGL 1.1 version.
  • Transformations to print the transformations of a model with _ArrayDisplay
If you apply transformations to a model, you can print the transformations with the Transformations menu. The transformations for the models in the examples are calculated in this way.

This is 3 instances of a dragon model with 3 different material files:

dragons_zpsbbfb707b.jpg

Share this post


Link to post
Share on other sites

Normal vectors

If a model only contains vertices, but no texture coordinates and no normal vectors, the normal vectors are calculated automatically by the loader. The normal vectors can be calculated in two ways:

  • One normal vector per triangle (default)
  • One average normal vector per vertex
The first point means that if a vertex is common to more triangles, this vertex will be assigned several (different) normal vectors.

In the second point only one normal vector will be calculated per vertex. This is a normal vector which is an average of the normal vectors of the adjacent triangles (in a mathematical sense this vector is not a normal vector, because it's not normal to the surface).

Smooth surfaces

This is SamplesBlendercylinder.obj and cylinder2.obj drawn with normal vectors:

cylinders_zps34896d49.jpg

The cylinders are created in Blender.

The cylinder on the left is edgy because there is an abrupt change in the normal vectors exactly on the edge between two adjacent triangles. The normal vectors determines how the light is reflected. Because the normal vectors changes abruptly on the edges, the edges looks very sharp.

Smoothing is added to the cylinder on the right. This means that Blender calculates average normal vectors on the edges, and the edges looks smooth.

Dark surfaces

spaceships_zps7ea9281e.jpg

For the spaceship (Samplesspaceship.obj) on the left the normal vectors are calculated by the loader. They are calculated just as they are with one normal vector per triangle. This means that a vertex with more adjacent triangles has more normal vectors. The light looks good, but the edges are sharp.

The normal vectors in the middle are also calculated by the loader. They are calculated as average normal vectors. The surface of the spaceship is smooth, but there is a problem with the light between the cockpit and cargo hold. It's too dark. The problem is that the normal vectors in this area are pointing in the wrong direction. They are pointing into the spaceship. For such a closed surface, all normal vectors should be pointing out of the surface.

On the right the spaceship is imported into Blender and smoothing is added to the model. Then the spaceship is exported as spaceship2.obj. All normal vectors are pointing out of the spaceship and the light looks good.

two-sided.obj

two-sided_zpsed81a1cf.jpg

two-sided.obj is one of the small models which is used in the OpenGL 2.1 light examples (SamplesOpenGL 2.11 WikiBooksLights). Here you easily see why the model is named two-sided. If you only are concerned about the sides, all the normal vectors are pointing in the same direction. The side without any normal vectors is dark.

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

General updates 2013-09-21.

MSAA rendering context

The model to the left (large model: Leaning Tower of Pisa) is rendered with a simple context while the model to the right is rendered with a proper context supporting MSAA (multisample antialiasing). The purpose of a MSAA context is among other things to reduce flicker along edges.

LeaningTowerofPisa_zpsdea87d8e.jpg

Not only this model but all the 3D models and all the other examples benefits from this new MSAA context. If you take a closer look at the pictures in post 7, 8 and 13, you'll see that many of the edges looks as if they are composed of a lot of small triangles. With the new context these edges looks much smoother.

The blue normal vectors in the post above also looks much better. With the simple context some of the vectors looks as if they are composed of 2 - 3 different line segments. With the new context the vectors looks much more like a single straight line.

Because we already know how to create a proper context it's easy to create a MSAA context. It's a matter of extending the pixel format attribute list with a few more attributes. See section 1.2 in first post for details.

As you can see in section 1.2, there are two new MSAA contexts in this update. A MSAA and a MSAAbest context. The MSAAbest context is set up as a new default context if your video card supports it.

A disadvantage of the MSAA context is that it can be more CPU/GPU intensive than the simple context or the default proper context. Especially in full screen windows.

An easy way to switch between the MSAAbest context and the default proper context is to use ExLauncher.au3. In the Context | Select menu and the "Supported context" group you can select a Simple and Proper context.

Simple will try to create a MSAAbest context and fall back to the Simple context in case of an error.

Proper will create a default proper context (which does not support MSAA).

Anisotropic texture filter

The problem along edges in the model to the left also exists in textures along edges. But the problem does not seem to be so prevalent in textures. Nevertheless, a solution to the problem would be to use an anisotropic filter. Such a filter can be applied through the GL_EXT_texture_filter_anisotropic extension. In this update the filter is implemented in CreateTexture in oglLoadImages.au3. See section 1.3 in first post. Because CreateTexture is a common function all 3D models and examples benefits from this update.

"SamplesOpenGL 1.1TexturesCubesCube Homer Simpson.au3" (rotating cube with a Homer Simpson texture) is an example where you clearly gets a better result. There is much less flicker along the edges between the texture and the oblique corner sides of the cube.

Sound alarm

If you create a GUI with a label as the only control you'll hear a sound alarm if you press a key e.g. a letter.

In these examples a lot of GUIs have a label as the only control. The label is used as statusbar. Because _IsPressed is used to catch key presses to rotate and move OpenGL objects this sound alarm can be very annoying.

An easy workaround is to add an input control to receive the key presses. In this update an input control is added to all the examples with this problem.

Edited by LarsJ

Share this post


Link to post
Share on other sites

3D model updates 2013-09-21.

Functionality

  • Quad meshes and higher order polygon meshes are supported
  • Negative references in face definitions are supported
  • Quad meshes can be rendered with quads (instead of triangles)
Polygon meshes

The picture shows how a pentagon can be constructed from 3 triangles.

Polygons_zps9fcd53de.jpg

The design ensures that the order of the vertices are preserved in the triangles. This means that if we have to calculate the normal vectors ourselves (because they are not supplied in the model) the normal vectors of the triangles will be pointing in the same direction as the normal vector of the pentagon.

The method can easily be extended to all types of polygons. The number of triangles equals the number of edges or vertices minus two. Programmatically the method is easy to implement.

A disadvantage is that it introduces redundancy. V0 (and VT0 (texture coordinates) and VN0 (normal vector)) is used in every triangle. The other points except the first and the last are used twice. See section 4.8 in first post for a possible solution.

Negative references

A new large model is added: Leaning Tower of Pisa. You can see a picture in the post above. This model uses negative references in face polygons. The face polygons consists of triangles and quads. With negative references you counts backwards from the last added vertices, texture coordinates and normal vectors. -1 is the last vertex, texture and normal. -2 the second last and so on.

Render with quads

Some models (albeit not many) are pure quad meshes. With this update it's possible to render these models with quads instead of triangles. By default, all models are rendered with triangles. For pure quad meshes the Load quads item in the Options menu is enabled and you can choose to load and render the model as a quad mesh.

Two of the sample models are quad meshes: box1 (quads).obj and PiggyBank (quads).obj. Use View | Wireframe to see that the models are rendered with quads:

PiggyBank_zpsf3a52362.jpg

Share this post


Link to post
Share on other sites

3D model updates 2013-09-21.

Optimizations

  • The objects which a model is built of, are sorted by material
  • 3D models are saved as binary files
Sorting

The Apollo Lunar Module large model is composed of 74 objects. In this context an object is a group of vertices, texture coordinates, normal vectors and face polygons which uses the same material and can be drawn with one single OpenGL drawing command (glDrawArrays or glDrawElements).

These 74 objects are rendered in a loop which is processed for every single OpenGL drawing cycle. Because the material changes from object to object they must be rendered in a loop so that it's possible to change material with the glMaterial command.

If the same material is used multiple times it's possible to achieve a performance improvement by sorting objects by material and put objects of the same material together into one large object.

For the Apollo Lunar Module 74 objects are reduced to 12 by sorting the objects. This means that the number of loops in the OpenGL drawing cycle is also reduced from 74 to 12. This is a huge performance improvement.

Under OpenGL 1.1 the CPU usage is 40% on my XP with 74 objects. With 12 objects the CPU usage is 5%. Even if you rotates the model (e.g. with the W-key) the CPU usage is still only about 5%. The model is running much smoother.

Not only large models can be composed of high number of objects. Two of the new small models (AircraftsF-16 Fighting Falconf-16.obj and Clemsonal.obj) are composed of 117 and 173 objects. These numbers are reduced to 3 and 35 by sorting the objects.

Binaries

When an OBJ-file is parsed the result is a pile of data (vertex and texture coordinates, normal vectors and face polygons). Data is stored in 4 structures (OpenGL 1.1) or 4 VBO-objects (OpenGL 2.1). It's easy to save the contents of these data stores directly to binary files. This can be done with a few fast commands. glGetBufferSubData can be used to extract data from VBO-objects. See section 4.3 in first post.

Restoring data from binary files can also be done with a few fast commands. Section 4.2.

This update contains functions to save and read models as binary files. This means that the models loads instantly.

Summary of 2013-09-21 updates

  • A new MSAA context is set up as the default context to reduce flicker along edges. Post 16.
  • An anisotropic texture filter is implemented to reduce texture flicker along edges. Post 16.
  • An annoying sound alarm is removed in examples including the model viewers. Post 16.
  • Quad meshes and higher order polygon meshes are supported. Post 17.
  • Negative references in face definitions are supported. Post 17.
  • Quad meshes can be rendered with quads (instead of triangles). Post 17.
  • The objects which a model is built of, are sorted by material. This can provide a huge performance improvement for models where the same material is used several times.
  • 3D models are saved as binary files. This means that the models loads instantly.
  • A lot of new models are included in the zipfile. Section 4.4.

Share this post


Link to post
Share on other sites

#19 ·  Posted

The code was not running under 3.3.10. Updated. New zips in first post. There is still a zip for 3.3.8.

The UDFs APIConstants.au3 and WinAPIEx.au3 by Yashied and RecFileListToArray.au3 by Melba23 are not used any more. These functions are included in 3.3.10. FASM assembler code to fix x64 issues is deleted. No x64 issues in 3.3.10.

Share this post


Link to post
Share on other sites

Sorry for my bed english
Can you help me how to view more image to GUI.
I try but i can not to do it

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