Must be something obvious I'm missing. Any help would be awesome!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 | #include "toast_platform.h" #include <windows.h> #include <gl/gl.h> #include "win32_toast.h" global_variable bool32 GlobalRunning; internal win32_window_dimension Win32GetWindowSize(HWND Window) { RECT WindowRect; GetClientRect(Window, &WindowRect); win32_window_dimension Result; Result.Width = WindowRect.right - WindowRect.left; Result.Height = WindowRect.bottom - WindowRect.top; return(Result); } internal void Win32DisplayBufferInWindow(HDC DeviceContext, int32 Width, int32 Height) { glViewport(0, 0, Width, Height); glClearColor(1.0f, 0.0f, 1.0f, 0.0f); glClear(GL_COLOR_BUFFER_BIT); SwapBuffers(DeviceContext); } internal void Win32InitOpenGL(HWND Window) { HDC DeviceContext = GetDC(Window); HGLRC OpenGLRC = wglCreateContext(DeviceContext); PIXELFORMATDESCRIPTOR DesiredPixelFormat = {}; DesiredPixelFormat.nSize = sizeof(DesiredPixelFormat); DesiredPixelFormat.nVersion = 1; DesiredPixelFormat.dwFlags = PFD_SUPPORT_OPENGL|PFD_DRAW_TO_WINDOW|PFD_DOUBLEBUFFER; DesiredPixelFormat.cColorBits = 32; DesiredPixelFormat.cAlphaBits = 8; DesiredPixelFormat.iLayerType = PFD_MAIN_PLANE; int32 SuggestedPixelFormatIndex = ChoosePixelFormat(DeviceContext, &DesiredPixelFormat); PIXELFORMATDESCRIPTOR SuggestedPixelFormat = {}; DescribePixelFormat(DeviceContext, SuggestedPixelFormatIndex, sizeof(SuggestedPixelFormat), &SuggestedPixelFormat); SetPixelFormat(DeviceContext, SuggestedPixelFormatIndex, &SuggestedPixelFormat); if(wglMakeCurrent(DeviceContext, OpenGLRC)) { int32 Y = 6; } else { int32 Y = 6; } ReleaseDC(Window, DeviceContext); } internal LRESULT CALLBACK Win32MainWindowCallback(HWND Window, UINT Message, WPARAM WParam, LPARAM LParam) { LRESULT Result = 0; switch(Message) { case WM_CLOSE: { GlobalRunning = false; } break; case WM_PAINT: { PAINTSTRUCT Paint; HDC DeviceContext = BeginPaint(Window, &Paint); win32_window_dimension WindowSize = Win32GetWindowSize(Window); Win32DisplayBufferInWindow(DeviceContext, WindowSize.Width, WindowSize.Height); EndPaint(Window, &Paint); } default: { Result = DefWindowProc(Window, Message, WParam, LParam); } break; } return(Result); } int CALLBACK WinMain(HINSTANCE Instance, HINSTANCE PrevInstance, LPSTR CommandLine, int ShowCode) { WNDCLASS WindowClass = {}; WindowClass.style = CS_HREDRAW|CS_VREDRAW|CS_OWNDC; WindowClass.lpfnWndProc = Win32MainWindowCallback; WindowClass.hInstance = Instance; WindowClass.hCursor = LoadCursor(0, IDC_ARROW); WindowClass.lpszClassName = "ToastWindowClass"; if(RegisterClass(&WindowClass)) { HWND Window = CreateWindowEx(0, WindowClass.lpszClassName, "Toast Game", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, Instance, 0); if(Window) { GlobalRunning = true; Win32InitOpenGL(Window); ShowWindow(Window, ShowCode); HDC DeviceContext = GetDC(Window); MSG Message = {}; while(GlobalRunning) { while(PeekMessage(&Message, 0, 0, 0, PM_REMOVE)) { TranslateMessage(&Message); DispatchMessage(&Message); } win32_window_dimension WindowSize = Win32GetWindowSize(Window); Win32DisplayBufferInWindow(DeviceContext, WindowSize.Width, WindowSize.Height); } } } return(0); } |