C language > Graphics programming
Squeezing some cool from Windows GDI
Vortex:
Hi MrBcx,
Many thanks, your parameters worked fine :
--- Code: ---cl.exe /std:c++20 /permissive /c /O2 /Gd /W2 /MT -D NTDDI_VERSION=0x0A000000 -D_WIN32_WINNT=0x0A000000 /EHsc /Tp %1.c
--- End code ---
This is why I like the assemlers, no need to struggle with those constantly changing standards and complicated commandline options. Everything in the life is coming with a price. :)
Edit : MS Link works as expected but Polink complains a lot but it manages to create the executable :
--- Code: ---E:\pellesc\bin\polink /SUBSYSTEM:WINDOWS main.obj
POLINK: warning: Unrecognized option '/FAILIFMISMATCH:_CRT_STDIO_ISO_WIDE_SPECIFIERS=0'; ignored.
POLINK: warning: Realigned section '.idata$2' in object 'kernel32.Lib(KERNEL32.dll)' (from 4 to 1 byte(s)).
POLINK: warning: Realigned section '.idata$3' in object 'kernel32.Lib(KERNEL32.dll)' (from 4 to 1 byte(s)).
POLINK: warning: Realigned section '.idata$2' in object 'User32.Lib(USER32.dll)' (from 4 to 1 byte(s)).
POLINK: warning: Realigned section '.idata$2' in object 'Gdi32.Lib(GDI32.dll)' (from 4 to 1 byte(s)).
POLINK: warning: Realigned section '.idata$2' in object 'ComCtl32.Lib(COMCTL32.dll)' (from 4 to 1 byte(s)).
POLINK: warning: Realigned section '.idata$2' in object 'Ole32.Lib(ole32.dll)' (from 4 to 1 byte(s)).
POLINK: warning: Section '.gfids$y' is not supported; ignored.
POLINK: warning: Unrecognized option '/disallowlib:msvcrt.lib'; ignored.
POLINK: warning: Unrecognized option '/disallowlib:msvcrtd.lib'; ignored.
POLINK: warning: Unrecognized option '/disallowlib:libcmtd.lib'; ignored.
POLINK: warning: Unrecognized option '/disallowlib:vcruntime.lib'; ignored.
POLINK: warning: Unrecognized option '/disallowlib:vcruntimed.lib'; ignored.
POLINK: warning: Unrecognized option '/disallowlib:libvcruntimed.lib'; ignored.
POLINK: warning: Unrecognized option '/disallowlib:ucrtd.lib'; ignored.
POLINK: warning: Unrecognized option '/disallowlib:libucrtd.lib'; ignored.
POLINK: warning: Unrecognized option '/GUARDSYM:__C_specific_handler,S'; ignored.
POLINK: warning: Unrecognized option '/GUARDSYM:__CxxFrameHandler3,S'; ignored.
POLINK: warning: Unrecognized option '/GUARDSYM:__CxxFrameHandler4,S'; ignored.
POLINK: warning: Unrecognized option '/GUARDSYM:__CxxFrameHandler2,S'; ignored.
POLINK: warning: Unrecognized option '/GUARDSYM:__CxxFrameHandler,S'; ignored.
POLINK: warning: COMDAT symbol '??$__crt_interlocked_read_pointer@UHINSTANCE__@@@@YAPEAUHINSTANCE__@@PEDSEAU0@@Z' is multiply defined: 'libvcruntime.lib(winapi_downlevel.obj)' and 'libucrt.lib(winapi_thunks.obj)'.
POLINK: warning: COMDAT symbol '??$__crt_interlocked_read_pointer@X@@YAPEAXPEDSEAX@Z' is multiply defined: 'libvcruntime.lib(winapi_downlevel.obj)' and 'libucrt.lib(winapi_thunks.obj)'.
POLINK: warning: COMDAT symbol '?__crt_interlocked_read_64@@YA_JPED_J@Z' is multiply defined: 'libvcruntime.lib(std_type_info.obj)' and 'libucrt.lib(winapi_thunks.obj)'.
--- End code ---
MrBcx:
These are what I routinely use to compile 64-bit GUI apps using Pelles:
SET PoccOPTS= /Go /Gn /W1 /Gd /Ze /Zx /Tx64-coff /D NTDDI_VERSION=0x0A000007 /std:c17 /fp:precise
SET PolinkOPTS= -release -machine:x64 /subsystem:windows,5.02 /STACK:10485760
and below for 32-bit:
SET PoccOPTS=/Go /Gn /W1 /Gd /Ze /Zx /Tx86-coff /D NTDDI_VERSION=0x0A000007 /std:c17 /fp:precise
SET PolinkOPTS= -release -machine:x86 /subsystem:windows,5.01 /STACK:10485760
John Z:
MrBCX - nice mesmerizing display. Good demo for BCX too, amazed at the code it generated...
John Z
MrBcx:
--- Quote ---MrBCX - nice mesmerizing display. Good demo for BCX too, amazed at the code it generated...
John Z
--- End quote ---
Thanks John !
Below is the BCX BASIC code ( before it is translated to C)
Approx 100 lines of BCX BASIC produced approx 900 lines of C.
Even if folks prefer C\C++ over BASIC, BCX will save us a lot of time
when beginning a project. It's useful for prototyping ideas and for learning
about Windows API programming.
Coincidentally, I actually have another BCX graphics demo named
"Mesmerize" here: https://bcxbasiccoders.com/smf/index.php?topic=889.0
--- Code: ---GUI "Cardioid and Beyond", PIXELS
CONST xmax = 700
CONST ymax = 700
CONST npoints = 200
GLOBAL Form1 AS HWND
GLOBAL BufferDC AS HDC
SUB FORMLOAD
Form1 = BCX_FORM ("Cardiod", 0, 0, xmax + 10, ymax + 30)
MODSTYLE(Form1, 0, WS_MAXIMIZEBOX | WS_MINIMIZEBOX, FALSE)
BCX_SET_FORM_COLOR (Form1, RGB(0, 0, 0))
CENTER Form1
SHOW Form1
'==============================
' Create the off-screen buffer
'==============================
DIM hDC AS HDC
hDC = GetDC(Form1)
BufferDC = CreateCompatibleDC(hDC)
ReleaseDC(Form1, hDC)
'==============================
CALL Drawit
END SUB
BEGIN EVENTS
SELECT CASE CBMSG
CASE WM_QUIT, WM_CLOSE, WM_DESTROY
END
END SELECT
END EVENTS
SUB Drawit
DIM AS DOUBLE Mult, DA, R
DIM AS LONG xx1, xx2, yy1, yy2, cx, cy
cx = xmax/2
cy = ymax/2
DA = 0.0314159
R = cx - 10
FOR Mult = 0 TO 100 STEP 0.01
DOEVENTS
SLEEP(1)
'=========================================
' Create our off-screen bitmap for drawing
'=========================================
DIM AS HBITMAP hOldBitmap
DIM AS INTEGER bmWidth, bmHeight
DIM RAW bm AS BITMAPINFO
bmWidth = xmax
bmHeight = ymax
bm.bmiHeader.biSize = SIZEOF(BITMAPINFOHEADER)
bm.bmiHeader.biWidth = bmWidth
bm.bmiHeader.biHeight = -bmHeight
bm.bmiHeader.biPlanes = 1
bm.bmiHeader.biBitCount = 32
bm.bmiHeader.biCompression = BI_RGB
hOldBitmap = (HBITMAP)SelectObject(BufferDC, CreateDIBSection(0, &bm, DIB_RGB_COLORS, 0, 0, 0))
'==========================================
BCX_PRINTEX (0, 10, 10, "Multiple: " + USING$("###.##", Mult), RGB(128, 162, 225), RGB(0, 0, 0), "Verdana", 26, BufferDC)
IF Mult = INT(Mult) THEN CALL ResetPlasma
BCX_CIRCLE(0, cx, cy, R, Kolor, 0, BufferDC)
FOR INT i = 1 TO npoints
DOEVENTS
xx1 = cx + R * COS(i * DA)
yy1 = cy + R * SIN(i * DA)
xx2 = cx + R * COS(Mult * i * DA)
yy2 = cy + R * SIN(Mult * i * DA)
CALL ChangePlasma
BCX_LINE(0, xx1, yy1, xx2, yy2, Kolor, BufferDC )
NEXT
'==================================================
' Copy the off-screen buffer to the visible window
'==================================================
DIM RAW hDC AS HDC
hDC = GetDC(Form1)
BitBlt(hDC, 0, 0, bmWidth, bmHeight, BufferDC, 0, 0, SRCCOPY)
ReleaseDC(Form1, hDC)
DeleteObject(SelectObject(BufferDC, hOldBitmap)) ' Clean up
NEXT
MSGBOX "Press Okay to close the window", "Completed!"
END
END SUB
SUB ChangePlasma
GLOBAL AS ULONG Kolor
GLOBAL AS ULONG cN
GLOBAL AS DOUBLE pR, pG, pB
cN = cN + 1
Kolor = RGB(127 + 127 * SIN(pR * cN), 127 + 127 * SIN(pG * cN), 127 + 127 * SIN(pB * cN))
END SUB
SUB ResetPlasma
pR = RND ^ 2
pG = RND ^ 2
pB = RND ^ 2
END SUB
--- End code ---
Vortex:
Hi MrBcx,
Compiling your code with Msys2, the equivalent of the MS VC option /Tp ( compile as c++ ) is -x c++ :
--- Quote --- -x <language> Specify the language of the following input files.
Permissible languages include: c c++ assembler none
'none' means revert to the default behavior of
guessing the language based on the file's extension.
--- End quote ---
--- Code: ---# gcc --version
gcc.exe (Rev2, Built by MSYS2 project) 13.2.0
Copyright (C) 2023 Free Software Foundation, Inc.
--- End code ---
--- Code: ---gcc -x c++ main.c -o main.exe -luser32 -lgdi32 -lole32 -loleaut32 -lcomctl32 -mwindows
--- End code ---
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version