Folge dem Video um zu sehen, wie unsere Website als Web-App auf dem Startbildschirm installiert werden kann.
Anmerkung: Diese Funktion ist in einigen Browsern möglicherweise nicht verfügbar.
// MAIN.CPP //
#include <Windows.h>
#include <glut.h>
#include <gl\GL.h>
#include <gl\GLU.h>
LRESULT CALLBACK WndProc ( HWND, UINT, WPARAM, LPARAM );
HWND hWnd;
HINSTANCE hInstance;
HDC hDC;
HGLRC hRC;
float zoom = 0.0;
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,
0,
16,
0,
0,
PFD_MAIN_PLANE,
0,
0,
0 };
int WINAPI WinMain ( HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR szCmdLine, int iCmdShow )
{
hInstance = hInst;
const char szClassname[] = "hWnd";
MSG msg;
WNDCLASS wc;
wc.cbClsExtra = NULL;
wc.cbWndExtra = NULL;
wc.hbrBackground = NULL;
wc.hCursor = LoadCursor ( NULL, IDC_ARROW );
wc.hIcon = LoadIcon ( NULL, IDI_APPLICATION );
wc.hInstance = hInst;
wc.lpfnWndProc = WndProc;
wc.lpszClassName = szClassname;
wc.lpszMenuName = NULL;
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
if ( ! RegisterClass ( &wc ) )
{
MessageBox ( NULL, "Das Fenster konnte nicht erstellt werden.", "Fehler", MB_OK | MB_ICONERROR );
return 1;
}
hWnd = CreateWindow ( szClassname, "Bewegung im Raum", WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS, 100, 100, 800, 600, NULL, NULL, NULL, NULL );
if ( ! hWnd )
{
MessageBox ( NULL, "Das Fenster konnte nicht erstellt werden.", "Fehler", MB_OK | MB_ICONERROR );
return 1;
}
ShowWindow ( hWnd, SW_SHOW );
UpdateWindow ( hWnd );
while ( GetMessage ( &msg, NULL, 0, 0 ) )
{
TranslateMessage ( &msg );
DispatchMessage ( &msg );
}
return 0;
}
LRESULT CALLBACK WndProc ( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
int iPF;
switch ( msg )
{
case WM_CREATE:
hDC = GetDC ( hwnd );
iPF = ChoosePixelFormat ( hDC, &pfd );
SetPixelFormat ( hDC, iPF, &pfd );
hRC = wglCreateContext ( hDC );
wglMakeCurrent ( hDC, hRC );
glViewport ( 0, 0, ( GLsizei ) 800 , ( GLsizei ) 600 );
glMatrixMode ( GL_PROJECTION );
glLoadIdentity ( );
glFrustum ( -1.0, 1.0, -1.0f, 1.0f, -1.0f, 1.0f );
glLoadIdentity ( );
glMatrixMode ( GL_MODELVIEW );
break;
case WM_KEYDOWN:
switch ( wParam )
{
case VK_ADD:
zoom = zoom - 0.1;
glTranslatef ( 0, 0, zoom );
glFlush ( );
SwapBuffers ( hDC );
InvalidateRect ( hwnd, NULL, true );
break;
case VK_SUBTRACT:
glEnable(GL_DEPTH_TEST);
glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glRotatef ( 10.0, 0, 0, 0 );
glFlush ( );
SwapBuffers ( hDC );
InvalidateRect ( hwnd, NULL, true );
break;
case 'X':
glEnable(GL_DEPTH_TEST);
glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glRotatef ( 5, 0, 1, 0 );
glFlush ( );
SwapBuffers ( hDC );
InvalidateRect ( hwnd, NULL, true );
break;
case 'Y':
glEnable(GL_DEPTH_TEST);
glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glRotatef ( 5, 1, 0, 0 );
glFlush ( );
SwapBuffers ( hDC );
InvalidateRect ( hwnd, NULL, true );
break;
case 'Z':
glEnable(GL_DEPTH_TEST);
glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glRotatef ( 5, 0, 0, 1 );
glFlush ( );
SwapBuffers ( hDC );
InvalidateRect ( hwnd, NULL, true );
break;
case VK_LEFT:
glEnable(GL_DEPTH_TEST);
glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glTranslatef ( 0.025, 0, 0 );
glFlush ( );
SwapBuffers ( hDC );
InvalidateRect ( hwnd, NULL, true );
break;
case VK_RIGHT:
glEnable(GL_DEPTH_TEST);
glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glTranslatef ( -0.025, 0, 0 );
glFlush ( );
SwapBuffers ( hDC );
InvalidateRect ( hwnd, NULL, true );
break;
case VK_UP:
glEnable(GL_DEPTH_TEST);
glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glTranslatef ( 0, 0.025, 0 );
glFlush ( );
SwapBuffers ( hDC );
InvalidateRect ( hwnd, NULL, true );
break;
case VK_DOWN:
glEnable(GL_DEPTH_TEST);
glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glTranslatef ( 0, -0.025, 0 );
glFlush ( );
SwapBuffers ( hDC );
InvalidateRect ( hwnd, NULL, true );
break;
}
break;
case WM_PAINT:
glEnable(GL_DEPTH_TEST);
glClearColor ( 1.0f, 1.0f, 1.0f, 1.0f );
glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glBegin ( GL_QUADS );
glColor3f ( 1, 0, 0 );
glVertex3f ( -0.25, 0.25, 0 );
glVertex3f ( -0.25, -0.25, 0 );
glVertex3f ( 0.25, -0.25, 0 );
glVertex3f ( 0.25, 0.25, 0 );
glColor3f ( 0, 1, 0 );
glVertex3f ( -0.25, 0.25, 0 );
glVertex3f ( -0.25, -0.25, 0 );
glVertex3f ( -0.25, -0.25, -0.25 );
glVertex3f ( -0.25, 0.25, -0.25 );
glColor3f ( 0, 0, 1 );
glVertex3f ( 0.25, 0.25, 0 );
glVertex3f ( 0.25, -0.25, 0 );
glVertex3f ( 0.25, -0.25, -0.25 );
glVertex3f ( 0.25, 0.25, -0.25 );
glColor3f ( 1, 1, 0 );
glVertex3f ( -0.25, 0.25, -0.25 );
glVertex3f ( -0.25, -0.25, -0.25 );
glVertex3f ( 0.25, -0.25, -0.25 );
glVertex3f ( 0.25, 0.25, -0.25 );
glColor3f ( 0, 1, 1 );
glVertex3f ( -0.25, 0.25, 0 );
glVertex3f ( 0.25, 0.25, 0 );
glVertex3f ( 0.25, 0.25, -0.25 );
glVertex3f ( -0.25, 0.25, -0.25 );
glColor3f ( 1, 0, 1 );
glVertex3f ( -0.25, -0.25, 0 );
glVertex3f ( 0.25, -0.25, 0 );
glVertex3f ( 0.25, -0.25, -0.25 );
glVertex3f ( -0.25, -0.25, -0.25 );
glEnd ( );
glFlush ( );
SwapBuffers ( hDC );
ValidateRect ( hwnd, NULL );
break;
case WM_DESTROY:
wglMakeCurrent ( hDC, NULL );
wglDeleteContext ( hRC );
PostQuitMessage ( 0 );
break;
}
return DefWindowProc ( hwnd, msg, wParam, lParam );
}
glLoadIdentity ( );
glFrustum ( -1.0, 1.0, -1.0f, 1.0f, -1.0f, 1.0f );
glLoadIdentity ( );
GL_INVALID_VALUE is generated if nearVal or farVal is not positive, ...
glMatrixMode ( GL_PROJECTION );
glLoadIdentity ( );
float aspectRatio = 600.0f/800.0f;
glFrustum ( -1.0, 1.0, -aspectRatio, aspectRatio, 0.1f, 10.0f );
case VK_ADD:
glTranslatef ( 0, 0, -0.01f );
glFlush ( );
SwapBuffers ( hDC );
InvalidateRect ( hwnd, NULL, true );
break;
Vielleicht hat dsa ja damit etwas zu tun. Und noch eine Frage:Ach ja nebenbei, der Würfel ist bei dir kein Würfel.
// MAIN.CPP //
#include <Windows.h>
#include <glut.h>
#include <gl\GL.h>
#include <gl\GLU.h>
LRESULT CALLBACK WndProc ( HWND, UINT, WPARAM, LPARAM );
HWND hWnd;
HINSTANCE hInstance;
HDC hDC;
HGLRC hRC;
float aspectRatio = 600.0f/800.0f;
PIXELFORMATDESCRIPTOR pfd = {
sizeof ( PIXELFORMATDESCRIPTOR ),
1,
PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL,
PFD_TYPE_RGBA,
32,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
16,
0,
0,
PFD_MAIN_PLANE,
0,
0,
0 };
int WINAPI WinMain ( HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR szCmdLine, int iCmdShow )
{
hInstance = hInst;
const char szClassname[] = "hWnd";
MSG msg;
WNDCLASS wc;
wc.cbClsExtra = NULL;
wc.cbWndExtra = NULL;
wc.hbrBackground = NULL;
wc.hCursor = LoadCursor ( NULL, IDC_ARROW );
wc.hIcon = LoadIcon ( NULL, IDI_APPLICATION );
wc.hInstance = hInst;
wc.lpfnWndProc = WndProc;
wc.lpszClassName = szClassname;
wc.lpszMenuName = NULL;
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
if ( ! RegisterClass ( &wc ) )
{
MessageBox ( NULL, "Das Fenster konnte nicht erstellt werden.", "Fehler", MB_OK | MB_ICONERROR );
return 1;
}
hWnd = CreateWindow ( szClassname, "Bewegung im Raum", WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS, 100, 100, 800, 600, NULL, NULL, NULL, NULL );
if ( ! hWnd )
{
MessageBox ( NULL, "Das Fenster konnte nicht erstellt werden.", "Fehler", MB_OK | MB_ICONERROR );
return 1;
}
ShowWindow ( hWnd, SW_SHOW );
UpdateWindow ( hWnd );
while ( GetMessage ( &msg, NULL, 0, 0 ) )
{
TranslateMessage ( &msg );
DispatchMessage ( &msg );
}
return 0;
}
LRESULT CALLBACK WndProc ( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
int iPF;
switch ( msg )
{
case WM_CREATE:
hDC = GetDC ( hwnd );
iPF = ChoosePixelFormat ( hDC, &pfd );
SetPixelFormat ( hDC, iPF, &pfd );
hRC = wglCreateContext ( hDC );
wglMakeCurrent ( hDC, hRC );
glViewport ( 0, 0, ( GLsizei ) 800 , ( GLsizei ) 600 );
glMatrixMode ( GL_PROJECTION );
glLoadIdentity ( );
glFrustum ( -1.0, 1.0, -aspectRatio, aspectRatio, 0.1f, 10.0f );
break;
case WM_KEYDOWN:
switch ( wParam )
{
case VK_ADD:
glTranslatef ( 0, 0, -0.01f );
glFlush ( );
SwapBuffers ( hDC );
InvalidateRect ( hwnd, NULL, true );
break;
case VK_SUBTRACT:
glEnable(GL_DEPTH_TEST);
glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glRotatef ( 10.0, 0, 0, 0 );
glFlush ( );
SwapBuffers ( hDC );
InvalidateRect ( hwnd, NULL, true );
break;
case 'X':
glEnable(GL_DEPTH_TEST);
glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glRotatef ( 5, 0, 1, 0 );
glFlush ( );
SwapBuffers ( hDC );
InvalidateRect ( hwnd, NULL, true );
break;
case 'Y':
glEnable(GL_DEPTH_TEST);
glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glRotatef ( 5, 1, 0, 0 );
glFlush ( );
SwapBuffers ( hDC );
InvalidateRect ( hwnd, NULL, true );
break;
case 'Z':
glEnable(GL_DEPTH_TEST);
glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glRotatef ( 5, 0, 0, 1 );
glFlush ( );
SwapBuffers ( hDC );
InvalidateRect ( hwnd, NULL, true );
break;
case VK_LEFT:
glEnable(GL_DEPTH_TEST);
glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glTranslatef ( 0.025, 0, 0 );
glFlush ( );
SwapBuffers ( hDC );
InvalidateRect ( hwnd, NULL, true );
break;
case VK_RIGHT:
glEnable(GL_DEPTH_TEST);
glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glTranslatef ( -0.025, 0, 0 );
glFlush ( );
SwapBuffers ( hDC );
InvalidateRect ( hwnd, NULL, true );
break;
case VK_UP:
glEnable(GL_DEPTH_TEST);
glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glTranslatef ( 0, 0.025, 0 );
glFlush ( );
SwapBuffers ( hDC );
InvalidateRect ( hwnd, NULL, true );
break;
case VK_DOWN:
glEnable(GL_DEPTH_TEST);
glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glTranslatef ( 0, -0.025, 0 );
glFlush ( );
SwapBuffers ( hDC );
InvalidateRect ( hwnd, NULL, true );
break;
}
break;
case WM_PAINT:
glEnable(GL_DEPTH_TEST);
glClearColor ( 1.0f, 1.0f, 1.0f, 1.0f );
glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glBegin ( GL_QUADS );
glColor3f ( 1, 0, 0 );
glVertex3f ( -0.25, 0.25, 0 );
glVertex3f ( -0.25, -0.25, 0 );
glVertex3f ( 0.25, -0.25, 0 );
glVertex3f ( 0.25, 0.25, 0 );
glColor3f ( 0, 1, 0 );
glVertex3f ( -0.25, 0.25, 0 );
glVertex3f ( -0.25, -0.25, 0 );
glVertex3f ( -0.25, -0.25, -0.25 );
glVertex3f ( -0.25, 0.25, -0.25 );
glColor3f ( 0, 0, 1 );
glVertex3f ( 0.25, 0.25, 0 );
glVertex3f ( 0.25, -0.25, 0 );
glVertex3f ( 0.25, -0.25, -0.25 );
glVertex3f ( 0.25, 0.25, -0.25 );
glColor3f ( 1, 1, 0 );
glVertex3f ( -0.25, 0.25, -0.25 );
glVertex3f ( -0.25, -0.25, -0.25 );
glVertex3f ( 0.25, -0.25, -0.25 );
glVertex3f ( 0.25, 0.25, -0.25 );
glColor3f ( 0, 1, 1 );
glVertex3f ( -0.25, 0.25, 0 );
glVertex3f ( 0.25, 0.25, 0 );
glVertex3f ( 0.25, 0.25, -0.25 );
glVertex3f ( -0.25, 0.25, -0.25 );
glColor3f ( 1, 0, 1 );
glVertex3f ( -0.25, -0.25, 0 );
glVertex3f ( 0.25, -0.25, 0 );
glVertex3f ( 0.25, -0.25, -0.25 );
glVertex3f ( -0.25, -0.25, -0.25 );
glEnd ( );
glFlush ( );
SwapBuffers ( hDC );
ValidateRect ( hwnd, NULL );
break;
case WM_DESTROY:
wglMakeCurrent ( hDC, NULL );
wglDeleteContext ( hRC );
PostQuitMessage ( 0 );
break;
}
return DefWindowProc ( hwnd, msg, wParam, lParam );
}