Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Windows.h>
- #include <GL/GL.h>
- #include <iostream>
- #include <string.h>
- #include <tchar.h>
- #pragma comment (lib, "opengl32.lib")
- static TCHAR szWindowClass[] = _T("Windows32App");
- static TCHAR szTitle[] = _T("OpenGL 3.3 Demo");
- bool active = TRUE;
- bool keys[256];
- int DRAW_OPENGL(GLvoid)
- {
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- glTranslatef(3.0f,0.0f,0.0f);
- glBegin(GL_TRIANGLES);
- glVertex3f(0.0f,1.0f,0.0f);
- glVertex3f(-1.0f,-1.0f,0.0f);
- glVertex3f(1.0f,-1.0f,0.0f);
- glEnd();
- return TRUE;
- }
- LRESULT CALLBACK WindowProcedure(HWND WindowHandle, UINT Messages, WPARAM wParam, LPARAM lParam)
- {
- //PAINTSTRUCT ps;
- HDC hdc = NULL;
- TCHAR greeting[] = _T("Test");
- COLORREF NewColor = RGB(255,0,0);
- switch(Messages)
- {
- case WM_ACTIVATE:
- {
- if(!HIWORD(wParam))
- {
- active = TRUE;
- }
- else
- {
- active = FALSE;
- }
- return 0;
- }
- case WM_CREATE:
- {
- PIXELFORMATDESCRIPTOR pfd =
- {
- sizeof(PIXELFORMATDESCRIPTOR),
- 1,
- PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,
- PFD_TYPE_RGBA,
- 32,
- 0,0,0,0,0,0
- ,0
- ,0
- ,0
- ,0,0,0,0,
- 16,
- 0,
- 0,
- PFD_MAIN_PLANE,
- 0,
- 0,0,0
- };
- hdc = GetDC(WindowHandle);
- GLuint ChooseWindowFormat = ChoosePixelFormat(hdc,&pfd);
- if(!SetPixelFormat(hdc,ChooseWindowFormat,&pfd))
- {
- MessageBox(NULL,L"Can't Set The PixelFormat.",L"ERROR",MB_OK|MB_ICONEXCLAMATION);
- };
- HGLRC DummyGLContext = wglCreateContext(hdc);
- wglMakeCurrent(hdc, DummyGLContext);
- MessageBoxA(0, (char*)glGetString(GL_VERSION), "OPENGL VERSION",0);
- //wglDeleteContext(0);
- glViewport(0,0,640,480);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glOrtho(0,640,0,480,-1,1);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- glClearColor(255,0,0,0);
- }
- break;
- //case WM_PAINT:
- //hdc = BeginPaint(WindowHandle, &ps);
- //EndPaint(WindowHandle, &ps);
- /*
- SetTextColor(hdc, NewColor);
- TextOut(hdc,5,5,greeting, _tcslen(greeting));
- */
- //break;
- case WM_CLOSE:
- DestroyWindow(WindowHandle);
- break;
- case WM_DESTROY:
- PostQuitMessage(0);
- break;
- default:
- return DefWindowProc(WindowHandle,Messages,wParam,lParam);
- }
- return 0;
- }
- int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLine, int nCmdShow)
- {
- MSG Messages;
- WNDCLASSEX WindowClass;
- HDC hdc = NULL;
- bool Running = true;
- hInstance = GetModuleHandle(NULL);
- WindowClass.cbSize = sizeof(WNDCLASSEX);
- WindowClass.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC ;
- WindowClass.lpfnWndProc = WindowProcedure;
- WindowClass.cbClsExtra = 0;
- WindowClass.cbWndExtra = 0;
- WindowClass.hInstance = hInstance;
- WindowClass.hIcon = LoadIcon(NULL, IDI_WINLOGO);
- WindowClass.hCursor = LoadCursor(NULL, IDC_ARROW);
- WindowClass.hbrBackground = NULL;
- WindowClass.lpszMenuName = NULL;
- WindowClass.lpszClassName = szWindowClass;
- WindowClass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
- if(!RegisterClassEx(&WindowClass)) {
- MessageBox(NULL,
- _T("Window Creation Failed"),
- _T("ERROR") ,
- NULL);
- return 1;
- }
- HWND WindowHandle = CreateWindow(
- szWindowClass,
- szTitle,
- WS_OVERLAPPEDWINDOW,
- CW_USEDEFAULT, CW_USEDEFAULT,
- 640,480,
- NULL,
- NULL,
- hInstance,
- NULL
- );
- if(!WindowHandle)
- {
- MessageBox(NULL,
- _T("Window Registration Failed!"),
- _T("ERROR"),
- NULL);
- return 1;
- }
- ShowWindow(WindowHandle, nCmdShow);
- UpdateWindow(WindowHandle);
- while(Running == true)
- {
- while(PeekMessage(&Messages,NULL,0,0,PM_NOREMOVE))
- {
- if(GetMessage(&Messages, NULL, 0, 0))
- {
- TranslateMessage(&Messages);
- DispatchMessage(&Messages);
- }
- else
- {
- return Messages.wParam;
- }
- }
- DRAW_OPENGL();
- SwapBuffers(hdc);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement