MiniB3d bird demo, cruption on my machine

BlitzMax Forums/MiniB3D Module/MiniB3d bird demo, cruption on my machine

Shagwana(Posted 2009) [#1]
*** Managed to solve it, check down the page ***

As you can see under I have a problem with minib3d on my rig;



As you can see the textures are not drawn correctly

When I try and build a standard texturemapped cube, i get the same results with the UV's getting all screwed up.

I suspect that this is an issue with my gfx card drivers, but hope its not!.

Gfx card = radeon 4870, drivers 9.8
Vista machine, 32bit

Anyone with any ideas on how to solve this issue?


To add to this, loading a b3d mesh as in the 'loadanimseq.bmx' example works as expected!


Shagwana(Posted 2009) [#2]
After further investigation;

VertexU() and VertexV() return the correct values set for the UV of the verts in question.

I also updated to the latest ati drivers, this did not solve the problem.


Shagwana(Posted 2009) [#3]
More information!. The flag demo works as expected, the uv of the b3d logo is all find and groovy on that one.

Looks like there maybe something special going on with this example?.

Does anyone else have this problem with the latest build of minib3d?


ima747(Posted 2009) [#4]
Have you tried the other examples, specifically anything that loads a textured mesh? If memory serves, the flag demo textures a surface and alters the vertexes rather than the bird demo which is loading textured meshes.


Midimaster(Posted 2009) [#5]
I have also a problem in loading textures and sprites, See the other topic next to yours...

http://www.blitzbasic.com/Community/posts.php?topic=87017

At first I thought it is a problem with sprites only, but now also textures do not work...


Shagwana(Posted 2009) [#6]
In short...

'loadanimseq.bmx' example works as expected!
'flag.bmx' example works as expected

The bird demo and the code I made myself does not.


Shagwana(Posted 2009) [#7]
After having a look at the minib3d code, looks like its a problem to do with only non-animated meshes.


ima747(Posted 2009) [#8]
What happens if you use load a non animated mesh as an animated one?


Shagwana(Posted 2009) [#9]

What happens if you use load a non animated mesh as an animated one?


Problem is still there

While poking around in minib3d, I see the flag demo uses 'vbo' for rendering the textures. This appears to work as expected here.

However the bird demo uses some sort of uv list that gets passed. From what I can tell is inside this list, it looks to be spot on and as expected.

I dont really understand enought about OpenGL in order to diagnose this problem any further, im going to keep hacking at it tho.


Shagwana(Posted 2009) [#10]
Right I have fudged together the simplest example of this happening on my machine.

'
' Simple problem show
'

Import "minib3d/minib3d.bmx"

Local width=1024,height=800,depth=32,mode=0
'Graphics3D width,height,depth
Graphics3D width,height,depth,mode


Local cam:TCamera=CreateCamera()
PositionEntity cam,0,0,-5
Local light:TLight=CreateLight()



Local n:Int
Local m:TMesh=CreateMesh()
Local s:TSurface=CreateSurface(m)

Local b:TBrush=LoadBrush("engine.jpg") '256x256 texture image

n=AddVertex(s,-1,+1,-1,0,0)
Print VertexU(s,n,0)+" "+VertexV(s,n,0)

n=AddVertex(s,+1,+1,-1,1,0)
Print VertexU(s,n,0)+" "+VertexV(s,n,0)

n=AddVertex(s,+1,-1,-1,1,1)
Print VertexU(s,n,0)+" "+VertexV(s,n,0)

n=AddVertex(s,-1,-1,-1,0,1)
Print VertexU(s,n,0)+" "+VertexV(s,n,0)


AddTriangle s,0,1,2
AddTriangle s,0,2,3

PaintSurface s,b

While Not KeyDown(KEY_ESCAPE)		
  If KeyHit(KEY_ENTER) Then DebugStop
  ' control camera
  MoveEntity cam,KeyDown(KEY_D)-KeyDown(KEY_A),0,KeyDown(KEY_W)-KeyDown(KEY_S)
  TurnEntity cam,KeyDown(KEY_DOWN)-KeyDown(KEY_UP),KeyDown(KEY_LEFT)-KeyDown(KEY_RIGHT),0


  renders=renders+1
  ' calculate fps
  If MilliSecs()-old_ms>=1000
    old_ms=MilliSecs()
    fps=renders
    renders=0
    EndIf
	
  UpdateWorld
  RenderWorld	
  Text 10,0,"FPS: "+fps

  Flip
	
Wend
End



This is what I get;




Does this happen for anyone else?


Shagwana(Posted 2009) [#11]
The plot thickens, I just tried my 256x256 texture in the flag demo and it comes back as above.

Flag demo texture is 400x197
My texture is 256x256

Maybe this is a problem with the loading of textures then!


Shagwana(Posted 2009) [#12]
The same texture saved as a 256 col bitmap works

On looking a little deeper into the loadbrush command, I see that it wraps the textureloading that ends up wrapping the load pixmap command

Some stuff goes on in behind to do with changing the format of textures and I think that this is now were the problem lies!


Shagwana(Posted 2009) [#13]
Now digging even deeper, if i save the loaded 24bit or 32bit textures pixmap to a png file...
SavePixmapPNG tex.pixmap,"savedpixmap.png"

The image is fine, so maybe its opengl not understanding the format the data is in?.

I feel lost!


ima747(Posted 2009) [#14]
interesting, what happens if you the load the breaking image in bmax (2d)? does it display OK there? if so what happens if you switch bmax to using the opengl driver instead of the default directx?


Shagwana(Posted 2009) [#15]
minib3d is opengl only.

The exported pixmap from the texture is a valid file and looks as expected

However, the 256 color one works fine in minib3d the 24bit one does not (and 32bit)

If I load a 256 colour texture, then manualy overwrite the pixmap with the 24bit data (using LoadPixmapPNG)- then it works!. The pixmap that textures refer to is a 32bit pixmap (RGBA8888) so i am able to load a 24bit texture over the top of the 8bit (256 cols).

When I get sometime i will have a further play


Shagwana(Posted 2009) [#16]
W00t! Well I managed to fix it...


Thats what it should look like. The problem I had was with ...

In TTexture.bmx...
  Local mip_level=0
  Repeat
  'glPixelStorei GL_UNPACK_ROW_LENGTH,pixmap.pitch/BytesPerPixel[pixmap.format] 'BAD LINE!
    glPixelStorei 2,pixmap.pitch/BytesPerPixel[pixmap.format]    'THE FIX!
    glTexImage2D GL_TEXTURE_2D,mip_level,GL_RGBA8,width,height,0,GL_RGBA,GL_UNSIGNED_BYTE,pixmap.pixels
    If Not mipmap Then Exit
    If width=1 And height=1 Exit
    If width>1 width:/2
    If height>1 height:/2

    pixmap=ResizePixmap(pixmap,width,height)
    mip_level:+1
  Forever



Shagwana(Posted 2009) [#17]
After further investion, I understand the fix is this;
glPixelStorei GL_UNPACK_ROW_LENGTH,(pixmap.pitch/BytesPerPixel[pixmap.format])-width  
glPixelStorei GL_UNPACK_ALIGNMENT,4


Anyone who really knows there OPENGL out there?, could you have a look at my fiddlings and point out what I am doing wrong (if anything?)


simonh(Posted 2009) [#18]
No idea why that screws up on your machine. Thanks for the fix though, I'll add it to future releases.


Shagwana(Posted 2009) [#19]
I think my fix will need a little testing on those machines that did not have this problem to begin with.


outsider(Posted 2009) [#20]
Hi,
your fix work very well (same like previous version with 'BAD LINE') on my old Intel card laptop (XP).