Dark Bit Factory & Gravity

PROGRAMMING => General coding questions => Topic started by: ttemper on January 25, 2012

Title: Full Screen Resolution
Post by: ttemper on January 25, 2012
Hi,

So I'm currently messing around with a 800px by 600px res screen, and I have created a background graphic at 800px by 600px, so it should fit 1:1 inside my screen.

My question is this... when I load in the background image and blit it to screen at the 800x600 res, the left border is ok, but the top, right and bottom 1px are missing... all it has is a black line. I only noticed this as i have a 1px border all the way around my graphic. What am I missing?

I'm currently using FreeBasic and Tinyptc_EXT for the screen setup.

The routines I currently am using are....

Code: [Select]
BGIMGX=800
BGIMGY=600

SUB BGLOADIMAGEDATA()
    DIM I as integer
    'Loads Color palette
    FOR I = 0 to 255
         BGIMG_R( i ) = cgbg.pal (i*3)'Red color
         BGIMG_G( i ) = cgbg.pal (i*3+1)'Green color
         BGIMG_B( i ) = cgbg.pal (i*3+2)'Blue color
    NEXT
    FOR I = 0 to (BGIMGX*BGIMGY) - 1
         BGIMG_BUFFER(i) = cgbg.raw (i)
    NEXT
END SUB

SUB BGDRAWIMAGEDATA(BYVAL xpos AS INTEGER,BYVAL ypos AS INTEGER)
    DIM X,Y,PIXEL as INTEGER
    FOR Y = 0 to BGIMGY-1
        FOR X = 0 to BGIMGX-1
            PIXEL = BGIMG_BUFFER(x+(y*BGIMGX))
            BGWRITEIMAGEDATA( x+xpos,y+ypos, (BGIMG_R(pixel) Shl 16) Or (BGIMG_G(pixel) Shl 8 )  Or BGIMG_B(pixel))
        NEXT
    NEXT
END SUB

SUB BGWRITEIMAGEDATA( byval intX As Integer, byval intY As Integer, byval intC As Integer )
    IF ( intX>0 And intX<XRES-1 ) And ( intY>0 And intY<YRES-1 ) Then
BUFFER( (INTX) + (INTY * XRES) ) = INTC
    END IF   
End SUB

I'm not quite sure why the full 800x600 isn't being blitted.

Thanks in advance.
Title: Re: Full Screen Resolution
Post by: Stonemonkey on January 25, 2012
I'm not sure if this is the cause but since you want to be able to fill pixels at x=0 and the same for other edges use >= and <=
Also it's a good idea to put brackets around all the conditions seperately otherwise the compiler can confuse how the And is to be used.

IF ( intX>=0) And (intX<=XRES-1 ) And ( intY>=0) And (intY<=YRES-1 ) Then

Title: Re: Full Screen Resolution
Post by: ttemper on January 25, 2012
Thanks Stonemonkey, that got it for the top and bottom borders, but the right border seems to be overlapped on the left, so instead of it being from 0,0 to 800x600, it seems to be from 0,0 to 799x600.

I tried adjusting values, but I couldn't seem to get that 1 extra pixel on the XRES. 800, not 799. Not sure what I'm doing wrong.
Title: Re: Full Screen Resolution
Post by: Stonemonkey on January 25, 2012
I can't see anything else atm, how are you displaying the buffer?
Title: Re: Full Screen Resolution
Post by: ttemper on January 25, 2012
The actual loop is...

Code: [Select]
DO
SINWAVE=SINWAVE+DV
OLD=TIMER
SINEWAVE()
   BGDRAWIMAGEDATA(0,0) ' <- HERE IS WHERE IT DRAWS THE BG IMAGE, STARTING AT 0,0
   SCROLLER1(1)
   IF BSTRIGGER = 1 THEN
    SCROLLER2(1)
   ENDIF
   LGDRAWIMAGEDATA(-300+450*SIN(SINWAVE*RAD2DEG/6),(YRES/2)-160)
   STATICTEXT(288,YRES-50+10*COS(SINWAVE*RAD2DEG),"_TEXT 2_")
   STATICTEXT(96,YRES-95+15*SIN(SINWAVE*RAD2DEG),"_TEXT1_")
PTC_UPDATE @BUFFER(0)
ERASE BUFFER
DV=(TIMER-OLD)*150
IF DV>5 THEN DV=5
GADD1 = GADD1+DV
GADD2 = GADD2+DV*2
LOOP UNTIL INKEY$ = CHR$(27)

The way its displaying the background 800x600 graphic at the moment, it looks as tho the pixel is overlapping to the left border.

Just checked, it is overlapping to the left of screen on that 1px

My buffer setup is...

Code: [Select]
DIM SHARED BUFFER(XRES*YRES) as UINTEGER
PTC_SETDIALOG(0,"DEMO TEST"+CHR$(13)+"Full Screen?",0,1)
PTC_OPEN("WE HAVE A SCREEN",XRES,YRES)
Title: Re: Full Screen Resolution
Post by: Stonemonkey on January 25, 2012
You mean it's wrapping round?

