Drawn images using ImageBuffer do not show

Blitz3D Forums/Blitz3D Beginners Area/Drawn images using ImageBuffer do not show

maneesh(Posted 2005) [#1]
Hello

I am writing a program that Draws and Image in an Imagebuffer (using createImage and Plot) and then Tiles the image across the screen. However, the Tile does not work until after I have run the program, clicked another window, and clicked back on to the program. This seems to be an event error, but I don't know how to correct it.

Following is the code.

;INITIALIZATION

;Set up the graphics
Graphics 800,600,0,2



;Seed the Random Generator
SeedRnd MilliSecs()

;CONSTANTS
;The length of each block
Const LENGTH = 100

;The height of each block
Const HEIGHT = 100

;The amount of dots in each block
Const DOTS = 100
;END CONSTANTS



;IMAGES
;Create the dotfield image
dotfieldimage = CreateImage(LENGTH,HEIGHT)
;END IMAGES

;For each dot, draw a random dot at a random location
For loop = 0 To DOTS ;For every star
;draw only on created image
SetBuffer ImageBuffer(dotfieldimage)

;Plot the dot
Plot Rnd(LENGTH), Rnd(HEIGHT)

Next

;Set buffer back to normal
SetBuffer FrontBuffer()
;END INITIALIZATION

;MAIN LOOP

;Tile the image until the user quits (presses ESC)
While Not KeyDown(1)
TileImage dotfieldimage
Wend

;END MAIN LOOP



Thank you

-Maneesh


Conan(Posted 2005) [#2]
must be an error in your computer, works fine for me


maneesh(Posted 2005) [#3]
The error is more obvious (happens 100% of the time) if you change the Graphics code to

Graphics 800,600

So the code becomes:


;INITIALIZATION

;Set up the graphics
Graphics 800,600



;Seed the Random Generator
SeedRnd MilliSecs()

;CONSTANTS
;The length of each block
Const LENGTH = 100

;The height of each block
Const HEIGHT = 100

;The amount of dots in each block
Const DOTS = 100
;END CONSTANTS



;IMAGES
;Create the dotfield image
dotfieldimage = CreateImage(LENGTH,HEIGHT)
;END IMAGES

;For each dot, draw a random dot at a random location
For loop = 0 To DOTS ;For every star
;draw only on created image
SetBuffer ImageBuffer(dotfieldimage)

;Plot the dot
Plot Rnd(LENGTH), Rnd(HEIGHT)

Next

;Set buffer back to normal
SetBuffer FrontBuffer()
;END INITIALIZATION

;MAIN LOOP

;Tile the image until the user quits (presses ESC)
While Not KeyDown(1)
TileImage dotfieldimage
Wend

;END MAIN LOOP


Thanks

-Maneesh


Ross C(Posted 2005) [#4]
The code above tiles the screen with an image. I think his may have something to do with drawing buffers. And i also assume your using blitzplus? If so, it uses the backbuffer for drawing by default.

Put in:

Flip


After your Wend.


Ross C(Posted 2005) [#5]
Try to always use the backbuffer for drawing, then flip before the wend in the main loop. :o)


maneesh(Posted 2005) [#6]
When I put in Flip, it works when not in fullscreen mode. However, in full screen mode, it doesn't work. I get a blank beige screen. What is going on?

Thanks

-Maneesh


Ross C(Posted 2005) [#7]
YOu need to get rid of your setbuffer frontbuffer command. Forgot to mention that ^_^


maneesh(Posted 2005) [#8]
When I set it to use the backbuffer, and use Flip, the screen alternates between blank beige and the star images. I still don't know what is happening.


Ross C(Posted 2005) [#9]
Ok, here's my code :

I changed the SetBuffer FrontBuffer() command to SetBuffer BackBuffer(). And added flip.

;Set up the graphics 
Graphics 800,600 



;Seed the Random Generator 
SeedRnd MilliSecs() 

;CONSTANTS 
;The length of each block 
Const LENGTH = 100 

;The height of each block 
Const HEIGHT = 100 

;The amount of dots in each block 
Const DOTS = 100 
;END CONSTANTS 



;IMAGES 
;Create the dotfield image 
dotfieldimage = CreateImage(LENGTH,HEIGHT) 
;END IMAGES 

;For each dot, draw a random dot at a random location 
For loop = 0 To DOTS ;For every star 
;draw only on created image 
SetBuffer ImageBuffer(dotfieldimage) 

;Plot the dot 
Plot Rnd(LENGTH), Rnd(HEIGHT) 

Next 

;Set buffer back to normal 
SetBuffer BackBuffer()
;END INITIALIZATION 

;MAIN LOOP 

;Tile the image until the user quits (presses ESC) 
While Not KeyDown(1) 
TileImage dotfieldimage
Flip
Wend 

;END MAIN LOOP



maneesh(Posted 2005) [#10]
Awesome thanks! The only thing is, when I run your program, it flips very rapidly and you can very easily see a blank beige color being alternated at the same time as the star image. Do you know why?


Ross C(Posted 2005) [#11]
Are you using the exact same code as mine?


maneesh(Posted 2005) [#12]
yes, i copied and pasted it directly. Is it a problem with my computer?


maneesh(Posted 2005) [#13]
This is blitzplus, by the way


Ross C(Posted 2005) [#14]
I'm running this in blitzplus. Seems like an odd thing to happen. Have you set, or changed anything in your graphics card drivers?

Try: (added in a cls at the top of the main loop)

;Set up the graphics 
Graphics 800,600 



;Seed the Random Generator 
SeedRnd MilliSecs() 

;CONSTANTS 
;The length of each block 
Const LENGTH = 100 

;The height of each block 
Const HEIGHT = 100 

;The amount of dots in each block 
Const DOTS = 100 
;END CONSTANTS 



;IMAGES 
;Create the dotfield image 
dotfieldimage = CreateImage(LENGTH,HEIGHT) 
;END IMAGES 

;For each dot, draw a random dot at a random location 
For loop = 0 To DOTS ;For every star 
;draw only on created image 
SetBuffer ImageBuffer(dotfieldimage) 

;Plot the dot 
Plot Rnd(LENGTH), Rnd(HEIGHT) 

Next 

;Set buffer back to normal 
SetBuffer BackBuffer()
;END INITIALIZATION 

;MAIN LOOP 

;Tile the image until the user quits (presses ESC) 
While Not KeyDown(1)

cls
TileImage dotfieldimage
Flip
Wend 

;END MAIN LOOP



Ross C(Posted 2005) [#15]
You say beige? That's an odd color to be changing too...


maneesh(Posted 2005) [#16]
Perfect, that fixes it completely! Any idea why the Cls command would have any effect here?

Thanks

-Maneesh


Ross C(Posted 2005) [#17]
Might be something to do with the tileimage command drawing over the previous contents of the buffer. I can't be sure :o) Usually put a cls in anyway, to wipe the buffer clean, before i draw.