Problems with BackbuffertoTex()
BlitzMax Forums/MiniB3D Module/Problems with BackbuffertoTex()
| ||
hi, I was currently checking out the BackbuffertoTex Function and realized that this doesn't work on any PC I was testing. The curious is CubemapRender works perfectly and other r2t codes from others works also but somehow minib3ds version doesn't work. Here is my code: Import "../MiniB3D.bmx" Strict Local width=640,height=480,depth=16,mode=0 Graphics3D width,height,depth,mode Local cam:TCamera=CreateCamera() CameraClsColor(Cam,255,0,0) Local light:TLight=CreateLight() Local ent1:TMesh=CreateCube() Local tex:TTexture=LoadTexture("media/test.png") EntityTexture ent1,tex Local ent2:TMesh=TMesh(CopyEntity(ent1)) Local ent3:TMesh=TMesh(CopyEntity(ent1)) Local ent4:TMesh=TMesh(CopyEntity(ent1)) Local ent5:TMesh=TMesh(CopyEntity(ent1)) Local ent6:TMesh=TMesh(CopyEntity(ent1)) PositionEntity ent1,0,0,10 PositionEntity ent2,0,0,5 PositionEntity ent3,0,0,20 PositionEntity ent4,0,0,15 PositionEntity ent5,0,0,30 PositionEntity ent6,0,0,25 EntityAlpha ent2,0.5 EntityAlpha ent4,0.5 ' used by camera code Local mxs#=0 Local mys#=0 Local move#=0.5 MouseXSpeed() ' flush MouseYSpeed() ' flush ' used by fps code Local old_ms=MilliSecs() Local renders Local fps Local Sprite:TMesh = CreateCube() PositionEntity(Sprite,-4,0,5) Local STex:TTexture = TTexture.CreateScreenTexture(256) EntityTexture Sprite,STex While Not KeyDown(KEY_ESCAPE) If KeyHit(KEY_ENTER) Then DebugStop '' control camera ' mouse look mxs#=mxs#+(MouseXSpeed()/5.0) mys#=mys#+(MouseYSpeed()/5.0) RotateEntity cam,mys#,-mxs#,0 MoveMouse width/2,height/2 MouseXSpeed() ' flush MouseYSpeed() ' flush ' move camera forwards/backwards/left/right with cursor keys If KeyDown(KEY_UP)=True Then MoveEntity cam,0,0,move# ' move camera forward If KeyDown(KEY_DOWN)=True Then MoveEntity cam,0,0,-move# ' move camera back If KeyDown(KEY_LEFT)=True Then MoveEntity cam,-move#,0,0 ' move camera left If KeyDown(KEY_RIGHT)=True Then MoveEntity cam,move#,0,0 ' move camera right '' If Renders Mod 1 = 0 Then Mirror(Cam,STex,Sprite) RenderWorld renders=renders+1 ' calculate fps If MilliSecs()-old_ms>=1000 old_ms=MilliSecs() fps=renders renders=0 EndIf Text 0,0,"FPS: "+String(fps) Flip Wend End Function Mirror(Cam:TCamera,STEx:TTexture,Sprite:TEntity) CameraViewport(Cam,0,0,256,256) CameraClsMode(Cam,False,True) HideEntity Sprite RenderWorld 'Flip BackBufferToTex(STex) ShowEntity(Sprite) CameraViewport(Cam,0,0,640,480) CameraClsMode(Cam,True,True) End Function Am i doing something wrong? I really have to find out why this doesn't work as I need the function to establish shader based posteffects etc. . thx for the help |
| ||
EDIT: dont need these to test...(dou you have the test.png and the CreateScreenTexture function? I would like to run your code to see if i can help but those look integral to the problem.) Initially, it looks like backbuffertotex is working on a single pixel (not the 256x256 area) |
| ||
It's because of mipmaps. You are copying only to the main texture, which will not be displayed unless you are very close to the texture. Otherwise, mipmaps will be displayed which haven't been copied to. Use ClearTextureFilters after Graphics3D (to disable mipmapping) and it will work. |
| ||
thx, now it works :) @bradford: sry the CreatescreenTexture was just a testing function and I haven't updated the code. the above way it doesn't work neither with the CreateTexture() Function without using simons advice :) |