SpeedUp FrontColour() ?

Everything else that doesn't fall into one of the other PB categories.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by MrVainSCL.


[== SpeedUp FrontColour()? ==]

I found out that the FrontColour() command is very slow on my game project and i need a faster way to paint/precalc my stuff to screen... If someone have any idea, please tell me!

Code: Select all

For x = 0 To 255 				; Generate my 256x256 texture
   For y = 0 To 255 
      r = Random ((125/1+Random(4))/4)		; Dont blame me, just only a bad example...
      g = Random (2)				
      b = Random ((255/1+Random(8))/4)
      FrontColour (r,g,b)
      Plot (x,y)
    Next
Next
If i want precalc a graphic in only one colour and use FrontColour(255,255,255) at the programstart (not inside the loop) it is very fast... But when i want to precalc a graphic in different colour i must use FrontColour() - its about 4 times slower when drawing a 256x256 texture ;(( Any idea??? Thanks in advance...


PIII450, 256MB Ram, 6GB HD, RivaTNT, DirectX8.1, SB AWE64, Win98SE + Updates...

greetz
MrVainSCL! aka Thorsten
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Danilo.

I think Random() is the slow part,
because it generates a number out
of nothing.

FrontColoUr() sets only a Color value,
so it shouldnt be that slow.

If you really need Random(), you can
make a Number-Table (structure) and
calculate the random numbers at the
beginning of your program (not in the
main-loop).

cya,
...Danilo

(registered PureBasic user)
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Franco.

Danilo,
this is a very good suggestion.
And I agree random must be the one coasing the speed problems.




Have a nice day...
Franco

Sometimes you have to go a lonely way to accomplish genius things.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by MrVainSCL.

Hello Danilo and Franco!
Thanks for the very fast reply... Its not the Random() command... This was my first suspiction but i tried the listed source and unmarked only the FrontColour() command inside the loop... At the programstart i wrote "FrontColour(255,255,255)" - so the Random command works too but without any effect... Its only the FrontColour() command that slow this loop very down... Just try n test it.. You will see... I was a bit wondering too...


PIII450, 256MB Ram, 6GB HD, RivaTNT, DirectX8.1, SB AWE64, Win98SE + Updates...

greetz
MrVainSCL! aka Thorsten
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Danilo.

Well, its not a working example.
There is no StartDrawing() and StopDrawing() etc...

Can you post your complete working example plz ??

cya,
...Danilo

(registered PureBasic user)
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by fred.

Front colour is veru slow on Windows as it creates a brush (yes !) even for a single color. I could try to implement a cache, say for the last 16 colours used or something like that, but it wouldn't help for your example (random value). I will look if there isn't another way to go.

Fred - AlphaSND
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by MrVainSCL.
Front colour is veru slow on Windows as it creates a brush (yes !)
Uarghhhh... i cant believe this - strange! I think this is why we need a new extra "DX2dDrawLib" (DirectX only commands) for faster drawing operations :wink:)
I could try to implement a cache, say for the last 16 colours used or something like that, but it wouldn't help for your example (random value). I will look if there isn't another way to go.
Mhhh that would be nice... thanks fred! Let us say for the last 256 colours (because 256 colors * 3 (r,g,b) is less then 1k of cache and i think that should be ok for the most operations!? Btw. the random command would be slow but it dont slow down my program loop... Its ok :wink:



PIII450, 256MB Ram, 6GB HD, RivaTNT, DirectX8.1, SB AWE64, Win98SE + Updates...

greetz
MrVainSCL! aka Thorsten
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by MrVainSCL.

Ok, some of you wanted a working source example... See how much FrontColour() will slow down your programs...

Code: Select all

;-----------------------------------;
;
; PB2.90 - FrontColour() SpeedTest 
;
;-----------------------------------
;
    #scrw = 640               ; screenwidth
    #scrh = 480               ; screendheight
    #scrd = 16                ; screendepth
;
;-------- Init all the needed system stuff --------
;
;
    If InitSprite() = 0 Or OpenScreen(#scrw,#scrh,#scrd,"FrontColour() SpeedTest") = 0                           
        End                                                                        
    EndIf
;
;-----------------------------------
; 
    StartDrawing(ScreenOutput()) 
      ;
      FrontColour(255,255,255)          ; Set to white if FrontColour() in loop is disabled! 
      ;
      For x = 0 To 255 
          For y = 0 To 255 
            r = Random ((125/1+Random(4))/4)
            g = Random (2)
            b = Random ((255/1+Random(8))/4)
            FrontColour (r,g,b)        ; Just only disable this line to draw in one colour/speed up! 
            Plot (x,y+150)
          Next
      Next
      ;
    StopDrawing()
    ;  
    FlipBuffers()      
    Sleep_ (8000)
End

PIII450, 256MB Ram, 6GB HD, RivaTNT, DirectX8.1, SB AWE64, Win98SE + Updates...

greetz
MrVainSCL! aka Thorsten
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Danilo.

>Front colour is very slow on Windows as it creates
>a brush (yes !) even for a single color.

Maybe that explains that some people reported
that Plot() is very slow too... ??
Your Plot() draws the brush on the screen ??

I thought you can access the directX buffer
directly (*MyScreen = OpenScreen() or so..) ??

Not ??

Thanks,
...Danilo

(registered PureBasic user)
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by MrVainSCL.
I thought you can access the directX buffer
directly (*MyScreen = OpenScreen() or so..) ??
Mhhh.. would be nice to see a working example how to use directX access for drawing any stuff (Plot, line, Frontcolour i.e.) - I think a second 2dDrawLib (dx2ddrawlib i.e) with DirextX access only would be nice for someone and it would be much faster... This lib would be very interested espectly for game developers... Tool coders can still continue using the old 2ddrawlib... :wink: If someone have a working example how to use DircetX buffer, please post it... thanks


PIII450, 256MB Ram, 6GB HD, RivaTNT, DirectX8.1, SB AWE64, Win98SE + Updates...

greetz
MrVainSCL! aka Thorsten
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Danilo.

I only refered to the PureBasic manual
(section "Variables & Types"):

Code: Select all

To use a pointer, put * before the variable name.
A pointer is a long variable which stores an address.
It is generally associated with a structured type.
So, you can access the structure via the pointer. 

Example :
*MyScreen.Screen = OpenScreen(0,320,200,8,0)
With this pointer it should be possible to
access the Screen directly, isnt it ??

cya,
...Danilo
(registered PureBasic user)

Edited by - Danilo on 02 February 2002 13:46:50
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by cor.

When I test the FrontColour example, I get a black screen.

No errors are given by the program?

So it doesn't run at all on my computer.

Registered PB version : 2.90 (Windows)
--------------------------
C. de Visser
Author of Super Guitar Chord Finder
http://www.ready4music.com
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by MrVainSCL.
When I test the FrontColour example, I get a black screen. ... So it doesn't run at all on my computer.
Mhhh... If you try the example with the FrontColour() inside the loop you must wait a few seconds before you can see the precalculated texture... Just remove the FrontColour() command inside the loop and you should get a white box (texture) when starting, because the colour is set via FrontColour(255,255,255) to white at the programstart... I dont know why this small example should not work everytime... mhhhh...

PIII450, 256MB Ram, 6GB HD, RivaTNT, DirectX8.1, SB AWE64, Win98SE + Updates...

greetz
MrVainSCL! aka Thorsten
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Danilo.

well...

FrontColor() outside the loop works.
FrontColor() INside the loop does _not_ work (black screen).

i´m confused...
...Danilo
(Win2kSP2, DX8)

(registered PureBasic user)
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by MrVainSCL.
FrontColor() INside the loop does _not_ work (black screen).
Mhhhh... crazy - i cant believe it... It works ok on my system and should work on any other system too!? When using the FrontColour() inside the loop, you must wait a few seconds... first you have a black screen but after a few seconds you should see the precalculated texture... When compiling the source example, will it end automatical without showing any graphic on screen???? Cant help you... Report Fred about this problem...

PIII450, 256MB Ram, 6GB HD, RivaTNT, DirectX8.1, SB AWE64, Win98SE + Updates...

greetz
MrVainSCL! aka Thorsten
Post Reply