Created
January 6, 2021 15:38
-
-
Save JettMonstersGoBoom/1f693a961dd85805859f1ccf41570b77 to your computer and use it in GitHub Desktop.
opengl context from a makefile ( win32 with TCC )
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#if 0 | |
.PHONY: run | |
run: | |
tcc -run makefile | |
ifeq (0, 1) | |
#endif | |
#include <GL/gl.h> | |
#include "stdio.h" | |
#define FALSE 0 | |
#define TRUE 1 | |
#pragma comment(lib, "opengl32") | |
#pragma comment(lib, "user32") | |
#pragma comment(lib, "gdi32") | |
#define TITLE "Hey" | |
#define WIDTH 640 | |
#define HEIGHT 480 | |
static PIXELFORMATDESCRIPTOR pfd={ | |
0, // Size Of This Pixel Format Descriptor... saves 6 bytes | |
1, PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER, PFD_TYPE_RGBA, 32, 0, 0, 0, 0, 0, | |
0, 0, 0, 0, 0, 0, 0, 32, 0, 0, 0, 0, 0, 0, 0 | |
}; | |
static WNDCLASS s_wc; | |
static HWND s_wnd; | |
static int s_close = 0; | |
static HDC s_hdc; | |
static BITMAPINFO* s_bitmapInfo; | |
static int isRunning; | |
static LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { | |
LRESULT res = 0; | |
switch (message) { | |
case WM_CLOSE: { | |
isRunning = FALSE; | |
break; | |
} | |
default:{ | |
res = DefWindowProc(hWnd, message, wParam, lParam); | |
} | |
} | |
return res; | |
} | |
// using main so we can printf to console | |
int main(int argc, const char *argv[]) { | |
float ticker; | |
isRunning = TRUE; | |
s_wc.style = CS_OWNDC | CS_VREDRAW | CS_HREDRAW; | |
s_wc.lpfnWndProc = WndProc; | |
s_wc.hCursor = LoadCursor(0, IDC_ARROW); | |
s_wc.lpszClassName = TITLE; | |
RegisterClass(&s_wc); | |
s_wnd = CreateWindowEx(0, | |
TITLE, TITLE, | |
WS_SYSMENU | WS_CAPTION, | |
CW_USEDEFAULT, CW_USEDEFAULT, | |
WIDTH,HEIGHT, | |
0, 0, 0, 0); | |
if (!s_wnd) | |
return; | |
ShowWindow(s_wnd, SW_NORMAL); | |
s_hdc = GetDC(s_wnd); | |
SetPixelFormat ( s_hdc, ChoosePixelFormat ( s_hdc, &pfd) , &pfd ); | |
wglMakeCurrent ( s_hdc, wglCreateContext(s_hdc) ); | |
ticker = 0.0f; | |
MSG msg = { }; | |
while (isRunning==TRUE) | |
{ | |
while (PeekMessage(&msg, s_wnd, 0, 0, PM_REMOVE)) | |
{ | |
TranslateMessage(&msg); | |
DispatchMessage(&msg); | |
} | |
glClearColor(0.0, 0.0, 0.0, 1.0); | |
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); | |
glMatrixMode(GL_PROJECTION); | |
glLoadIdentity(); | |
glOrtho(-1.0, 1.0, -1.0, 1.0, -1, 1.0); | |
glMatrixMode(GL_MODELVIEW); | |
glLoadIdentity(); | |
glRotatef(ticker,0,0,1); | |
glBegin(GL_QUADS); | |
glColor3f(1.0, 0.0, 0.0); | |
glVertex3f(-0.75, -0.75, 0.0); | |
glColor3f(0.0, 1.0, 0.0); | |
glVertex3f(0.75, -0.75, 0.0); | |
glColor3f(0.0, 0.0, 1.0); | |
glVertex3f(0.75, 0.75, 0.0); | |
glColor3f(1.0, 1.0, 0.0); | |
glVertex3f(-0.75, 0.75, 0.0); | |
glEnd(); | |
ticker+=0.01f; | |
SwapBuffers(s_hdc); | |
} | |
ReleaseDC(s_wnd, s_hdc); | |
DestroyWindow(s_wnd); | |
return 0; | |
} | |
#define endif | |
endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment