Screen Memory

Game development specific discussions.
vdecampo
Posts: 2982
Joined: Aug 07, 2007 23:20
Location: Maryland, USA
Contact:

Screen Memory

Postby vdecampo » Aug 07, 2007 23:37

Hello,
I am new to FreeBasic but not programming. I have been re-coding a gaming engine and I have encountered a curious problem.

I use internal DIBs to hold all my sprite animations and graphics. (I use this instead of the GFX library because (1. I am more comfortable with them, 2. I can use all the Windows GDI functions like StretchBlt which can both scale objects and will convert pixel formats automatically.)

Anyway, all my graphics are 24bit RGB and I set the screen to 800x600x24. I composite all my sprites onto an internal 24bit image buffer and them use ScreenPtr to copy the image to the screen.

The problem is the final image does not display properly but rather I see 4 copies next to each other with mixed colors and raster lines. This usually means the display surface is not a match for the image data.

I know the data is correct because when I save it to a BMP on the disk it displays fine.

So is the screen really at 800x600x24? Am I setting the display incorrectly?

Code: Select all

               #Define ScreenWidth    800
               #Define ScreenHeight    600

   Dim wPage  As Integer = 1
   Dim vPage  As Integer = 0

   ScreenRes ScreenWidth, ScreenHeight, 24, 2
   ScreenSet wPage, vPage
         
   Do      
               
       ScreenLock
       pScreen = ScreenPtr
       If pScreen>0 then
           MoveMemory pScreen, BackBuffer.pbits, ScreenBytes
           ScreenUnLock
       endif
      
       Swap wPage, vPage
       Screenset wPage, vPage
      
   Loop While Inkey=""
   
   Screen 0
   DestroyMemoryBitmap (BackBuffer)
   
'***************************
anonymous1337
Posts: 5494
Joined: Sep 12, 2005 20:06
Location: California

Postby anonymous1337 » Aug 07, 2007 23:56

Code: Select all

            ScreenLock
            pScreen = ScreenPtr
            If pScreen>0 Then
                MoveMemory pScreen, BackBuffer.pbits, ScreenBytes
                ScreenUnLock
            Endif
Just letting you know, that could lead to you locking a screen that's already locked.

Your code looks fine at first glance. I don't see enough of it to try out myself, sorry.
vdecampo
Posts: 2982
Joined: Aug 07, 2007 23:20
Location: Maryland, USA
Contact:

Postby vdecampo » Aug 08, 2007 1:10

Ok. I changed my internal BackBuffer to 32bits and everything displays fine. Now the question becomes....

Why does this code....

ScreenRes 800, 600, 24, 2

result in a bit depth of 32 bits?

According to the documentation, I should get a 24bpp screen but this is not the case.

Also, is there a way to retreive the current screen res and depth?
DrV
Site Admin
Posts: 2116
Joined: May 27, 2005 18:39
Location: Midwestern USA
Contact:

Postby DrV » Aug 08, 2007 1:35

There are only 3 actual bit depths supported by fbgfx: 8, 16, and 32

When any other bit depth is requested, the next highest supported one is picked (1,2,4->8, 24->32).

Return to “Game Dev”

Who is online

Users browsing this forum: Majestic-12 [Bot] and 3 guests