September 26, 2022, 12:19:06 AM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Texture Problem

Started by YarSnez, July 12, 2008, 04:03:15 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

YarSnez

July 12, 2008, 04:03:15 AM Last Edit: July 12, 2008, 02:30:19 PM by YarSnez
Hi,

I am experimenting with 3d graphics in e-basic and created the following simple little program ( heavily based on the example code  ;) ) to create a sphere and apply a texture of earth.  It's been done so many times before but is a good starting point.

Const DIK_ESCAPE = 0x01

Declare Import, QueryPerformanceFrequency( Pointer lpFrequency ), Int
Declare Import, QueryPerformanceCounter( Pointer lpPerformanceCount ), Int

C3DScreen Screen
C3DCamera Camera1
C3DObject Scene
C3DLight Light1
C3DMesh Ball

Double fTarget, flAdjust : fTarget=75.0 : fAdjust = 1.0
Int64 Freq
QueryPerformanceFrequency( Freq )
Double Dfreq
Dfreq = Freq

Screen.CreateWindowed( 0,0, 1024, 768, @CAPTION|@SIZE, "My 3D World", NULL, True )

Camera1.Create( Screen )
Camera1.Position( 0, 0, -1.5 )
Camera1.Orient( 0, 0, 1, 0, 1, 0 )
Camera1.SetBackPlane( 500 )

Screen.Clear(RGBA( 0, 0, 0, 255 ) )
Screen.BeginScene( Camera1 )
Light1.Create( Screen, LIGHT_POINT, 1 )
Light1.Position( 0, 20, -150 )
Light1.SetAttenuation( 0, 1/200.0, 0 )
Light1.SetSpecular( .8, .8, .8, 1 )
Light1.SetDiffuse ( .8, .8, .8, 1)
Light1.SetAmbient( .4, .4, .4, 1 )

Scene.CreateScene( Screen )
Ball.CreateSphere( Screen, 25, .25, false )
Ball.EnableLighting( true )
Scene.AddChild( Ball )
Scene.AddChild( Light1 )

Ball.LoadTexture(0, GetStartPath + "EarthNight2.jpg", 0 )
Ball.UseVertexColor( false )
Ball.Position( 0, 0, 0 )

Double StartTime
StartTime = 0.0
Int64 nStartTime

do
QueryPerformanceCounter( nStartTime )
StartTime = nStartTime

Ball.Rotate( -(400 / 1000.0f), MILLISECS() / 3000.0f, 0)

Screen.Clear( RGBA( 0, 0, 0, 255 ) )
Screen.BeginScene( Camera1 )
Scene.Draw()
Screen.SetFont("Arial", 28, 800)
Screen.RenderText( 10, 10, "Earth", RGBA( 255, 255, 255, 255 ) )
Screen.RenderText( 12, 11, "Earth", RGBA( 5, 200, 20, 255 ) )
Screen.RenderScene()

QueryPerformanceCounter( nStartTime )
fAdjust = ( ( nStartTime - StartTime) / Dfreq) * fTarget

until KeyDown( DIK_ESCAPE )
Scene.Free()

Sub RGBAtoD3DC(UINT col),D3DCOLORVALUE
D3DCOLORVALUE ret
ret.b = (col & 0xff) / 255.0
ret.g = ((col & 0xff00) >> 8) / 255.0
ret.r = ((col & 0xff0000) >> 16) / 255.0
ret.a = ((col & 0xff000000) >> 24) / 255.0
return ret
EndSub


The Earth is created ( not in 6 days but in seconds  :D ) and the texture applied, but look carefully as the Earth rotates and you will see two New Zealands.  Checking the texture with a paint program reveals only one New Zealand, so somehow my program is upsetting the texture.  I have tried with other textures and scaliing them so that the width and height are in multiples of 256 pixels, but still have this problem.  Have also tried various radius settings but no luck.  Checking all the supplied textures in the examples I see they are sized in multiples of 256 pixels so felt sure this was the issue. Does anyone have any ideas as to what might be wrong?

Thanks.

Yarsnez.


I have now tried the same texture using Blitz basic and this is ok.  So think this is possibly a bug in the texture assignment in e-basic unless I am missing something?

Yarsnez.

pistol350

July 12, 2008, 04:15:01 AM #1 Last Edit: July 12, 2008, 04:22:47 AM by pistol350
unfortunately you don't provide your texture.
That can be helpful as your problem is about texture mapping.


Edit: I tried with the texture below and things seem to be OK.
Regards,

Peter B.

YarSnez

Thanks for the reply.

That texture is the one I'm using and gives me two New Zealands!  Very strange.

Yarsnez

YarSnez

I have found some nice Earth textures here:

http://oera.net/How2/TextureMaps.htm

But they exhibit the same problem even when scaled to widths and heights divisible by 256 pixels on my machine.

???

Yarsnez

RG

I get the same problem using your program. It looks like the texture map isn't wide enough and so it is being repeated on the right edge to fill in the gap. Can't explain why it behaves that way.

YarSnez

Quote from: RG on July 12, 2008, 02:24:05 PM
I get the same problem using your program. It looks like the texture map isn't wide enough and so it is being repeated on the right edge to fill in the gap. Can't explain why it behaves that way.

No I can't explain either, but suspect that as the same texture works in Blitz basic the problem is not down to the texture but either how I am applying it or how e-basic is applying it.  Thanks for confirming it happends on your PC.

Yarsnez

pistol350

you're right.
The texture does not wrap properly.
After looking a bit more carefully i saw what you talked about.
By the way, thanks for the link, there are really great textures there.
Regards,

Peter B.

Ionic Wind Support Team

Oh it is probably an error in my UV calculations.  Try an even number for the bands.
Ionic Wind Support Team

YarSnez

Quote from: Paul Turley on July 12, 2008, 08:53:15 PM
Oh it is probably an error in my UV calculations.  Try an even number for the bands.

Hi Paul.  I have now tried various band settings within the region of 8 - 140 both odd and even and get varying degrees of overlap   With just 8 bands half of Australia is duplicated but as I increase the number things dramatically improve.  At about 160 onwards I can't see any problem, so not sure if this is a bug or that I need to experiment more with the number of bands for certain textures? 

Thanks for the feedback.

Yarsnez. 

Ionic Wind Support Team

It's probably an error in my calculations as stated.  The sphere is created on the fly and texture coordinates assigned to the vertices.
Ionic Wind Support Team

YarSnez

Quote from: Paul Turley on July 13, 2008, 12:38:53 PM
It's probably an error in my calculations as stated.  The sphere is created on the fly and texture coordinates assigned to the vertices.

Ok.  It's not an issue that will hinder me at present, I'm just learning things at the moment.