#include <windows.h>
#include <stdio.h>
#include <gl\gl.h>
#include <gl\glu.h>
#pragma comment(lib,"opengl32.lib")
#pragma comment(lib,"glu32.lib")
#pragma comment(lib,"glu32.lib")
#include "ExampleProject.h"
HINSTANCE hInst;
GLvoid ReSizeGLScene(GLsizei width, GLsizei height)
{
if (height == 0)
height = 1;
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0f, (GLfloat)width / (GLfloat)height, 0.1f, 1000.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
int i = 0;
int DrawGLScene(int i)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0, 0, -10);
glRotatef(i, 0, 0, 0);
glBegin(GL_LINES);
glColor3d(1, 0, 0);
glVertex3d(10, 0, 0);
glVertex3d(-10, 0, 0);
glColor3d(0, 1, 0);
glVertex3d(0,10, 0);
glVertex3d(0,-10, 0);
glColor3d(0, 0, 1);
glVertex3d(0,0,10);
glVertex3d(0,0,-10);
glEnd();
return 1;
}
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
HWND hWndButton;
HWND hWndAbout;
switch (message)
{
/* case WM_PAINT:
DrawGLScene();
SwapBuffers(GetDC(hwnd));
RECT rect;
GetClientRect(hwnd, &rect);
ValidateRect(hwnd, &rect);
break;*/
case WM_SIZE:
ReSizeGLScene(LOWORD(lParam), HIWORD(lParam));
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
}
return DefWindowProc (hwnd, message, wParam, lParam);
}
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
hInst = hInstance;
WNDCLASS wc;
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
wc.lpfnWndProc = (WNDPROC)WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(FIRSTAPP_ICON_MAIN));
wc.hCursor = LoadCursor(NULL, IDC_HAND);
wc.hbrBackground = NULL;
wc.lpszMenuName = MAKEINTRESOURCE(FIRSTAPP_MENU_MAIN);
wc.lpszClassName = TEXT("ExampleProjectWindowClass");
if ( !RegisterClass( &wc ) ) return( FALSE );
HWND hWnd = CreateWindow( TEXT("ExampleProjectWindowClass"),
TEXT("ExampleProjectWindow"),
WS_OVERLAPPEDWINDOW,
0,
0,
600,
800,
NULL,
NULL,
hInstance,
NULL);
if ( hWnd == NULL ) return( FALSE );
static PIXELFORMATDESCRIPTOR pfd =
{
sizeof(PIXELFORMATDESCRIPTOR),
1,
PFD_DRAW_TO_WINDOW |
PFD_SUPPORT_OPENGL |
PFD_DOUBLEBUFFER,
PFD_TYPE_RGBA,
16,
0,0,0,0,0,0,
0,
0,
0,
0,0,0,0,
16,
0,
0,
PFD_MAIN_PLANE,
0,
0,0,0
};
HDC hDC = NULL;
HGLRC hRC = NULL;
GLuint PixelFormat;
if (!(hDC = GetDC(hWnd))) return 0;
if (!(PixelFormat = ChoosePixelFormat(hDC, &pfd))) return 0;
if (!SetPixelFormat(hDC, PixelFormat, &pfd)) return 0;
if (!(hRC = wglCreateContext(hDC))) return 0;
if (!wglMakeCurrent(hDC, hRC)) return 0;
ShowWindow(hWnd,iCmdShow);
SetForegroundWindow(hWnd);
SetFocus(hWnd);
MSG msg;
BOOL done = false;
while (!done)
{
if (PeekMessage(&msg, NULL, 0, 0,PM_REMOVE))
{
if (msg.message == WM_QUIT) { done = TRUE; }
else
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
else
{
DrawGLScene(i);
i = i + 10;
SwapBuffers(hDC);
}
}
if (hRC)
{
!wglMakeCurrent(NULL, NULL);
!wglDeleteContext(hRC);
hRC = NULL;
}
if (hDC && !ReleaseDC(hWnd, hDC)) { hDC = NULL; }
if (hWnd && !DestroyWindow(hWnd)) { hWnd = NULL; }
return 0;
}
Dlaczego scena się nie obraca tylko dziwnie miga? Chciałbym zrobić animację jak te trzy proste się obracają w przestrzeni, a coś mi to nie działa.
A ponadto nie wiem dlaczego niebieska linia mi się nie wyświetla w ogóle.