I'm wondering if cgbg.raw is indexed from 1.
Title: Re: Full Screen Resolution
Post by: ttemper on January 25, 2012
Yeh, I'ts putting the 800th pixel back on pixel 1 (left border) and pixel 2 on xres is the proper border, so the whole screen seems to be shifted to the right by 1 px, hence the overlap... I cant see where its doing it though. :/

I changed my sinewave logo to the same sub proc, and that also wraps around... for example...

It was this..
Code: [Select]
Sub LGWRITEIMAGEDATA( byval intX As Integer, byval intY As Integer, byval intC As Integer )
    If ( intX>0 And intX<XRES-1 ) And ( intY>0 And intY<YRES-1 ) Then
BUFFER( (INTX) + (INTY * XRES) ) = INTC
    End If   
End SUB

And I changed it to this..
Code: [Select]
Sub LGWRITEIMAGEDATA( byval intX As Integer, byval intY As Integer, byval intC As Integer )
    If ( intX>=0 And intX<=XRES ) And ( intY>=0 And intY<=YRES ) Then
BUFFER( (INTX) + (INTY * XRES) ) = INTC
    End If   
End SUB

Which now I see pixel 800 on xres, wrapped back to pixel 1 on xres.
Title: Re: Full Screen Resolution
Post by: ttemper on January 25, 2012
Ok, so after doing some more testing, as xpos seemed to wrap the screen from 800 back to 1, I changed it to -1 from xres when it blitted to screen.

Heres the code I ended up with...

Code: [Select]
SUB BGDRAWIMAGEDATA(BYVAL xpos AS INTEGER,BYVAL ypos AS INTEGER)
    DIM X,Y,PIXEL,XXPOS,YYPOS as INTEGER
    FOR Y = 0 to BGIMGY-1
        FOR X = 0 to BGIMGX ' as you can see here I removed the -1 from BGIMGX
            IF ( X>=0 ) AND ( X<=XRES ) AND ( Y>=0 ) AND ( Y<=YRES ) THEN
            PIXEL = BGIMG_BUFFER(x+(y*BGIMGX))
            XXPOS = X+XPOS-1 ' the minus one puts pixel 800 for each YPOS back on location 800 (right side of screen) and not on location 1 (left side of screen).
            YYPOS = Y+YPOS ' ypos didn't need adjusting.
            BGWRITEIMAGEDATA( XXPOS,YYPOS, (BGIMG_R(pixel) Shl 16) Or (BGIMG_G(pixel) Shl 8 )  Or BGIMG_B(pixel))           
            ENDIF

        NEXT
    NEXT
END SUB

Not exactly sure why it didn't blit the full 800x600, and then not sure why it didn't blit starting at 0,0.

I just tried to make the logo that moves on the x axis offscreen left to offscreen right, cycle, and when I change the loop to match that of the background image, it still wraps around and I see the 1px from the right border back on the left border 1px. *shrugs*

Any insight as to what is going on?
Title: Re: Full Screen Resolution
Post by: Stonemonkey on January 25, 2012
Since I still can't see anything else I'm womdering if it's this:

BGIMG_BUFFER(i) = cgbg.raw (i)

and if cgbg should be indexed from 1 instead of 0 so you would have this:

BGIMG_BUFFER(i) = cgbg.raw (i+1)

I've not seen any code from that so I can't tell.
Title: Re: Full Screen Resolution
Post by: ttemper on January 25, 2012
You know what, I think that might just be it, I briefly tested it and it seems to work... but I'm tired as and need sleep, will do some more code tomorrow sometime and let you know the outcome.

Thanks again for your input Stonemonkey, much appreciated.
Title: Re: Full Screen Resolution
Post by: ttemper on January 26, 2012
Well that...
Code: [Select]
BGIMG_BUFFER(i) = cgbg.raw (i+1)seems to do the trick for the background image fine. The outcome was the same as my other code with the -1 as I posted before.

As for the sinewaving logo, when I use the same code and put my borders to ">=0 and <=XRES", I still see the logo wrapping from px800 back to px1. Again, no idea why, so I just used ">1 and <XRES-1" for the logo, works fine, no overlap, it just doesn't blit on 1px or 800px, I can live with that I guess.

Again, thanks for your help Stonemonkey.
Title: Re: Full Screen Resolution
Post by: Stonemonkey on January 26, 2012
You have to be careful, it's easy to have something a little bit out and end up reading or writing somewhere you shouldn't. Some machines might be more sensitive to that than others and throw up an error.

in a 800*600 buffer the coords are actually x=0 -> 799    y=0 -> 599

so use either

if (x>=0)and(x<=XRES-1)and(y>=0)and(y<=YRES-1) then

or

if (x>=0)and(x<XRES)and(y>=0)and(y<YRES) then

they both do the same thing and it's down to how you want to think about it although the second one doesn't need the subtractions.