Author Topic: My Windows Graphics Tutorial  (Read 32839 times)

caballero

  • Member
  • *****
  • Posts: 2160
  • Matrix - Noah
    • abre ojos ensamblador
My Windows Graphics Tutorial
« on: April 28, 2013, 09:31:50 PM »
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
« Last Edit: August 19, 2013, 07:55:46 PM by avcaballero »
The logic of the error is hidden among the most unexpected lines of the program

Gunther

  • Member
  • *****
  • Posts: 4198
  • Forgive your enemies, but never forget their names
Re: My Windos Graphics Tutorial
« Reply #1 on: April 28, 2013, 09:40:37 PM »
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

  • Member
  • *****
  • Posts: 8828
  • Still using Abacus 2.0
    • DednDave
Re: My Windos Graphics Tutorial
« Reply #2 on: April 28, 2013, 10:32:13 PM »
great, Alfonso - i'll have a look   :t

Vortex

  • Member
  • *****
  • Posts: 2794
Re: My Windos Graphics Tutorial
« Reply #3 on: April 29, 2013, 04:48:13 AM »
Hi Alfonso,

Thanks for your contribution.

Siekmanski

  • Member
  • *****
  • Posts: 2725
Re: My Windos Graphics Tutorial
« Reply #4 on: April 29, 2013, 04:26:05 PM »
Hi Alfonso,

COOL  8)
Creative coders use backward thinking techniques as a strategy.

caballero

  • Member
  • *****
  • Posts: 2160
  • Matrix - Noah
    • abre ojos ensamblador
Re: My Windos Graphics Tutorial
« Reply #5 on: July 02, 2013, 04:34:39 PM »
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
The logic of the error is hidden among the most unexpected lines of the program

Gunther

  • Member
  • *****
  • Posts: 4198
  • Forgive your enemies, but never forget their names
Re: My Windos Graphics Tutorial
« Reply #6 on: July 02, 2013, 09:53:26 PM »
Thank you Alfonso. Great work.  :t

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

caballero

  • Member
  • *****
  • Posts: 2160
  • Matrix - Noah
    • abre ojos ensamblador
Re: My Windos Graphics Tutorial
« Reply #7 on: August 19, 2013, 04:38:40 AM »
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
The logic of the error is hidden among the most unexpected lines of the program

caballero

  • Member
  • *****
  • Posts: 2160
  • Matrix - Noah
    • abre ojos ensamblador
Re: My Windows Graphics Tutorial
« Reply #8 on: September 05, 2013, 09:45:43 PM »
Updated with a new chapter about optimizations. Only in TinyC and no exe, just c files uploaded. Any suggestion?

Regards
The logic of the error is hidden among the most unexpected lines of the program

dedndave

  • Member
  • *****
  • Posts: 8828
  • Still using Abacus 2.0
    • DednDave
Re: My Windows Graphics Tutorial
« Reply #9 on: September 05, 2013, 10:07:30 PM »
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

caballero

  • Member
  • *****
  • Posts: 2160
  • Matrix - Noah
    • abre ojos ensamblador
Re: My Windows Graphics Tutorial
« Reply #10 on: September 05, 2013, 10:25:10 PM »
Thank you Dave, I'll have a look :t
The logic of the error is hidden among the most unexpected lines of the program

caballero

  • Member
  • *****
  • Posts: 2160
  • Matrix - Noah
    • abre ojos ensamblador
Re: My Windows Graphics Tutorial
« Reply #11 on: September 09, 2013, 05:39:59 PM »
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.
« Last Edit: September 09, 2013, 07:54:56 PM by avcaballero »
The logic of the error is hidden among the most unexpected lines of the program

dedndave

  • Member
  • *****
  • Posts: 8828
  • Still using Abacus 2.0
    • DednDave
Re: My Windows Graphics Tutorial
« Reply #12 on: September 09, 2013, 10:31:22 PM »
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

Code: [Select]
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

  • Member
  • *****
  • Posts: 13957
  • Assembly is fun ;-)
    • MasmBasic
CreateDIBSection
« Reply #13 on: November 24, 2013, 10:32:45 AM »
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:
Quote
Return 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

  • Member
  • *****
  • Posts: 1475
  • The base type of a type is the type itself
    • SmplMath macros
Re: CreateDIBSection
« Reply #14 on: November 24, 2013, 11:24:29 AM »
bmi   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!