
Эксперт
   
Профиль
Группа: Экс. модератор
Сообщений: 2639
Регистрация: 12.4.2002
Где: Москва
Репутация: 8 Всего: 12
|
Вот те моя тошнилка... если она у тебя мерцать будет - значит видюха левая... з.ы. долго на анимацию не смотри - правда стошнит. Код | #include <StdAfx.h> #include <windows.h> #include <GL/gl.h> #include <GL/glu.h> #include <stdio.h> #include <stdlib.h>
void display() { glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_QUADS); glColor3f(1.0f, 0.0f, 0.0f); glVertex3f(-0.5, -0.5, 0.5); glColor3f(0.0f, 1.0f, 0.0f); glVertex3f(0.5, -0.5, 0.5); glColor3f(0.0f, 0.0f, 1.0f); glVertex3f(0.5, -0.5, -0.5); glColor3f(1.0f, 1.0f, 0.0f); glVertex3f(-0.5, -0.5, -0.5); glEnd();
glBegin(GL_QUADS); glColor3f(1.0f, 0.0f, 0.0f); glVertex3f(-0.5, 0.0, 0.5); glColor3f(0.0f, 1.0f, 0.0f); glVertex3f(0.5, 0.0, 0.5); glColor3f(0.0f, 0.0f, 1.0f); glVertex3f(0.5, 0.0, -0.5); glColor3f(1.0f, 1.0f, 0.0f); glVertex3f(-0.5, 0.0, -0.5); glEnd();
glBegin(GL_QUADS); glColor3f(1.0f, 0.0f, 0.0f); glVertex3f(-0.5, 0.5, 0.5); glColor3f(0.0f, 1.0f, 0.0f); glVertex3f(0.5, 0.5, 0.5); glColor3f(0.0f, 0.0f, 1.0f); glVertex3f(0.5, 0.5, -0.5); glColor3f(1.0f, 1.0f, 0.0f); glVertex3f(-0.5, 0.5, -0.5); glEnd ();
glFlush(); }
LONG WINAPI WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { static PAINTSTRUCT ps;
switch(uMsg) { case WM_PAINT: display(); BeginPaint(hWnd, &ps); EndPaint(hWnd, &ps); return 0;
case WM_TIMER: //glRotatef (1.0, 0.0, 0.0, 0.5); glRotatef (1.0, 1.0, 0.0, 0.5); display(); break;
case WM_SIZE: glViewport(0, 0, LOWORD(lParam), HIWORD(lParam)); PostMessage(hWnd, WM_PAINT, 0, 0); return 0;
case WM_CHAR: switch (wParam) { case 27: /* ESC key */ PostQuitMessage(0); break; } return 0;
case WM_CLOSE: KillTimer (hWnd, 12); PostQuitMessage(0); return 0; }
return DefWindowProc(hWnd, uMsg, wParam, lParam); }
HWND CreateOpenGLWindow(char* title, int x, int y, int width, int height, BYTE type, DWORD flags) { int pf; HDC hDC; HWND hWnd; WNDCLASS wc; PIXELFORMATDESCRIPTOR pfd; static HINSTANCE hInstance = 0;
/* only register the window class once - use hInstance as a flag. */ if (!hInstance) { hInstance = GetModuleHandle(NULL); wc.style = CS_OWNDC; wc.lpfnWndProc = (WNDPROC)WindowProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; wc.hIcon = LoadIcon(NULL, IDI_WINLOGO); wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = NULL; wc.lpszMenuName = NULL; wc.lpszClassName = "OpenGL";
if (!RegisterClass(&wc)) { MessageBox(NULL, "RegisterClass() failed: " "Cannot register window class.", "Error", MB_OK); return NULL; } }
hWnd = CreateWindow("OpenGL", title, WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, x, y, width, height, NULL, NULL, hInstance, NULL);
if (hWnd == NULL) { MessageBox(NULL, "CreateWindow() failed: Cannot create a window.", "Error", MB_OK); return NULL; }
SetTimer (hWnd , 12, 10, NULL);
hDC = GetDC(hWnd);
memset(&pfd, 0, sizeof(pfd)); pfd.nSize = sizeof(pfd); pfd.nVersion = 1; pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | flags; pfd.iPixelType = type; pfd.cColorBits = 16;
pf = ChoosePixelFormat(hDC, &pfd); if (pf == 0) { MessageBox(NULL, "ChoosePixelFormat() failed: " "Cannot find a suitable pixel format.", "Error", MB_OK); return 0; } if (SetPixelFormat(hDC, pf, &pfd) == FALSE) { MessageBox(NULL, "SetPixelFormat() failed: " "Cannot set format specified.", "Error", MB_OK); return 0; }
DescribePixelFormat(hDC, pf, sizeof(PIXELFORMATDESCRIPTOR), &pfd);
ReleaseDC( hWnd, hDC);
return hWnd; }
int APIENTRY WinMain(HINSTANCE hCurrentInst, HINSTANCE hPreviousInst, LPSTR lpszCmdLine, int nCmdShow) { HDC hDC; HGLRC hRC; HWND hWnd; MSG msg;
hWnd = CreateOpenGLWindow("Minimal", 0, 0, 256, 256, PFD_TYPE_RGBA, 0); if (hWnd == NULL) exit(1);
hDC = GetDC(hWnd); hRC = wglCreateContext(hDC); wglMakeCurrent(hDC, hRC);
ShowWindow(hWnd, nCmdShow);
while(GetMessage(&msg, hWnd, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); }
wglMakeCurrent(NULL, NULL); ReleaseDC(hWnd, hDC); wglDeleteContext(hRC); DestroyWindow(hWnd);
return msg.wParam; }
|
--------------------
"Duty is everything; the greatest of joys, the deepest of sorrows" Aribeth de Tylmarande
|