News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

My Windows Graphics Tutorial

Started by avcaballero, April 28, 2013, 09:31:50 PM

Previous topic - Next topic

avcaballero

Well Gunther, what stress, guy ;). I've finally released my tutorial on Windows graphics. It
is not finished at all, but... well, here it is... I hope you all like it. I keep on working on it... I did it in a hurry so, maybe it may has anything wrong (broken links, etc) ... Only in Spanish for now, sorry, only a bit translated to English...

Regards

Gunther

Hi Alfonso,

looks nice and interesting. Thank you.  :t We need to torment the translation program. But never mind.

Gunther
You have to know the facts before you can distort them.

dedndave

great, Alfonso - i'll have a look   :t

Vortex

Hi Alfonso,

Thanks for your contribution.

Siekmanski

Creative coders use backward thinking techniques as a strategy.

avcaballero

Hello, I have updated my graphics tuto with the latest demos. Of course, not finished, many things to do yet. Only in Spanish, English version is for the previous one, so deprecated for the moment, till I have time to translate it.

Regards

Gunther

Thank you Alfonso. Great work.  :t

Gunther
You have to know the facts before you can distort them.

avcaballero

Hello there, if anyone interested I've just uploaded my updated tuto on GDI Win graphics.

There are here many new stuff from the last one though many to do yet, including translating

it to English, but I'm getting more lazy to work on it, though surely I will keep on making

things for it. In the other hand, there're many things that I've removed from the downloable

version, that may be not in the interest of anybody.

Now you can download the entire tuto from here.

Also you can download the libs from here, but you need login first in my forum. The

registering is 100% free, but you have to provide a valid email to complete it. I did it

just for have an idea of how many times it was downloaded (at least one time for my checking

;) ) and by who... I know, I know, you are rather shy and can't do it. Never mind, many

codes really don't need libs...

Besides, there're many new things from last one.

Oops, I must say that the libs have failed while downloading, I will check it as soon as I

can :)

In the end... Good fun

avcaballero

Updated with a new chapter about optimizations. Only in TinyC and no exe, just c files uploaded. Any suggestion?

Regards

dedndave

one of the things that i found was to do your drawing on a DIB section with a controlled bit-depth
some programmers like to use a 32-bit DIB section to draw on - because addressing is simple
if you use CreateCompatibleBitmap, the bitmap bit-depth is dependant on the user display settings
on my machine, i have my display setttings set to 32-bit, so it creates a 32-bit bitmap
while addressing pixels might be simpler in a 32-bit bitmap, it can be slow as hell - lol

in this particular app, i am using FloodFillEx for part of the image
and, 256 colors is plenty
when i changed from CreateCompatibleBitmap to CreateDIBSection, using a 24-bit DIB,
the flood fill was 6 times faster
and, faster still using a 256-color DIB

i am talking about the back-buffer/memory DC that you draw on before you blit to the display DC

of course, you have probably covered this in another section.....
but, i want to mention returning the DC to original state before deleting it

some functions return the original value/state when called
functions like SetBkMode, etc
but, the documentation does not say it should be restored
i think it is a good idea to do so, however

one way to restore a DC is to use SaveDC/RestoreDC
these functions will save DC states in a stack-like manner (LIFO)
simpler and probably a little faster than calling several SelectObject's   :P

avcaballero

Thank you Dave, I'll have a look :t

avcaballero

#11
Hello, Dave. Thanks a lot. When I started this project I tried to do the same, dumping the DIB buffer directly to the main window device context, but after several tries I decided that I did not able to do it, thus from there it is that I first dump dib to bmp and then bmp to hdc |o| and go on to work... Good, now it works, just one step for dumping dib to hdc !!  What the hell did I before for it didn't work...? Hmmm, never mind, it works... lightning fast ;)

I owe you a beer!  :biggrin:  :t


By the way, does any one know if these examples works in Win mobiles phones? or tablets, etc... Mine is Android... Thank you.

dedndave

you probably got better at writing GDI code while writing the tutorial   :t

i have had similar experiences...
like, if you try to create the back-buffer DC as compatible to something other than the device DC   :P

INVOKE  BeginPaint,hWnd,addr ps
INVOKE  CreateCompatibleDC,eax
mov     hdcMem,eax
INVOKE  CreateDIBSection,ps.hdc,....
INVOKE  SelectObject,hdcMem,eax

seems to work nicely
although, i like to store hdcMem in ESI or EDI if i am going to do a lot of different things with it

many GDI functions, like SetPixel, LineTo, PolyLine, PolyBezier, etc, create a DIB section to do the work
if it's already a DIB section, it seems to save a step

jj2007

I have a weird problem with CreateDIBSection:

.data
bmih   BITMAPINFOHEADER <BITMAPINFOHEADER, 400, 300, 1, 32, BI_RGB, 0, 0, 0, 0, 0>
bmiColors   RGBQUAD <0, 0, 0, 0>
bmi   BITMAPINFO <<bmih>, bmiColors>   ; OK for ML 6.15 but not for JWasm
...
.code
...
case WM_CREATE:
   invoke SetLastError, 0
   mov hDC, rv(GetDC, hWnd)      ; use handle to main window
   mov hDib, rv(CreateDIBSection, eax, addr bmi, DIB_RGB_COLORS, addr ppvBits, 0, 0)
   deb 4, "CDS", hDib, ppvBits, hDC, hWnd, $Err$()


hDC is a valid handle, but CreateDIBSection returns zero, with hDib=0, ppvBits=0, GetLastError = zero... ::)
MDSN:
QuoteReturn Value

A handle to the newly created device-independent bitmap indicates success, and *ppvBits points to the bitmap's bit values.

NULL indicates failure, and *ppvBits is NULL.

To get extended error information, call GetLastError.

Which logically excludes the case that both CreateDIBSection and GetLastError return zero :eusa_boohoo:

In addition, ML and JWasm behave contradictory:

bmih   BITMAPINFOHEADER <BITMAPINFOHEADER, 400, 300, 1, 32, BI_RGB, 0, 0, 0, 0, 0>
bmiColors   RGBQUAD <0, 0, 0, 0>      ; OK for ML and JWasm

; OK for ML 6.15 but JWasm says Structure improperly initialized: RGBQUAD
bmi   BITMAPINFO <<bmih>, bmiColors>

; OK for JWasm but ML says invalid data initializer
bmi   BITMAPINFO <<bmih>, <0, 0, 0, 0>>


Any ideas? Anybody use CreateDIBSection successfully?

qWord

Quote from: jj2007 on November 24, 2013, 10:32:45 AMbmi   BITMAPINFO <<bmih>, bmiColors>   ; OK for ML 6.15 but not for JWasm
I've doubts that you get what you did expect.
MREAL macros - when you need floating point arithmetic while assembling!