OpenGL model

Jim Brown

Active Member
Licensed User
Longtime User
Hi Kamac

What I do at the moment is create a model in Wings 3D then export as DirectX format. I then convert this using my own tool into my own *.model format

I found that raw DirectX format files are big and slow to parse. So my converter trims everything down to half the original size. That means quicker parsing, and less storage space required in the APK

Later today or tomorrow I will upload the converter tool (Win32), B4A code, and some *.models to give you something to play with
 
Upvote 0

Jim Brown

Active Member
Licensed User
Longtime User
I wanted to look at converting 3DS models but I have little information on their format. Perhaps Waveform Object (*.obj) files are worth doing. However, when I exported models from wings under this format the texture coordinates seemed to be all messed up

It would be great if your brother could knock up some models in DirectX format. My convertor can only handle single-textured and single-grouped models as the moment. I have not got around to handling materials properly yet. The texture should be in the same folder at the model too
 
Upvote 0

Jim Brown

Active Member
Licensed User
Longtime User
Ok, here are the goodies ---> OpenGL ES Model project (beta)

The ZIP includes:
=====================
ModelUtil.exe - Win32 executable for converting DirectX models
GLObjectTest13.zip - Sample demo showing how various models are loaded
DXModels folder - Just a few sample DirectX models for testing with the converter

The ModelUtil convertor is a Win32 executable which converts DirectX models into *.model format. The executable DOES NOT require any special installation. Just drag it from the zip and place it where you like. NOTE: Tested in Windows 7 only
mupic2.png


EXAMPLE of the demo running in Android (x86 Virtual Android):
mupic1.png



See README.txt in the zip for more details
 
Upvote 0

Jim Brown

Active Member
Licensed User
Longtime User
The biggest tips I can think of:

1) Make sure you hide any faces which will never be seen (back face culling). I know in Wings you can delete the inside of faces whilst the outer side still renders. Have a look at the very simple house model in the demo. The bottom is not drawn for example.

2) Keep the texture low-res where possible. 512x512 for simple models is plenty good. I have even used 128x128 to give that "retro" look

3) Reduce polys as much as possible. Especially where they don't make much difference

How do the example models fair in general? The spring and planet are fairly heavy in polycount

What phone are you using? I tested on Galaxy S and Galaxy Tab. Both breeze through my models
 
Upvote 0

Kamac

Active Member
Licensed User
Longtime User
What phone are you using? I tested on Galaxy S and Galaxy Tab. Both breeze through my models

LG GT540 Swift. Pretty bad phone :BangHead:


2) Keep the texture low-res where possible (512x512 for simple models)

My is two times smaller on this sample :cool:

3) Reduce polys as much as possible. Especially where they don't make much difference

I'll try, but it should be yet smooth at 1100 poly's :(

How do the example models fair in general? The spring and planet are fairly heavy in polycount

They're all smooth. I wonder how much poly's does planet have.
 
Upvote 0

Jim Brown

Active Member
Licensed User
Longtime User
Earth model has 288 quads and 36 triangles
Spring model has 476 quads and 4 triangles

(NOTE: Details available in the *.model files which are in regular text format)
 
Upvote 0

Jim Brown

Active Member
Licensed User
Longtime User
Nice and retro!

There are still some critical things I want to add to my demo code:
* Ability to identify the object as touched on-screen by the user
* Collision detection between objects
 
Upvote 0

Kamac

Active Member
Licensed User
Longtime User
* Ability to identify the object as touched on-screen by the user
* Collision detection between objects


+10!

It would be the best to make a simple engine.

And what about objects rotation and objects positioning?

By the way, here's the skybox added ;):

ascreen.png


I am up to make trees now! I've been thinking of optimising a tree to a minimum of polys, whichout making it a 2d plane, we'll see what can i work out :)

@EDIT

It will be hard to add much trees, because i don't know how to change their position :(
 
Last edited:
Upvote 0

Jim Brown

Active Member
Licensed User
Longtime User
For positioning, rotation, and scaling the general method is:


1) For each object start by resetting any previous translations:
----------------------------------------------------------------
gl.glLoadIdentity

Alternatively, you can use gl.glPushMatrix and gl.glPopMatrix:
With this method you first 'push' the current translations to the stack. Next, set your own translations,scaling,rotations. Render the object. Finally, 'pull' (or Pop) the previous translations from the stack to restore the previous settings


2) Set desired position of the object in 3D space via x,y,z coordinates
----------------------------------------------------------------
gl.glTranslatef(x,y,z)

X is Left to right
Y is bottom to top *
Z is near to far

0,0,0 is center of the display by default
* NOTE: OpenGL uses inverted Y coordinate system


3) Set the rotation of the object where applicable
----------------------------------------------------------------
gl.glRotatef(rotX,1,0,0) -- Rotate around X axis (PITCH) by rotX units
gl.glRotatef(rotY,0,1,0) -- Rotate around Y axis (YAW) by rotY units
gl.glRotatef(rotZ,0,0,1) -- Rotate around Z axis (ROLL) by rotZ units


4) Set the scale of the object where needed
----------------------------------------------------------------
gl.glScalef(x,y,z) --- 1.0,1.0,1.0 is the default size


Have a look at my GLObjects demo. You will see these actions take place in the glsv_Draw sub



Here is a basic example:
B4X:
gl.glPushMatrix ' capture current translations
gl.glScalef(0.5,0.5,0.5)  ' make object half its size
gl.glTranslatef(0.6,0.0,0) ' move it a little to the right
gl.glRotatef(1.5,0,1,0) ' rotate objects Y (YAW) axis
GLObject_Draw(obj1,gl) ' draw object
gl.glPopMatrix ' reset translations
 
Last edited:
Upvote 0
Top