Simplify drawing to screen example
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -5,6 +5,7 @@
|
|||||||
*.4c
|
*.4c
|
||||||
*.bin
|
*.bin
|
||||||
*.rdbg
|
*.rdbg
|
||||||
|
start.bat
|
||||||
|
|
||||||
*.c
|
*.c
|
||||||
backup*
|
backup*
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ In the future
|
|||||||
|
|
||||||
- [ ] Cleanup
|
- [ ] Cleanup
|
||||||
- [ ] Remove tuple stuff or cleanup, in the future might replace it with a better implementation
|
- [ ] Remove tuple stuff or cleanup, in the future might replace it with a better implementation
|
||||||
|
- [ ] Add ability to do i: int = 0 inside for loops
|
||||||
|
|
||||||
- [ ] Conditional compilation
|
- [ ] Conditional compilation
|
||||||
- [ ] Expand macros
|
- [ ] Expand macros
|
||||||
|
|||||||
@@ -1,36 +1,41 @@
|
|||||||
#import "Base.core"
|
#import "Base.core"
|
||||||
#import "Arena.core"
|
#import "Arena.core"
|
||||||
#import "Windows.core"
|
|
||||||
#import "KERNEL32.core"
|
#import "KERNEL32.core"
|
||||||
#import "GDI32.core"
|
#import "GDI32.core"
|
||||||
#import "USER32.core"
|
#import "USER32.core"
|
||||||
#import "WINMM.core"
|
|
||||||
|
|
||||||
Vec2I :: struct;; x: S64; y: S64
|
WinMain :: (hInstance: HINSTANCE, hPrevInstance: HINSTANCE, lpCmdLine: LPSTR, nShowCmd: int): int
|
||||||
|
screen_size_x: int = 1280
|
||||||
|
screen_size_y: int = 720
|
||||||
|
|
||||||
AppIsRunning := true
|
arena: Arena
|
||||||
Windows_Bitmap :: struct
|
window_name := StringToString16(&arena, "Have a wonderful day!")
|
||||||
size: Vec2I
|
w := WNDCLASSW{
|
||||||
data: *U32
|
lpfnWndProc = WindowProc,
|
||||||
hdc: HDC
|
hInstance = hInstance,
|
||||||
dib: HBITMAP
|
lpszClassName = window_name.str,
|
||||||
|
}
|
||||||
|
Assert(RegisterClassW(&w) != 0)
|
||||||
|
|
||||||
Bitmap :: struct
|
window := CreateWindowExW(
|
||||||
size: Vec2I
|
dwExStyle = 0, hWndParent = 0, hMenu = 0, lpParam = 0,
|
||||||
data: *U32
|
X = CW_USEDEFAULT, Y = CW_USEDEFAULT, nWidth = screen_size_x, nHeight = screen_size_y,
|
||||||
|
lpClassName = window_name.str,
|
||||||
CreateBitmap :: (size: Vec2I, bottom_up: Bool = true): Windows_Bitmap
|
lpWindowName = window_name.str,
|
||||||
result: Windows_Bitmap = {size = size}
|
dwStyle = WS_OVERLAPPEDWINDOW,
|
||||||
if bottom_up == false
|
hInstance = hInstance
|
||||||
result.size.y = -result.size.y
|
)
|
||||||
|
Assert(window != 0)
|
||||||
|
ShowWindow(window, nShowCmd)
|
||||||
|
window_dc := GetDC(window)
|
||||||
|
|
||||||
header_size: U32 = SizeOf(BITMAPINFOHEADER)
|
header_size: U32 = SizeOf(BITMAPINFOHEADER)
|
||||||
Assert(header_size == 40)
|
Assert(header_size == 40)
|
||||||
bminfo := BITMAPINFO{
|
bminfo := BITMAPINFO{
|
||||||
BITMAPINFOHEADER{
|
BITMAPINFOHEADER{
|
||||||
biSize = header_size,
|
biSize = header_size,
|
||||||
biWidth = size.x->LONG,
|
biWidth = screen_size_x->LONG,
|
||||||
biHeight = size.y->LONG,
|
biHeight = screen_size_y->LONG,
|
||||||
biPlanes = 1,
|
biPlanes = 1,
|
||||||
biBitCount = 32,
|
biBitCount = 32,
|
||||||
biCompression = BI_RGB,
|
biCompression = BI_RGB,
|
||||||
@@ -39,46 +44,9 @@ CreateBitmap :: (size: Vec2I, bottom_up: Bool = true): Windows_Bitmap
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
hdc := GetDC(0)
|
pixels: *U32
|
||||||
result.dib = CreateDIBSection(hdc, &bminfo, DIB_RGB_COLORS, (&result.data)->**void, 0, 0)
|
bitmap_dib := CreateDIBSection(window_dc, &bminfo, DIB_RGB_COLORS, (&pixels)->**void, 0, 0)
|
||||||
result.hdc = CreateCompatibleDC(hdc)
|
bitmap_hdc := CreateCompatibleDC(window_dc)
|
||||||
return result
|
|
||||||
|
|
||||||
WindowProc :: (hwnd: HWND, msg: UINT, wparam: WPARAM, lparam: LPARAM): LRESULT
|
|
||||||
if msg == WM_DESTROY
|
|
||||||
PostQuitMessage(0)
|
|
||||||
AppIsRunning = false
|
|
||||||
return 0
|
|
||||||
else;; return DefWindowProcW(hwnd, msg, wparam, lparam)
|
|
||||||
|
|
||||||
WinMain :: (hInstance: HINSTANCE, hPrevInstance: HINSTANCE, lpCmdLine: LPSTR, nShowCmd: int): int
|
|
||||||
if good_scheduling := false, timeBeginPeriod(1) == TIMERR_NOERROR
|
|
||||||
good_scheduling = true
|
|
||||||
|
|
||||||
arena: Arena
|
|
||||||
|
|
||||||
window_name := StringToString16(&arena, "Have a wonderful day! 你好世界 ")
|
|
||||||
w := WNDCLASSW{
|
|
||||||
lpfnWndProc = WindowProc,
|
|
||||||
hInstance = hInstance,
|
|
||||||
lpszClassName = window_name.str,
|
|
||||||
}
|
|
||||||
Assert(RegisterClassW(&w) != 0)
|
|
||||||
|
|
||||||
screen_size: Vec2I = {1280, 720}
|
|
||||||
window := CreateWindowExW(
|
|
||||||
dwExStyle = 0, hWndParent = 0, hMenu = 0, lpParam = 0,
|
|
||||||
X = CW_USEDEFAULT, Y = CW_USEDEFAULT, nWidth = screen_size.x->int, nHeight = screen_size.y->int,
|
|
||||||
lpClassName = window_name.str,
|
|
||||||
lpWindowName = window_name.str,
|
|
||||||
dwStyle = WS_OVERLAPPEDWINDOW,
|
|
||||||
hInstance = hInstance
|
|
||||||
)
|
|
||||||
Assert(window != 0)
|
|
||||||
ShowWindow(window, nShowCmd)
|
|
||||||
|
|
||||||
window_dc := GetDC(window)
|
|
||||||
bitmap := CreateBitmap(screen_size)
|
|
||||||
|
|
||||||
for AppIsRunning
|
for AppIsRunning
|
||||||
msg: MSG
|
msg: MSG
|
||||||
@@ -86,14 +54,23 @@ WinMain :: (hInstance: HINSTANCE, hPrevInstance: HINSTANCE, lpCmdLine: LPSTR, nS
|
|||||||
TranslateMessage(&msg)
|
TranslateMessage(&msg)
|
||||||
DispatchMessageW(&msg)
|
DispatchMessageW(&msg)
|
||||||
|
|
||||||
for y := 0, y < bitmap.size.y, y+=1
|
for y := 0->int, y < screen_size_y, y+=1
|
||||||
for x := 0, x < bitmap.size.x, x+=1
|
for x := 0->int, x < screen_size_x, x+=1
|
||||||
bitmap.data[x + y*bitmap.size.x] = 0xFFFF0000
|
pixels[x + y*screen_size_x] = 0xFFFF0000
|
||||||
|
|
||||||
SelectObject(bitmap.hdc, bitmap.dib)
|
SelectObject(bitmap_hdc, bitmap_dib)
|
||||||
BitBlt(window_dc, 0, 0, (bitmap.size.x)->int, (bitmap.size.y)->int, bitmap.hdc, 0, 0, SRCCOPY)
|
BitBlt(window_dc, 0, 0, screen_size_x, screen_size_y, bitmap_hdc, 0, 0, SRCCOPY)
|
||||||
Sleep(100)
|
Sleep(100)
|
||||||
|
|
||||||
if CStringCompare(lpCmdLine, "testing")
|
if CStringCompare(lpCmdLine, "testing")
|
||||||
return 0
|
return 0
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
AppIsRunning := true
|
||||||
|
WindowProc :: (hwnd: HWND, msg: UINT, wparam: WPARAM, lparam: LPARAM): LRESULT
|
||||||
|
if msg == WM_DESTROY
|
||||||
|
PostQuitMessage(0)
|
||||||
|
AppIsRunning = false
|
||||||
|
return 0
|
||||||
|
else;; return DefWindowProcW(hwnd, msg, wparam, lparam)
|
||||||
@@ -18,6 +18,11 @@ AlignUp :: (size: SizeU, align: SizeU): SizeU
|
|||||||
result := size + GetAlignOffset(size, align)
|
result := size + GetAlignOffset(size, align)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
ZeroMemory :: (p: *void, size: SizeU)
|
||||||
|
pcast := p->*U8
|
||||||
|
for i := 0->SizeU, i < size, i++
|
||||||
|
pcast[i] = 0
|
||||||
|
|
||||||
//
|
//
|
||||||
// Unicode
|
// Unicode
|
||||||
//
|
//
|
||||||
|
|||||||
@@ -37,3 +37,5 @@ CreateDIBSection :: #foreign (hdc: HDC, pbmi: *BITMAPINFO, usage: UINT, ppvBit
|
|||||||
CreateCompatibleDC :: #foreign (hdc: HDC): HDC
|
CreateCompatibleDC :: #foreign (hdc: HDC): HDC
|
||||||
SelectObject :: #foreign (hdc: HDC, h: HGDIOBJ): HGDIOBJ
|
SelectObject :: #foreign (hdc: HDC, h: HGDIOBJ): HGDIOBJ
|
||||||
BitBlt :: #foreign (hdc: HDC, x: int, y: int, cx: int, cy: int, hdcSrc: HDC, x1: int, y1: int, ro: DWORD): BOOL
|
BitBlt :: #foreign (hdc: HDC, x: int, y: int, cx: int, cy: int, hdcSrc: HDC, x1: int, y1: int, ro: DWORD): BOOL
|
||||||
|
DeleteDC :: #foreign (hdc: HDC): BOOL
|
||||||
|
DeleteObject :: #foreign (ho : HGDIOBJ): BOOL
|
||||||
Reference in New Issue
Block a user