mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-02 12:48:14 +00:00
field = value, for structure literals
This commit is contained in:
+38
-50
@@ -24,45 +24,33 @@ win32_print_last_error :: proc() {
|
||||
}
|
||||
|
||||
main :: proc() {
|
||||
wc: WNDCLASSEXA;
|
||||
instance := GetModuleHandleA(null);
|
||||
|
||||
// Init time info
|
||||
_ = QueryPerformanceFrequency(^win32_perf_count_freq);
|
||||
class_name := "Odin-Language-Demo\x00";
|
||||
title := "Odin Language Demo\x00";
|
||||
c_class_name := ^class_name[0];
|
||||
c_title := ^title[0];
|
||||
|
||||
// Yuck!
|
||||
to_c_string :: proc(s: string) -> ^u8 {
|
||||
c_str := heap_alloc(len(s)+1) as ^u8;
|
||||
mem_copy(c_str, ^s[0], len(s));
|
||||
c_str[len(s)] = 0;
|
||||
return c_str;
|
||||
}
|
||||
|
||||
class_name := to_c_string("Odin-Language-Demo");
|
||||
title := to_c_string("Odin Language Demo");
|
||||
defer heap_free(class_name);
|
||||
defer heap_free(title);
|
||||
|
||||
wc.cbSize = size_of(WNDCLASSEXA) as u32;
|
||||
wc.style = CS_VREDRAW | CS_HREDRAW;
|
||||
wc.hInstance = instance;
|
||||
wc.className = class_name;
|
||||
|
||||
wc.wndProc = proc(hwnd: HWND, msg: u32, wparam: WPARAM, lparam: LPARAM) -> LRESULT #no_inline {
|
||||
if msg == WM_DESTROY || msg == WM_CLOSE || msg == WM_QUIT {
|
||||
ExitProcess(0);
|
||||
return 0;
|
||||
}
|
||||
return DefWindowProcA(hwnd, msg, wparam, lparam);
|
||||
wc := WNDCLASSEXA{
|
||||
cbSize = size_of(WNDCLASSEXA) as u32,
|
||||
style = CS_VREDRAW | CS_HREDRAW,
|
||||
hInstance = instance as HINSTANCE,
|
||||
className = c_class_name,
|
||||
wndProc = proc(hwnd: HWND, msg: u32, wparam: WPARAM, lparam: LPARAM) -> LRESULT #no_inline {
|
||||
if msg == WM_DESTROY || msg == WM_CLOSE || msg == WM_QUIT {
|
||||
ExitProcess(0);
|
||||
return 0;
|
||||
}
|
||||
return DefWindowProcA(hwnd, msg, wparam, lparam);
|
||||
},
|
||||
};
|
||||
|
||||
if RegisterClassExA(^wc) == 0 {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
hwnd := CreateWindowExA(0,
|
||||
class_name, title,
|
||||
c_class_name, c_title,
|
||||
WS_VISIBLE | WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX,
|
||||
CW_USEDEFAULT, CW_USEDEFAULT, 854, 480,
|
||||
null, null, instance, null);
|
||||
@@ -77,31 +65,31 @@ main :: proc() {
|
||||
opengl_context: HGLRC;
|
||||
|
||||
{
|
||||
attribs : [8]i32;
|
||||
pfd: PIXELFORMATDESCRIPTOR;
|
||||
pfd.nSize = size_of(PIXELFORMATDESCRIPTOR) as u32;
|
||||
pfd.nVersion = 1;
|
||||
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
|
||||
pfd.iPixelType = PFD_TYPE_RGBA;
|
||||
pfd.cColorBits = 32;
|
||||
pfd.cAlphaBits = 8;
|
||||
pfd.cDepthBits = 24;
|
||||
pfd.cStencilBits = 8;
|
||||
pfd.iLayerType = PFD_MAIN_PLANE;
|
||||
pfd := PIXELFORMATDESCRIPTOR{
|
||||
nSize = size_of(PIXELFORMATDESCRIPTOR) as u32,
|
||||
nVersion = 1,
|
||||
dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
|
||||
iPixelType = PFD_TYPE_RGBA,
|
||||
cColorBits = 32,
|
||||
cAlphaBits = 8,
|
||||
cDepthBits = 24,
|
||||
cStencilBits = 8,
|
||||
iLayerType = PFD_MAIN_PLANE,
|
||||
};
|
||||
|
||||
SetPixelFormat(dc, ChoosePixelFormat(dc, ^pfd), null);
|
||||
opengl_context = wglCreateContext(dc);
|
||||
wglMakeCurrent(dc, opengl_context);
|
||||
|
||||
attribs[0] = 0x2091; // WGL_CONTEXT_MAJOR_VERSION_ARB
|
||||
attribs[1] = 2; // Major
|
||||
attribs[2] = 0x2092; // WGL_CONTEXT_MINOR_VERSION_ARB
|
||||
attribs[3] = 1; // Minor
|
||||
|
||||
attribs[4] = 0x9126; // WGL_CONTEXT_PROFILE_MASK_ARB
|
||||
attribs[5] = 0x0002; // WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB
|
||||
|
||||
attribs[6] = 0; // NOTE(bill): tells the proc that this is the end of attribs
|
||||
attribs := [8]i32{
|
||||
0x2091, // WGL_CONTEXT_MAJOR_VERSION_ARB
|
||||
2, // Major
|
||||
0x2092, // WGL_CONTEXT_MINOR_VERSION_ARB
|
||||
1, // Minor
|
||||
0x9126, // WGL_CONTEXT_PROFILE_MASK_ARB
|
||||
0x0002, // WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB
|
||||
0, // NOTE(bill): tells the proc that this is the end of attribs
|
||||
};
|
||||
|
||||
wgl_string := "wglCreateContextAttribsARB\x00";
|
||||
wglCreateContextAttribsARB := wglGetProcAddress(^wgl_string[0]) as wglCreateContextAttribsARBType;
|
||||
@@ -111,7 +99,7 @@ main :: proc() {
|
||||
}
|
||||
|
||||
start_time := time_now();
|
||||
running := true;
|
||||
running := false;
|
||||
for running {
|
||||
curr_time := time_now();
|
||||
dt := curr_time - start_time;
|
||||
|
||||
Reference in New Issue
Block a user