fullscreen vs. windowed
BlitzPlus Forums/BlitzPlus Programming/fullscreen vs. windowed
| ||
| I've been playing around with some of the graphics commands, and am running into a snag: The code listed below works just fine in windowed mode -- but as soon as I switch to full-screen, it starts acting up. What it is supposed to do: 1) Load a full-color image from disk 2) Change a rectangle to dark black-and-white 3) Load a masked 'frame'-image from disk, which will be used as a border around the B&W area. the screen outside of the border will remail full-color In windowed mode this works just fine, but in full-screen mode both the B&W area and the full-color edges won't get drawn: just the frame itself, with a black box in the middle and black edges around it. Note: To pull up or switch away from the frame image in the code below, press 'TAB'. Press ESC to quit. Any insights would be much appreciated!
Global gfx$
Global frame$
Graphics 640,480,16,1
gfx$=LoadImage("background.jpg") ; 640x480 background image
frame$=LoadImage("frame.png") ; 640x480 overlay image, color 0,255,0 transparent
MaskImage frame$,0,255,0
SetBuffer=BackBuffer()
DrawImage gfx$,0,0
Flip
While True
If KeyDown(1) Then End ; Press Esc
If KeyDown(15) Then ; Press TAB
overlay(100,100,540,380) ; Changes a rectangle to dark greyscale
FlushKeys
While Not KeyDown(15)
Wend
FlushKeys
DrawImage gfx$,0,0
Flip
End If
Wend
Function overlay(xstart,ystart,xend,yend)
SetBuffer=FrontBuffer()
gfxtemp$=CreateImage(640,480)
GrabImage gfxtemp$,0,0
SetBuffer BackBuffer()
DrawImage gfxtemp$,0,0
LockBuffer
For y=ystart To yend
For x=xstart To xend
temp1=ReadPixel(x,y)
orgb=(temp1 And 255)
orgg=(temp1 And 65280) Shr 8
orgr=(temp1 And 16711680) Shr 16
temp2=(orgr+orgg+orgb) Shr 3 ; Average red/green/blue, and darken
WritePixel x,y,temp2+(temp2 Shl 8)+(temp2 Shl 16) ; write greyscale pixels
Next
Next
UnlockBuffer
DrawImage frame$,0,0
Flip
gfxtemp$=""
End Function
|
| ||
Global gfx
Global frame
Graphics 640,480,16,1
gfx = LoadImage("monkey4.jpg") ; 640x480 background image
frame = LoadImage("frame4.png") ; 640x480 overlay image, color 0,255,0 transparent
MaskImage frame,0,255,0
Global overlay_image = CreateImage(1,1) ; temp image for overlay
While Not KeyHit(1)
If KeyHit(15)
create_overlay(100,100,540,380) ; create it
display_overlay(100,100) ; show it and deal with inventory
EndIf
DrawImage gfx,0,0
Flip
Wend
; Create the overlay
Function create_overlay(xstart,ystart,xend,yend)
FreeImage overlay_image
width = xend - xstart
height = yend - ystart
overlay_image = CreateImage(width,height)
CopyRect xstart,ystart,width,height,0,0,ImageBuffer(gfx),ImageBuffer(overlay_image)
SetBuffer ImageBuffer(overlay_image)
LockBuffer
For y = 0 To height
For x = 0 To width
temp1 = ReadPixel(x,y)
orgb = (temp1 And 255)
orgg = (temp1 And 65280) Shr 8
orgr = (temp1 And 16711680) Shr 16
temp2 = (orgr + orgg + orgb) Shr 3 ; Average red/green/blue, and darken
WritePixel x,y,temp2 + (temp2 Shl 8) + (temp2 Shl 16) ; write greyscale pixels
Next
Next
UnlockBuffer
SetBuffer BackBuffer()
End Function
; Show the overlay and the function where you
; can deal with all inventory code.
Function display_overlay(ox,oy)
While Not KeyHit(15)
DrawImage gfx,0,0
DrawImage overlay_image,ox,oy
DrawImage frame,0,0
Flip
Wend
End Function
Working, completely different and a lot less memory intensive. Have fun :) Tracer |
| ||
| Tracer: Unfortunately, your version doesn't work either... createimage(0,0) failed. After changing to createimage(1,1) it started without errors, but doesn't appear to actually do anything. Pressing TAB (scancode 15) doesn't appear to have any effect... In neither windows nor fullscreen mode. |
| ||
| works fine here.. And yeah, the CreateImage(0,0) works fine under B3D, which is what i used to alter your code. BlitzPlus bombs on it (Mark?) http://www.darkeffect.com/tracer/temp/overlay.zip <- try this. Tracer |
| ||
| Nevermind... For some reason Tracer's code didn't like the copy/paste from the forum much -- I downloaded the linked copy, and it worked flawlessly. Thanks! |
| ||
| @xlsior, bare in mind that the right statement for setbuffer is: setbuffer backbuffer() and not, as you wrote in your above example: setbuffer = backbuffer() Read more here: http://www.blitzbasic.com/bpdocs/command.php?name=SetBuffer&ref=goto Sergio. |
| ||
| Duh... You are absolutely right, looks like I kind of used those notations interchangable. (I'm surprised it didn't error out on it) Either way, that by itself was not the only problem - even after fixing those setbuffer statements, my original code still doesn't work properly -- Tracer's version was much appreciated! |