From 18270a2ae92d52b2ef6379f21aae4d0e75b47824 Mon Sep 17 00:00:00 2001 From: Zack Buhman Date: Sat, 20 Dec 2025 16:01:28 -0600 Subject: [PATCH] initial --- .gitignore | 8 ++++ Makefile | 47 ++++++++++++++++++++++ main.cpp | 114 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 169 insertions(+) create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 main.cpp diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fd55e31 --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +*~ +.#* +*.o +*.d +*.s +*.blend1 +*.zip +*.exe diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..3ff096d --- /dev/null +++ b/Makefile @@ -0,0 +1,47 @@ +.SUFFIXES: +.INTERMEDIATE: +.SECONDARY: +.PHONY: all clean + +CC = i686-w64-mingw32-gcc +CXX = i686-w64-mingw32-g++ + +CSTD += -std=gnu11 +CXXSTD += -std=gnu++14 + +CFLAGS += -Wall -Werror -Wfatal-errors +CFLAGS += -Wno-error=unused-function +CFLAGS += -Wno-error=unused-variable +CFLAGS += -DUNICODE + +LDFLAGS += -Wl,--subsystem,windows -mwindows -mconsole -municode -ld3d9 + +OPT = -Og + +DEBUG = -g + +DEPFLAGS = -MMD -MP + +makefile_path := $(dir $(abspath $(firstword $(MAKEFILE_LIST)))) + +all: main + +%.o: %.cpp + $(CXX) $(CXXSTD) $(CFLAGS) $(OPT) $(DEBUG) $(DEPFLAGS) -MF ${<}.d -c $< -o $@ + +%.o: %.c + $(CC) $(CSTD) $(CFLAGS) $(CXXFLAGS) $(OPT) $(DEBUG) $(DEPFLAGS) -MF ${<}.d -c $< -o $@ + +MAIN_OBJS = \ + main.o + +main.exe: $(MAIN_OBJS) + $(CXX) $^ -o $@ $(LDFLAGS) + +-include $(shell find $(makefile_path) -type f -name '*.d') + +%: RCS/%,v +%: RCS/% +%: %,v +%: s.% +%: SCCS/s.% diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..05a7c43 --- /dev/null +++ b/main.cpp @@ -0,0 +1,114 @@ +#include +#include + +LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); + +LPDIRECT3D9 g_pD3D = NULL; +LPDIRECT3DDEVICE9 g_pd3dDevice = NULL; + +HRESULT InitDirect3D(HWND hwnd) +{ + g_pD3D = Direct3DCreate9(D3D_SDK_VERSION); + if (g_pD3D == NULL) + return E_FAIL; + + D3DPRESENT_PARAMETERS d3dpp = {}; + d3dpp.Windowed = TRUE; + d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; + d3dpp.BackBufferFormat = D3DFMT_UNKNOWN; + + HRESULT res = g_pD3D->CreateDevice(D3DADAPTER_DEFAULT, + D3DDEVTYPE_HAL, + hwnd, + D3DCREATE_HARDWARE_VERTEXPROCESSING, + &d3dpp, + &g_pd3dDevice); + if (FAILED(res)) { + return E_FAIL; + } + + return S_OK; +} + +void Cleanup() +{ + if (g_pd3dDevice != NULL) + g_pd3dDevice->Release(); + + if (g_pD3D != NULL) + g_pD3D->Release(); +} + +void Render() +{ + if (g_pd3dDevice == NULL) + return; + + g_pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 255), 1.0f, 0); + + if (SUCCEEDED(g_pd3dDevice->BeginScene())) { + g_pd3dDevice->EndScene(); + } + + g_pd3dDevice->Present(NULL, NULL, NULL, NULL); +} + +int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow) +{ + const wchar_t CLASS_NAME[] = L"Sample Window Class"; + + WNDCLASS wc = {}; + + wc.lpfnWndProc = WindowProc; + wc.hInstance = hInstance; + wc.lpszClassName = CLASS_NAME; + + RegisterClass(&wc); + + HWND hwnd = CreateWindowEx(0, // window style + CLASS_NAME, // window class + L"Learn to Program Windows", + WS_OVERLAPPEDWINDOW, + // size and position + CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, + NULL, // parent window + NULL, // menu + hInstance, // instance handle + NULL // additional application data + ); + if (hwnd == NULL) { + return 0; + } + + if (!SUCCEEDED(InitDirect3D(hwnd))) + return 0; + + ShowWindow(hwnd, nCmdShow); + UpdateWindow(hwnd); + + MSG msg = { }; + while (GetMessage(&msg, NULL, 0, 0) > 0) { + TranslateMessage(&msg); + DispatchMessage(&msg); + } + + return 0; +} + +LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) +{ + switch (uMsg) { + case WM_DESTROY: + PostQuitMessage(0); + return 0; + + case WM_PAINT: + { + Render(); + ValidateRect(hwnd, NULL); + } + return 0; + } + + return DefWindowProc(hwnd, uMsg, wParam, lParam); +}