[5.20 LTS] Camera ViewPort not correctly updated w Sprites

All bugs related to the 3D engine
User avatar
Danilo
Addict
Addict
Posts: 3037
Joined: Sat Apr 26, 2003 8:26 am
Location: Planet Earth

[5.20 LTS] Camera ViewPort not correctly updated w Sprites

Post by Danilo »

If we use a camera smaller than 100 percent, the viewport is not updated correctly, when using PB Sprites with SubSystem 'opengl'.

In the following example we use two modes: 0 and 1
In mode 0, the camera is 100% x 100% and everything is fine.
In mode 1, the camera is 50% x 50% of the screen, but the real viewport is still 100% x 100% (OpenGL subsystem only).

Please note:
The problem disappears if you remove the line with DisplayTransparentSprite().
After removing the line with DisplayTransparentSprite(), the viewport is correct in mode 1.

With DisplayTransparentSprite(), the viewport of the camera in mode 1 (50%,%0%) is wrong.
50%,50% is displayed, but the rotating box is still in 100%,100% viewport.

Code: Select all

#MODE = 1 ; mode 0 or 1


CompilerIf #MODE = 0
#CAM_WIDTH  = 100
#CAM_HEIGHT = 100
CompilerElseIf #MODE = 1
#CAM_WIDTH  = 50
#CAM_HEIGHT = 50
CompilerEndIf

Procedure Draw()   
    DrawingMode(#PB_2DDrawing_AllChannels)
    Box(0,0,OutputWidth(),OutputHeight(),RGBA(0,0,0,0))
    DrawingMode(#PB_2DDrawing_Outlined|#PB_2DDrawing_AlphaBlend)
    Box(0,0,OutputWidth(),OutputHeight(),RGBA(255,255,255,255))
EndProcedure

If InitEngine3D()=0 Or InitSprite()=0
    End
EndIf

If OpenWindow(0,0,0,400,400,"Camera ViewPort",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
    
    OpenWindowedScreen(WindowID(0),0,0,400,400)
    
    CreateCamera(0,0,0,#CAM_WIDTH,#CAM_HEIGHT)
    CameraBackColor(0, RGB(29, 117, 188))
    MoveCamera(0, 0, 0, 10)
    CameraLookAt(0, 0, 0, 0)
    
    CreateSprite(0,128,128,#PB_Sprite_AlphaBlending)
    If StartDrawing(SpriteOutput(0))
        Draw()
        StopDrawing()
    EndIf
    
    tex = CreateTexture(#PB_Any, 128, 128)
    If StartDrawing(TextureOutput(tex))
        Draw()
        StopDrawing()
    EndIf
    
    mat=CreateMaterial(#PB_Any, TextureID(tex))
    MaterialCullingMode(mat, #PB_Material_ClockWiseCull)
    MaterialFilteringMode(mat, #PB_Material_None)
    MaterialBlendingMode(mat, #PB_Material_AlphaBlend)
    DisableMaterialLighting(mat, #True)
    obj=CreateCube(#PB_Any,  4)
    ;obj = CreatePlane(#PB_Any,4,4,20,20,1,1)
    ent=CreateEntity(#PB_Any, MeshID(obj), MaterialID(mat))
    
    RotateEntity(ent, 45, 45, 45, #PB_Absolute)

    Repeat
        Repeat
            event = WindowEvent()
            If event = #PB_Event_CloseWindow
                quit = 1
            EndIf
        Until event = 0
        Delay(20)
        
        RotateEntity(ent, 0.2, 0.4, 0.6, #PB_Relative)
        RenderWorld()
        DisplayTransparentSprite(0,0,0) ; remove this line and viewport is correct in #mode = 1
        FlipBuffers()
        
    Until quit
EndIf
DX9 screenshot (default):
Image

opengl subsystem screenshot, wrong camera viewport:
Image

Same bug on Mac OS X with default OpenGL implementation.