Skip to content

Instantly share code, notes, and snippets.

@jsonzilla
Forked from zeux/nanoglfw.cpp
Created November 4, 2022 12:22
Show Gist options
  • Save jsonzilla/1ceeb49ed1d0e1bd19a9ff92cd05800a to your computer and use it in GitHub Desktop.
Save jsonzilla/1ceeb49ed1d0e1bd19a9ff92cd05800a to your computer and use it in GitHub Desktop.
#include <windows.h>
#include <GL/gl.h>
#include <stdio.h>
#pragma comment(lib, "opengl32.lib")
void glview()
{
HWND hWnd = CreateWindow(L"ListBox", L"Title", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, NULL, NULL);
HDC hDC = GetDC(hWnd);
PIXELFORMATDESCRIPTOR pfd = { sizeof(pfd), 1, PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER, 0, 32 };
SetPixelFormat(hDC, ChoosePixelFormat(hDC, &pfd), &pfd);
wglMakeCurrent(hDC, wglCreateContext(hDC));
ShowWindow(hWnd, SW_SHOWNORMAL);
MSG msg;
while (GetMessage(&msg, hWnd, 0, 0) && msg.message)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
RECT rect;
GetClientRect(hWnd, &rect);
glViewport(0, 0, rect.right - rect.left, rect.bottom - rect.top);
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_TRIANGLES);
glColor3f(1.0f, 0.0f, 0.0f);
glVertex2i(0, 1);
glColor3f(0.0f, 1.0f, 0.0f);
glVertex2i(-1, -1);
glColor3f(0.0f, 0.0f, 1.0f);
glVertex2i(1, -1);
glEnd();
SwapBuffers(hDC);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment