Raycaster Library
-
- PureBasic Expert
- Posts: 2812
- Joined: Fri Apr 25, 2003 4:51 pm
- Location: Portugal, Lisbon
- Contact:
New lib works just fine, but how does one define which sprite is the texture one?
In the big example you assign the sprite to a dx surface, but wouldn't it be easier to have a command like.
Set_texture(sprite,texture)
where sprite would be PB sprite number a texture would be the wall (a,b,c,d)
Can you gimme an easy example otherwise?
In the big example you assign the sprite to a dx surface, but wouldn't it be easier to have a command like.
Set_texture(sprite,texture)
where sprite would be PB sprite number a texture would be the wall (a,b,c,d)
Can you gimme an easy example otherwise?
Hi
Yes, it is also possible to load each texture like a sprite. In the example the sprites are single bitmaps. The walls are all together, exept the door. In the SetupTextures.inc file you can see, that the door texture is loaded as a single texture. You can make this with all other textures. But you have to change the blt command in the ProcRenderScene.inc to choose the correct texture for the texture number and declare this surface as a global variable. I made it this way to make it simpler (same surface). But it's up to you how to make it.
Edit...
If you want to add new textures (Walls) (b to z), you can just add a new picture at the end of the Textures.bmp. It will choose itself the correct texture. The texture.bmp lenght can be 64* the number of textures.
Yes, it is also possible to load each texture like a sprite. In the example the sprites are single bitmaps. The walls are all together, exept the door. In the SetupTextures.inc file you can see, that the door texture is loaded as a single texture. You can make this with all other textures. But you have to change the blt command in the ProcRenderScene.inc to choose the correct texture for the texture number and declare this surface as a global variable. I made it this way to make it simpler (same surface). But it's up to you how to make it.

Edit...
If you want to add new textures (Walls) (b to z), you can just add a new picture at the end of the Textures.bmp. It will choose itself the correct texture. The texture.bmp lenght can be 64* the number of textures.
Last edited by pg on Wed Jul 21, 2004 9:13 pm, edited 1 time in total.
-
- PureBasic Expert
- Posts: 2812
- Joined: Fri Apr 25, 2003 4:51 pm
- Location: Portugal, Lisbon
- Contact:
I understand how it works.
What i'm missing is how does the engine know which buffer the walls are...
Example:
Loadbitmap(0,"all_wall_textures.bmp")
How do i say to the engine, scan this buffer to read the textures....
There is no SetWallTexture(bitmapnumber)...
Must i always declare a TextureBuffer.IDirectDrawSurface7 so that the engine can grab the textures from there?
In other words i'm just trying to get the easy example to have textures
I've worked it all out, i even know how to make ligth FX with a dinamic map, but i haven't yet understand where the engine reads the textures from
What i'm missing is how does the engine know which buffer the walls are...
Example:
Loadbitmap(0,"all_wall_textures.bmp")
How do i say to the engine, scan this buffer to read the textures....
There is no SetWallTexture(bitmapnumber)...
Must i always declare a TextureBuffer.IDirectDrawSurface7 so that the engine can grab the textures from there?
In other words i'm just trying to get the easy example to have textures

I've worked it all out, i even know how to make ligth FX with a dinamic map, but i haven't yet understand where the engine reads the textures from

Aha, i think I know what you mean. The engine knows the texture number with the command GetTexture(ray).
Example:
If the command GetTexture(a) returns 5 (5=e in the map), then this will get the bitmapposition at 5*64 in the texture.bmp. It just moves a 64*64 clipping rectangle with blt and copies it. With this, you just have to add a new 64*64 pixel texture at the end of the texture.bmp when you add a new wall in the map.
If GetTexture(a) returns 2 (=b) , it is the first 64*64 pixel texture in the texture.bmp
This is how it clips the rectangle.
The texturecolumn is the column number of the the texture returned by GetTexture().
Does this answer your question?
Example:
If the command GetTexture(a) returns 5 (5=e in the map), then this will get the bitmapposition at 5*64 in the texture.bmp. It just moves a 64*64 clipping rectangle with blt and copies it. With this, you just have to add a new 64*64 pixel texture at the end of the texture.bmp when you add a new wall in the map.
If GetTexture(a) returns 2 (=b) , it is the first 64*64 pixel texture in the texture.bmp
This is how it clips the rectangle.
Code: Select all
sldestRect\left = a+100;
sldestRect\top = 300-scale;
sldestRect\right = a+100+1;
sldestRect\bottom = 300+scale;
slsrcRect\left = ((texnum - 2) * 64) + texcol;
slsrcRect\top = 1;
slsrcRect\right = ((texnum - 2) * 64) + texcol+1;
slsrcRect\bottom = 64;
SceneBuffer\Blt(sldestRect, TextureBuffer, slsrcRect, 0, 0)
Does this answer your question?
Here is an example, not perfect at all sorry. You have to put the Texture.bmp in the same folder!
Code: Select all
sldestRect.RECT
slsrcRect.RECT
destRect.RECT
eraserect.RECT
;rect for black sprite
eraserect\left=0
eraserect\top=0
eraserect\right=320
eraserect\bottom=200
; rect to copy buffer to buffer
destRect\left=160
destRect\top=140
destRect\right=480
destRect\bottom=340
Declare GetBackBuffer()
Declare GetPrimaryBuffer()
InitSprite()
InitKeyboard();
WndScrID = OpenScreen(640, 480, 16, "")
InitMouse()
TextureBuffer.IDirectDrawSurface7 =LoadSprite(0, "Textures.bmp", 0)
FlipBuffer.IDirectDrawSurface7 =CreateSprite(2,520,600);320,600
backbuffer.IDirectDrawSurface7 =GetBackBuffer()
erase.IDirectDrawSurface7 =CreateSprite(3,320,200)
InitRaycaster()
Load_World("raymap.dat")
PositionPlayer(2,2,100)
SetMaxScale(400)
CloseDoor(1) ;open doors
Repeat
ExamineMouse()
KeyAction(-MouseDeltaY(),-MouseDeltaX()) ; move the player
For a.l= 0 To 319
texnum.l=GetTexture(a)
texcol.l=GetTextureColumn(a)
scale=GetScale(a)/2
If texnum=26:texnum=8:EndIf ; no door, else no texture at z...bitmap lenght too short
sldestRect\left = a+160
sldestRect\top = 240-scale;
sldestRect\right = a+160+1
sldestRect\bottom = 240+scale;
slsrcRect\left = ((texnum - 1) * 64) + texcol;
slsrcRect\top = 1;
slsrcRect\right = ((texnum - 1) * 64) + texcol+1
slsrcRect\bottom = 64;
FlipBuffer\Blt(sldestRect, TextureBuffer, slsrcRect, 0, 0)
Next a
;copy scene to bacjbuffer
backbuffer\Blt(destRect, FlipBuffer, destRect, 0, 0)
FlipBuffers()
;erase backbuffer
ClearScreen(0,0,0)
;Erase the the rendering buffer
FlipBuffer\Blt(destRect, erase, eraserect, 0, 0)
ExamineKeyboard()
Until KeyboardPushed(#PB_Key_Escape)
End
Procedure.l GetPrimaryBuffer()
!extrn _PB_DirectX_PrimaryBuffer
!mov eax, [_PB_DirectX_PrimaryBuffer]
ProcedureReturn
EndProcedure
Procedure.l GetBackBuffer()
!extrn _PB_DirectX_BackBuffer
!mov eax, [_PB_DirectX_BackBuffer]
ProcedureReturn
EndProcedure
This is pretty blooming impressive!
Using the simple example, after moving around a bit the title bar starts flickering v fast across the top of the screen, to the right of the scenario. You can see the bar and the [X] close button. Happens with both the .pb and the .exe
Haven't managed to make that happen with the other example.
Good stuff, this!
Using the simple example, after moving around a bit the title bar starts flickering v fast across the top of the screen, to the right of the scenario. You can see the bar and the [X] close button. Happens with both the .pb and the .exe
Haven't managed to make that happen with the other example.
Good stuff, this!
@}--`--,-- A rose by any other name ..
got the same with a lot of proggies, you wouldn't...
- be running on a multimonitor system?
- use a non-standard desktop size? (1152 x 8xx or something)
- use a desktop size that is different from the screensize?
all these things do cause that...
- be running on a multimonitor system?
- use a non-standard desktop size? (1152 x 8xx or something)
- use a desktop size that is different from the screensize?
all these things do cause that...
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
( The path to enlightenment and the PureBasic Survival Guide right here... )