Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <windows.h>
- #include <gl/gl.h>
- #include <gl/glu.h>
- #include <stdio.h>
- #include <stdlib.h>
- HDC hdc;
- HWND hwnd;
- WNDCLASS wnd;
- HGLRC hglrc;
- MSG msg;
- LPSTR szClassName = "MyClass";
- HINSTANCE hInstance;
- LRESULT CALLBACK MyWndProc(HWND, UINT, WPARAM, LPARAM);
- void startGL();
- void initwindow();
- void closewindow();
- void draw();
- int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInstance, LPSTR szCmdLine, int iCmdShow)
- {
- hInstance = hInst;
- initwindow();
- startGL();
- while(1) {
- if(PeekMessage(&msg, hwnd, 0, 0, PM_REMOVE)) {
- if(msg.message == WM_QUIT) {
- break;
- }
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- } else
- draw();
- Sleep(100); //crappy way of stopping 10000000000000 loops a second
- }
- closewindow();
- return msg.wParam;
- }
- void initwindow()
- {
- wnd.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; //CS_OWNDC required for OPEGL - HREDRAW and VREDRAW update the screen on resize.
- wnd.lpfnWndProc = MyWndProc;
- wnd.cbClsExtra = 0;
- wnd.cbWndExtra = 0;
- wnd.hInstance = hInstance;
- wnd.hIcon = LoadIcon(NULL, IDI_APPLICATION); //Icon of the program - default
- wnd.hCursor = LoadCursor(NULL, IDC_ARROW); //Mouse cursor - default
- wnd.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
- wnd.lpszMenuName = NULL; //no menu
- wnd.lpszClassName = szClassName;
- if(!RegisterClass(&wnd)) {
- MessageBox(NULL, "couldn't register class", //cant continue
- "Error", MB_OK);
- return 0;
- }
- hwnd = CreateWindow(szClassName, "Arcticcu leetpro swagfagets!",WS_OVERLAPPEDWINDOW,
- CW_USEDEFAULT,CW_USEDEFAULT,
- 1000,1000,NULL,NULL,hInstance,NULL);
- ShowWindow(hwnd, iCmdShow); //Shows and updates window.
- UpdateWindow(hwnd);
- }
- void startGL()
- {
- hdc = GetDC(hwnd);
- PIXELFORMATDESCRIPTOR pfd = {0};
- pfd.nSize = sizeof( PIXELFORMATDESCRIPTOR ); // just its size
- pfd.nVersion = 1; // always 1
- pfd.dwFlags = PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER | PFD_DRAW_TO_WINDOW; // openglsupport - doublebuffer support - draw to window not bitmap
- pfd.iPixelType = PFD_TYPE_RGBA ; // red, green, blue, alpha for each pixel
- pfd.cColorBits = 24; // 24 bit == 8 bits for red, 8 for green, 8 for blue.
- pfd.cDepthBits = 32;
- int pick;
- pick = ChoosePixelFormat(hdc, &pfd);
- SetPixelFormat(hdc,pick,&pfd);
- hglrc = wglCreateContext(hdc);
- wglMakeCurrent(hdc, hglrc);
- }
- void closewindow()
- {
- wglMakeCurrent(NULL,NULL); // makes the opengl context not-current
- wglDeleteContext(hglrc); // deletes the opengl context
- ReleaseDC(hwnd, hdc); // releases Device context
- CloseWindow(hwnd); //closes the window, duh
- }
- void draw()
- {
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glMatrixMode(GL_MODELVIEW); //Basic opengl drawing.. a triangle :P
- glTranslatef(0,0,0);
- glClear(GL_COLOR_BUFFER_BIT);
- glBegin(GL_POLYGON);
- glColor3f(1,0,0);
- glVertex2f(-0.6, -0.75);
- glColor3f(0, 1, 0);
- glVertex2f(0.6, -0.75);
- glColor3f(0, 0, 1);
- glVertex2f(0, 0.75);
- glEnd();
- SwapBuffers(hdc); //Swap the buffers so what was drawn is shown on the screen, must be done on each redraw.
- }
- LRESULT CALLBACK MyWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
- {
- if(msg == WM_DESTROY) {
- PostQuitMessage(0);
- break;
- }
- if(msg == WM_CLOSE) {
- DestroyWindow(hwnd);
- break;
- }
- return DefWindowProc(hwnd, msg, wParam, lParam);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement