Drawing Window mode & sync

Just starting out? Need help? Post your questions and find answers here.
heaven6502
User
User
Posts: 20
Joined: Mon Jan 26, 2009 1:43 pm

Drawing Window mode & sync

Post by heaven6502 »

Clearing screen or what is best practice having

I am opening a window with:

If CreateImage(0, 640, 480) And OpenWindow(0,0,0,640,480,"Fractal Lines",#PB_Window_SystemMenu)
...

and do simple 2d drawing (linexy) with
StartDrawing(ImageOutput(0))
StopDrawing()

but how can I clear the window and wait for sync with monitor refresh so I can render an realtime animation without flickering?

actually I need windowed screen where I can simply draw with the basic 2d functions (setting pixels, drawing lines, not sprites etc)... and clear it (without doing a fake BOX draw with background color).

and best... without flickering as waiting for a sync?

Thanks for help here again.
User avatar
Demivec
Addict
Addict
Posts: 4266
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Drawing Window mode & sync

Post by Demivec »

Use a windowed Screen by using OpenWindowedScreen() after your OpenWindow().

Code: Select all

If CreateImage(0, 640, 480) And OpenWindow(0,0,0,640,480,"Fractal Lines",#PB_Window_SystemMenu)
  And OpenWindowedScreen(WindowID(0),0,0,640,480)
...

;and with a loop that first checks for WindowEvents then includes:
ClearScreen(RGB(0, 0, 0)) ;background color

;then first do simple 2d drawing (linexy) with
StartDrawing(ImageOutput(0))
StopDrawing()

;then use the following to either DrawImage(ImageID(0)) or do all simple 2d drawing (linexy) instead of using an image
StartDrawing(ScreenOutput())
StopDrawing()

;display results before continuing loop
FlipBuffers()
heaven6502
User
User
Posts: 20
Joined: Mon Jan 26, 2009 1:43 pm

Re: Drawing Window mode & sync

Post by heaven6502 »

well... actually 5.11 tells me to use initsprite() before?
heaven6502
User
User
Posts: 20
Joined: Mon Jan 26, 2009 1:43 pm

Re: Drawing Window mode & sync

Post by heaven6502 »

Code: Select all

InitKeyboard()
InitSprite()

CreateImage(0, 800, 480) 
OpenWindow(0,0,0,800,480,"Fractal Lines",#PB_Window_SystemMenu) 
OpenWindowedScreen(WindowID(0),0,0,800,480) 
;StartDrawing(ScreenOutput()) 
frame=0
z0.w =100

    camx.w=0
    camy.w=-40
    camz.w=0

Repeat
  ClearScreen(RGB(0,255,0))
  
  For i=0 To max_width-1
    ybuffer(i)=h
    heights(i)=h
  Next
    draw_grid()
    
        
;StopDrawing()
;SaveImage(0,"bars2.bmp",#PB_ImagePlugin_BMP) 
FlipBuffers() 
;ImageGadget(0, 0, 0, xres, yres, ImageID(0))

camz=camz+1
camz=camz&$00f

Until WindowEvent()=#PB_Event_CloseWindow 


it actually only displays something when I got the ImageGadget(0,0,0,xres,yres,ImageID(0)) in the code at the end but flickers badly.
heaven6502
User
User
Posts: 20
Joined: Mon Jan 26, 2009 1:43 pm

Re: Drawing Window mode & sync

Post by heaven6502 »

fcking cool. I overread the startdrawing(screenoutput()) instead of imageoutput... now works!
Post Reply