GLBasic forum

Main forum => Bug Reports => Topic started by: FutureCow on 2012-May-20

Title: Broken (see through) 3D textures in GLBasic 10?
Post by: FutureCow on 2012-May-20
Hi All,
There was an old thread that I was testing the code from (http://www.glbasic.com/forum/index.php?topic=673.0) as I was having issues with my code. The old example does something very similar to my program and it shows the same problem in in GLBasic 10 (I'm running 10.283). I don't understand why it doesn't work correctly.

The problem is that some colours on textures are showing up see-through and I'm not sure why.

I've modified the original code very slightly. Firstly, it shows you the sample texture on the screen and waits for an "enter" keypress to continue. This way you can see what the texture should look like.
Secondly, I've replaced FillRect with DrawRect (the current equivalent), and lowered the camera angle to make it easy to see that the texture is see-through - everything else is identical to the original code.

If someone could run this code and tell me why some coloured textures are invisible and others aren't, that would be awesome!

Code (glbasic) Select

LOCAL world[]
DIM world[15][10]

// Dummy Data
FOR x=0 TO 14
FOR y=0 TO 9
world[x][y]=RND(15)/10
NEXT
NEXT

// Create World Object
X_OBJSTART 0
X_AUTONORMALS 2
FOR x=0 TO 14
FOR y=0 TO 9
MakeTile(world[], x,y, -15/2, -10/2)
NEXT
NEXT
X_OBJEND

LOCAL a=0
WHILE a=0
// some dummy texture:
DRAWRECT 0,0,128,128, RGB(0,0,255)
DRAWRECT 4,4,124,124, RGB(255,255,255)
DRAWRECT 5,62,123,66, RGB(0,255,0)
DRAWRECT 62,5,66,123, RGB(0,255,0)
DRAWRECT 62,62,66,66, RGB(255,0,0)
PRINT "GLBasic", 8,8

GRABSPRITE 0, 0,0,128,128
SHOWSCREEN
IF KEY(28)=1 THEN a=1
WEND
BLACKSCREEN


WHILE TRUE
X_MAKE3D 1,100, 45
X_CAMERA 1,6,10, 0,0,0
X_SETTEXTURE 0,-1
X_ROTATION GETTIMERALL()/100, 0,1,0
X_DRAWOBJ 0,0
SHOWSCREEN
WEND



FUNCTION MakeTile: heights[], x,y, offsetx, offsety
// Triangle Strip is:
// 0--2--4-.
// | /| /| .
// |/ |/ |/
// 1--3--5-.

// We need:
// 0-1-2
// |\|/|
// 3-4-5
// |/|\|
// 6-7-8
LOCAL pts[]
LOCAL i, px, py, mx, my
DIM pts[9][3] // 9 points[x,y,z]
pts[0][0]=-1; pts[0][1]=-1
pts[1][0]=.0; pts[1][1]=-1
pts[2][0]= 1; pts[2][1]=-1
pts[3][0]=-1; pts[3][1]=.0
pts[4][0]=.0; pts[4][1]=.0
pts[5][0]= 1; pts[5][1]=.0
pts[6][0]=-1; pts[6][1]= 1
pts[7][0]=.0; pts[7][1]= 1
pts[8][0]= 1; pts[8][1]= 1

// now calculate Z for each point
mx = BOUNDS(heights[], 0)-1
my = BOUNDS(heights[], 1)-1

FOR i=0 TO 8
// Get neighbour point
// but stop at array border
px = MIN(mx, MAX(0, x+pts[i][0]))
py = MIN(my, MAX(0, y+pts[i][1]))
pts[i][2] = ( heights[px][py]+ _
heights[ x][ y]+ _
heights[px][ y]+ _
heights[ x][py])/4
NEXT

// Next a function to create 2 triangles:
INC x, offsetx
INC y, offsety
AddQuad(pts[], x,y,1,0,4,3)
AddQuad(pts[], x,y,1,4,2,5)
AddQuad(pts[], x,y,3,6,4,7)
AddQuad(pts[], x,y,5,4,8,7)

ENDFUNCTION


FUNCTION AddQuad: pts[], x,y,a,b,c,d

// here we build a triangle stipped quad
// for the points a,b,c,d
// we divide coordinates by 2, so we get a
// rectangle of size 1x1 (-0.5 -> 0.5)
// for the texture we divide by 2 and add 0.5
// (0.0 -> 1.0)
// last: we swap y and z, since y is vertical in GLBasic
LOCAL cl
cl =RGB(255,255,255)
X_OBJADDVERTEX x+pts[a][0]/2,pts[a][2],y+pts[a][1]/2, pts[a][0]/2+.5, pts[a][1]/2+.5,cl
X_OBJADDVERTEX x+pts[b][0]/2,pts[b][2],y+pts[b][1]/2, pts[b][0]/2+.5, pts[b][1]/2+.5,cl
X_OBJADDVERTEX x+pts[c][0]/2,pts[c][2],y+pts[c][1]/2, pts[c][0]/2+.5, pts[c][1]/2+.5,cl
X_OBJADDVERTEX x+pts[d][0]/2,pts[d][2],y+pts[d][1]/2, pts[d][0]/2+.5, pts[d][1]/2+.5,cl
X_OBJNEWGROUP
ENDFUNCTION


In the code above, the white part of the texture becomes see through. It's even more apparent if you replace the following section of code (the bit that draws the texture) :
Code (glbasic) Select

// some dummy texture:
DRAWRECT 0,0,128,128, RGB(0,0,255)
DRAWRECT 4,4,124,124, RGB(255,255,255)
DRAWRECT 5,62,123,66, RGB(0,255,0)
DRAWRECT 62,5,66,123, RGB(0,255,0)
DRAWRECT 62,62,66,66, RGB(255,0,0)
PRINT "GLBasic", 8,8


with
Code (glbasic) Select

DRAWRECT 0,0,128,128, RGB(0,100,0)
DRAWRECT 4,4,124,124, RGB(0,200,0)


Any takers????
Title: Re: Broken (see through) 3D textures in GLBasic 10?
Post by: mentalthink on 2012-May-20
HI I comment my experiencies, I don´t test your code... perhaps you have troubles whit the UVW maps...

When I do something in 3D, if my model not´s it´s correct mapping, when I apply the text... the black color it´s transparent... basically when it´s .png and when I run under windows... in mobile devices don´t fails...

Sorry for not help more... but in windows...  not it´s the same behaviour in some cases than mobiles devices...

Reminder : Textures whit same WXH and not bigger than 1024... in some cases make strange things... and the power of two, becuase OPENGL works very faster whit this measure...
Title: Re: Broken (see through) 3D textures in GLBasic 10?
Post by: Minion on 2012-May-20
I just tried the above in both 10.231 and 11 and dint get any transparent textures ;( Could you post a screen shot so I (we) can see what your experiencing ?
Title: Re: Broken (see through) 3D textures in GLBasic 10?
Post by: FutureCow on 2012-May-21
I'll have to see if I can find the download for 11 and see if it's any different.

I've fixed the camera position so I could get a known (repeatable) angle for the screenshots. Below we have all the same code as the original where I've only changed the lines that draw the texture. I've screenshotted the texture first (as per the first screen in the code), then screenshotted the model ("X_CAMERA 1,3,5, 0,0,0" and "X_ROTATION 45,0,1,0")

Screen 1 : I've swapped the white on the original texture for cyan (0,255,255). This is a correctly drawn 3d image.
Code (glbasic) Select
DRAWRECT 0,0,128,128, RGB(0,0,255)
DRAWRECT 4,4,124,124, RGB(0,255,255)           // THIS LINE CHANGED
DRAWRECT 5,62,123,66, RGB(0,255,0)
DRAWRECT 62,5,66,123, RGB(0,255,0)
DRAWRECT 62,62,66,66, RGB(255,0,0)
PRINT "GLBasic", 8,8

(http://img838.imageshack.us/img838/5044/texture1p.png)
(http://img85.imageshack.us/img85/9779/screen1sd.png)

Screen 2: I've changed one drawrect to get back to the original texture. Notice not only are some areas see-through, but the image looks slightly different - it's the exact same angle etc, it's just lost shape where transparent polygons have ended up drawn.
Code (glbasic) Select
DRAWRECT 0,0,128,128, RGB(0,0,255)
DRAWRECT 4,4,124,124, RGB(255,255,255)           // THIS LINE CHANGED
DRAWRECT 5,62,123,66, RGB(0,255,0)
DRAWRECT 62,5,66,123, RGB(0,255,0)
DRAWRECT 62,62,66,66, RGB(255,0,0)
PRINT "GLBasic", 8,8

(http://img440.imageshack.us/img440/2605/texture2z.png)
(http://img692.imageshack.us/img692/7771/screen2az.png)


Screen 3 : My Modified texture which should be a dark green square with light border, but instead results in a see-through grid
Code (glbasic) Select
DRAWRECT 0,0,128,128, RGB(0,100,0)
DRAWRECT 4,4,124,124, RGB(0,200,0)


(http://img814.imageshack.us/img814/2259/texture3j.png)
(http://img689.imageshack.us/img689/6501/screen3qv.png)


I'm running GLBasic 10.283, Windows XP, DirectX 9.0c, Graphics card NVidia GeForce 8800 GTS
Title: Re: Broken (see through) 3D textures in GLBasic 10?
Post by: MrTAToad on 2012-May-21
I presume you haven't set SETTRANSPARENCY to white ? :)

It does it in both V10 and V11, but only for some colours - white and purple, for example produces a see-through effect, but not yellow...

I think this is a job for... Gernot :)
Title: Re: Broken (see through) 3D textures in GLBasic 10?
Post by: FutureCow on 2012-May-21
Thanks for testing all. I've posted a link in the bug forum asking for a moderator to move it there, so hopefully Gernot will be able to take a look at some point.
Title: Re: Broken (see through) 3D textures in GLBasic 10?
Post by: Ian Price on 2012-May-21
Quoteasking for a moderator to move it there
Moved and other post (now not necessary) deleted.

:)
Title: Re: Broken (see through) 3D textures in GLBasic 10?
Post by: Schranz0r on 2012-May-21
FutureCow

Set the wireframe over the fulltextured tarrain +0.001 in Y and let the F U C K GLOW! :D
Title: Re: Broken (see through) 3D textures in GLBasic 10?
Post by: Kitty Hello on 2012-May-22
disable alpha-testing. ALPHATESTING FALSE. Your texture has transparent bits.
Title: Re: Broken (see through) 3D textures in GLBasic 10?
Post by: MrTAToad on 2012-May-22
It works with ALPHATESTING 1.0 :)