Anyone here able to load a popular object with its texture for openGL?
OKay since no one seems to answer, I guess it is a difficult thing to handle.
Im gonna use a file named as a .tri file.
The .tri file is a simple 3D object format using plain text.
This file type is using GL_TRIANGLE to define each face.
To read this format type is simple. We only need to read each 3 line to form a face.
Each line have a format like this [Position X, Position Y, Position Z, Normal X, Normal Y, normal Z, UV X, UV Y]
This format is very simple is not it? I will try to make a function loader for this.
I uploaded a tri format file of a cube.
[attachment deleted by admin]
Got it working.
I made a TRI object loader, but not completed yet.
This uploaded project will demonstrate you how to load a TRI file and then show it.
I will made this loader able to load the texture or coloring it.
On this file I also included a blender script which will be able to export your 3D model into TRI file.
i see a black box, Farabi
xp sp2
I can barely make out a grey square centered on a black background, with another grey square sqewed out of square to the right of the center square.
winxp home sp2
oh yah - i see em - lol
if i maximize the window, they are in the lower left corner
Yes it is It will only draw a cube.
Press a w s d to move in the 3D world. I will try to load a texture and view it.
So I guess no crashes.
i couldn't make it crash Farabi :U
Okay, the TRI file loader able to load a texture. The real texture format is a TGA file but on this example I modify the tri file so the texture format became jpg. I dont really like jpg even it smaller in size, because the texture became bad and blurred.
I will reveal the magic trick of this picture.
(http://omploader.org/vMXdsZA/t3.JPG)
The loader on this project is very slow since it do a heavy transfer between RAM and VRAM. I can make it faster but the memory for the texture will be limited to 4 MB. I think I can use the VRAM up to 256 MB but for compatibility reason, I will stick to 16 MB.
Here is the bottle neck of my loader
Quote
fLoadTexture proc uses esi edi hBmp:dword,Wrap:dword
LOCAL texture:dword
LOCAL h:BITMAP
LOCAL frm:dword
LOCAL buff[256]:dword
invoke glGenTextures,1,addr texture
invoke glBindTexture,GL_TEXTURE_2D, texture
invoke glTexEnvf,GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE
invoke glTexParameterf,GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST
invoke glTexParameterf,GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR
.if Wrap
invoke glTexParameterf,GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT
invoke glTexParameterf,GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT
.else
invoke glTexParameterf,GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP
invoke glTexParameterf,GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP
.endif
invoke GetObject,hBmp,sizeof BITMAP,addr h
xor edx,edx
xor eax,eax
mov ax,h.bmBitsPixel
mov ecx,8
div ecx
mov ecx,eax
.if eax==3
push GL_BGR_EXT
pop frm
.elseif eax==4
push GL_BGRA_EXT
pop frm
.else
invoke MessageBox,0,CADD("Picture Depth Bit must be 24 or 32"),0,0
.endif
.if h.bmBits==0
invoke MessageBox,0,CADD("Error"),0,0
.endif
invoke gluBuild2DMipmaps,GL_TEXTURE_2D,ecx,h.bmWidth,h.bmHeight,frm,GL_UNSIGNED_BYTE,h.bmBits
.if eax!=0
invoke gluErrorString,eax
invoke MessageBox,0,eax,0,0
.endif
mov eax,texture
ret
fLoadTexture endp
I called gluBuild2DMipmaps each time my object need to be drawn. This call function is to send data between RAM to VRAM. I can make this call only called once, but it will mean a confusing texture management where I only limited to 16 MB texture memory. If anyone had a good idea for optimizing this function, you are welcome.
bmp format is lossless - not that small
you might be able to use the 256-color format
Quote from: dedndave on July 14, 2009, 03:36:33 PM
bmp format is lossless - not that small
you might be able to use the 256-color format
Well, for shading 256-color not really good.
Maybe I can make the jpg picture not losless some how, even the file will be bigger but on 1024x1024 pixels the size is less than 200 kb.
many photo editor programs allow you to adjust the "smoothing" and compression for jpegs
i sometimes use uncompressed 24-bit bmps for editing - they can be a bit large, though
Hi Farabi
Is PNG an option ?
It's lossless data compression.
PNG supports palette-based (palettes of 24-bit RGB colors)
Quote from: Siekmanski on July 15, 2009, 06:43:13 AM
Hi Farabi
Is PNG an option ?
It's lossless data compression.
PNG supports palette-based (palettes of 24-bit RGB colors)
Yes why not? Everything can be used as long as windows support it.
I finished the texture loader. I will erase all other projects posts above.
Here is my comparation between Raydium and Mine.
Raydium
(http://omploader.org/vMXphaA/RaydiumSS.JPG)
Mine:
(http://omploader.org/vMXphZw/fGameEngineSS.JPG)
I cut the CPU Usage from 75% to 29%. And increase the FPS from 20 to 32.
I will try to integrate my Game Engine with Physic Engine and see the performance.
I uploaded the finished 3D models loader.
[attachment deleted by admin]