• Welcome to Dark Bit Factory & Gravity.
 

Writepixel dll[BB2D]

Started by Paul, January 03, 2007

Previous topic - Next topic

0 Members and 0 Guests are viewing this topic.

Paul

Hi
Would it be possible to make a "Writepixel dll" for Blitz in C++? :inspired:
Since the built in one is so slow.  :(

I can unfortunately not program in C++ and absolutely not make dlls. I'm thinking it could be done by letting blitz send an array to the dll and the dll drawing the whole screen, maybe masking some colour(s).



I will bite you - http://s5.bitefight.se/c.php?uid=31059
Challenge Trophies Won:

mike_g

Sorry, I dont know how that could be done but have you tried using SDL?

Ghost^BHT

 Blitz+ (although I don't have it) is faster than blitz or blitz3d for pixelwise operations. If you search you can also find some functions written by coders that uses banks to mimic the locked pixel command of B+ and that's supposed to be faster.

Paul

It could be done using api_setpixel but thats probably slower than the built in ones in blitz
I will bite you - http://s5.bitefight.se/c.php?uid=31059
Challenge Trophies Won:

Jim

In blitz it seems to always be faster to draw into a bank or array and copy it to the screen wholesale, even if that means using writepixelfast to move it over.

api_SetPixel is calling Windows GDI?  If so that is REALLY slow.

Jim
Challenge Trophies Won:

Stonemonkey

#5
I have no idea if this'll work or how to get it working in blitz but it's a little dll written in freebasic that uses tiny_ptc that i'd started messing around with ages ago. You won't be able to use any of blitz's graphics functions with this though if you can get it working.

http://www.stonemonkie.pwp.blueyonder.co.uk/sm_dll.zip

EDIT: Just tried to get this working in blitz but can't seem to work it out.

Paul

Would it be possible to run a sub from a dll?
Do you do it the same way as you run a function???
I will bite you - http://s5.bitefight.se/c.php?uid=31059
Challenge Trophies Won:

Stonemonkey

I think so but with blitz the dll has to be placed in the userlibs folder along with a .decls file which in this case should look something like:

file 'sm_dll.decls'

.lib "sm_dll.dll"

create_buffer%( w%,h% ):"create_buffer"
setup_graphics%( w%,h% ):"setup_graphics"
close_graphics( b% ):"close_graphics"
flip_buffer( b% ):"flip_buffer"
clear_buffer( bi%,c% ):"clear_buffer"

set_pixel( bi%,x%,y%,c% ):"set_pixel"
get_pixel%( bi%,x%,y% ):"get_pixel"


But there's something wrong somewhere.


Paul

#8
I've found that the builtin commands (writepixelfast) is about 2X the speed of this but its a good start :D and you dont need to think about the lockbuffer widh i usually forget

decels by paul at least some of them seem to work


.lib "sm_dll.dll"
create_buffer%(wwidth,height):"create_buffer@8"
setup_graphics(wwidth,height):"setup_graphics@8"
close_graphics(bufferi):"close_graphics@4"
flip_buffer(bufferi):"flip_buffer@4"
clear_buffer(bufferi):"clear_buffer@8"

set_pixel(bufferi,x,y,argb):"set_pixel@16"
get_pixel%(bufferi,x,y):"get_pixel@12"
set_pixel_fast(bufferi,x,y,argb):"set_pixel_fast@16"
get_pixel_fast%(bufferi,x,y):"get_pixel_fast@12"

fill_rect(bufferi,x0,y0,x1,y1,argb):"fill_rect@24"
fill_triangle(bufferi,x0,y0,x1,y1,x2,y2,argb):"fill_triangle@32"
fill_gtriangle(bufferi,x0,y0,argb0,x1,y1,argb1,x2,y2,argb2):"fill_gtriangle@40"

;::::::::::::::::::::::::::::::::::::::::

setup_graphics(400,300)
buff=create_buffer(400,300)
flip_buffer(buff)

While Not KeyHit(1)
fill_rect(buff,10,10,100,100,255)
flip_buffer(buff)
Wend

;:::::::::::::::::::::::::::::::::::::::::::::::::


Edit:

setup_graphics(400,300)
buff=create_buffer(400,300)
flip_buffer(buff)

While Not KeyHit(1)
;fill_rect(buff,10,10,100,100,255)
For x=0 To 400
For y=0 To 300
set_pixel_fast(buff,x,y,255)
Next
Next
flip_buffer(buff)
Wend
I will bite you - http://s5.bitefight.se/c.php?uid=31059
Challenge Trophies Won:

Stonemonkey

Sorry, I'm off out now but well done on getting that working so far.

Paul

I'm wondering something else is it faster having a bank or an array for your screen array.
I will bite you - http://s5.bitefight.se/c.php?uid=31059
Challenge Trophies Won:

Stonemonkey

When writing software 3d stuff in blitz a while ago I tried both but even though using an array involved writing everything to the screen buffer at the end I found hardly any difference and just stuck to using arrays as far as i can remember.

Stonemonkey

just noticed, your test code should be:

buff=setup_graphics(400,300)

While Not KeyHit(1)
   ;fill_rect(buff,10,10,100,100,255)
   For x=0 To 399
      For y=0 To 299
         set_pixel_fast(buff,x,y,255)
      Next
   Next
   flip_buffer(buff)
Wend


setup_graphics creates a buffer and returns it's handle although what you had should probably work too.
Another thing is that you would've been writing outside the buffer with 0 to 400 and 0 to 300 and set_pixel_fast doesn't have any bounds checking.

Stonemonkey

#13
OK, I've got it working but it's very slllloooooowwwwwwwww. Not much use at all.

EDIT: oops, not used blitz for a while and had debug on. It's faster now but it's still messing up the keyboard, must be something to do with tiny_ptc.

Paul

#14
An other thing...
If you use that test you will need to change the .decls file from


setup_graphics(wwidth,height):"setup_graphics@8"

to               

setup_graphics%(wwidth,height):"setup_graphics@8"
I will bite you - http://s5.bitefight.se/c.php?uid=31059
Challenge Trophies Won:

Stonemonkey

yep, and the tri functions take single floats for the screen coords so i have something like:


.lib "sm_dll.dll"

create_buffer%( wwidth%,height% ):"create_buffer@8"
setup_graphics%( wwidth%,height% ):"setup_graphics@8"
close_graphics( bufferi% ):"close_graphics@4"
flip_buffer( bufferi% ):"flip_buffer@4"
clear_buffer( bufferi% ):"clear_buffer@8"

set_pixel( bufferi%,x%,y%,argb% ):"set_pixel@16"
get_pixel%( bufferi%,x%,y% ):"get_pixel@12"
set_pixel_fast( bufferi%,x%,y%,argb% ):"set_pixel_fast@16"
get_pixel_fast%( bufferi%,x%,y% ):"get_pixel_fast@12"

fill_rect( bufferi%,x0%,y0%,x1%,y1%,argb% ):"fill_rect@24"
fill_triangle( bufferi%,x0#,y0#,x1#,y1#,x2#,y2#,argb% ):"fill_triangle@32"
fill_gtriangle( bufferi%,x0#,y0#,argb0%,x1#,y1#,argb1%,x2#,y2#,argb2% ):"fill_gtriangle@40"


also since i'm not able to read from the keyboard i was exiting with X on the window but the program was still running and i had to close it 'blitzcc.exe' from the task manager.

Paul

#16
To read from the keyboard I would use the winapi, api_GetKeyState(), Note that the keys have different values.
And


api_GetCursorPos%(lpPoint)

together with


api_ScreenToClient(hWnd,lpPoint)

But then you would need to know the window handle to the sm_lib window

Edit:
Here bouth the keyboard and the mouse work :D
you probably will ned to add this to your user32.decls

FindWindow%( class%,Text$ ):"FindWindowA"

notice the class% instead of Class$


buff=setup_graphics(400,300)
flip_buffer(buff)


lpPoint = CreateBank(8)

Window=FindWindow(0,"SM_graphics");Find the WIndow

While Not quit
If api_GetKeyState(27)>2 Then quit=1;escape
api_GetCursorPos%(lpPoint)
api_ScreenToClient(Window,lpPoint)
mx = PeekInt(lpPoint,0)
my = PeekInt(lpPoint,4)
If mx=>0 And my=>0 And mx<400 And my<300
set_pixel_fast(buff,mx,my,255)
EndIf

flip_buffer(buff)

Wend
api_PostMessage(Window, $10, 0, 0)
End
I will bite you - http://s5.bitefight.se/c.php?uid=31059
Challenge Trophies Won:

Paul

#17
Just hit the key(mouse) you want to find out the code for


Dim k(256)
For i=0 To 256
k(i)=api_GetKeyState(i)
Next
While Not KeyHit(1)
For i=0 To 256
If api_GetKeyState(i)<>k(i)
k(i)=api_GetKeyState(i)
Print i
EndIf
Next
Wend
I will bite you - http://s5.bitefight.se/c.php?uid=31059
Challenge Trophies Won:

Stonemonkey

Tiny_ptc isn't the best thing to be using here but I was curious as to what I could do anyway, if i come up with anything else I'll let you know. Probably better to have something written in c++ for something like this anyway.

Paul

I think so too and if i knew how to do c++ I would try, but i don,t :(
It feels so different to blitz with all the include files and i cant get my head arround it
I will bite you - http://s5.bitefight.se/c.php?uid=31059
Challenge Trophies Won: