flat assembler
Message board for the users of flat assembler.
 Home   FAQ   Search   Register 
 Profile   Log in to check your private messages   Log in 
flat assembler > Examples and Tutorials > Simplest way for graphics prototyping with FreshLib

Author
Thread Post new topic Reply to topic
JohnFound



Joined: 16 Jun 2003
Posts: 3439
Location: Bulgaria
Simplest way for graphics prototyping with FreshLib
It was easy in the DOS days. The video memory was accessible from the user programs. Graphics programming in assembly was easy and fun.

That is why even now, the most examples for the beginners are written for DOS.

The modern OSes provide too complex API for graphics that is pretty hard for the beginners to learn.

FreshLib provides very simple way to make graphics, very close to the old DOS approach. One big array of pixels and your assembly program that to fill them up.

Here is a very simple example that illustrates how simple is to make graphics routines in FreshLib. The same code compiles for Linux and Windows:


Code:
include "%lib%/freshlib.inc"

@BinaryType GUIcompact

include "%lib%/freshlib.asm"


frmMainForm:
        ObjTemplate  tfEndTFormfrmMain, \
                     x = 100,        \
                     y = 50,         \
                     width = 320,    \
                     height = 240,   \
                     Visible = TRUE, \
                     OnPaint = OnFormPaint,     \
                     Caption = 'Easy drawing with FreshLib'


start:
        InitializeAll

        create  [pApplication], TApplication
        stdcall GUI.Init
        stdcall CreateFromTemplatefrmMainForm0
        set     [pApplication], TApplication:MainWindowfrmMain

        stdcall Run

        FinalizeAll
        stdcall TerminateAll0



Colors dd $ff584435$ffBD9D86

proc OnFormPaint.self.canvas
begin

        mov     esi, [.canvas]
        mov     edi, [esi+TImage.pPixels]

        xor     edxedx  ; Y coordinate

.loop_y:

        xor     ecxecx  ; X coordinate

.loop_x:

        mov     eaxecx
        xor     eaxedx
        shr     eax5    ; 2^5 = 32px one field size.
        and     eax1    ; dark or light?

        mov     eax, [Colors+4*eax]

        stosd

        inc     ecx
        cmp     ecx, [esi+TImage.width]
        jl      .loop_x

        inc     edx
        cmp     edx, [esi+TImage.height]
        jl      .loop_y

        return
endp



In the attachment is the full project. It contains the precompiled binaries for Linux and Windows as well.
Open and compile it with Fresh IDE.

[EDIT]Oh, I forgot about the attachment! Here it is.[/EDIT]


Description: Simple graphics with FreshLib example project.
Download
Filename: SimpleGraphics.zip
Filesize: 17.53 KB
Downloaded: 68 Time(s)


_________________
Tox ID: 48C0321ADDB2FE5F644BB5E3D58B0D58C35E5BCBC81D7CD333633FEDF1047914A534256478D9


Last edited by JohnFound on 09 Dec 2016, 12:18; edited 1 time in total
Post 09 Dec 2016, 10:44
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
avcaballero



Joined: 02 Feb 2004
Posts: 146
Location: Madrid - Spain
Interesting. What is .canvas and TImage? I guess that you paint on the HDC of the client area.
Post 09 Dec 2016, 11:09
View user's profile Send private message Visit poster's website Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3439
Location: Bulgaria
.canvas is an argument of the OnPaint event handler, that contains pointer to the canvas TImage of the window that have to be drawn.

TImage is in memory bitmap, defined following way:

Code:
struct TImage
  .width   dd ?  ; width in pixels.
  .height  dd ?  ; height in pixels.
  .pPixels dd ?  ; pointer to the pixel memory.

; follows os dependent data
ends



For the user only the first 3 fields are useful, because the following are OS dependent fields. For example for Linux TImage is defined this way: Source code

The .pPixels member of TImage contains pointer to the pixels array. Every pixel is always 32bit ARBG value, using premultiplied alpha.
Post 09 Dec 2016, 11:33
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3439
Location: Bulgaria
I have added the missed attachment from the first post.
Post 09 Dec 2016, 12:18
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3439
Location: Bulgaria
This example, with some additional comments has been added to the Fresh IDE examples/ directory in v2.5.1
Post 20 Dec 2016, 07:54
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >

Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2005 phpBB Group.

Main index   Download   Documentation   Examples   Message board
Copyright © 2004-2016, Tomasz Grysztar.