Accueil > > > WIN32 COMBINÉ AVEC GLUT...
WIN32 COMBINÉ AVEC GLUT...
Information sur la source
Description
Bin, j'ai combiné glut avec l'api Win32 pour voir ce que ça donne... Plus un truc nouveau pour moi, un changement de caméra. Dsl sur le code, je n'ai pas fait de commentaire, j'en mettrai quand j'aurai le temps.
Source
- #include <stdio.h>
- #include <windows.h>
- #include <gl/gl.h>
- #include <gl/glut.h>
- #include <gl/glu.h>
-
- LRESULT CALLBACK WndProc (HWND hWnd, UINT message,
- WPARAM wParam, LPARAM lParam);
- void EnableOpenGL (HWND hWnd, HDC *hDC, HGLRC *hRC);
- void DisableOpenGL (HWND hWnd, HDC hDC, HGLRC hRC);
- GLfloat rtri;
-
-
- int WINAPI WinMain (HINSTANCE hInstance,
- HINSTANCE hPrevInstance,
- LPSTR lpCmdLine,
- int iCmdShow)
- {
- WNDCLASS wc;
- HWND hWnd;
- HDC hDC;
- HGLRC hRC;
- MSG msg;
- BOOL bQuit = FALSE;
- float theta = 0.0f;
-
- wc.style = CS_OWNDC;
- wc.lpfnWndProc = WndProc;
- wc.cbClsExtra = 0;
- wc.cbWndExtra = 0;
- wc.hInstance = hInstance;
- wc.hIcon = LoadIcon (NULL, IDI_APPLICATION);
- wc.hCursor = LoadCursor (NULL, IDC_ARROW);
- wc.hbrBackground = (HBRUSH) GetStockObject (BLACK_BRUSH);
- wc.lpszMenuName = NULL;
- wc.lpszClassName = "GLSample";
- RegisterClass (&wc);
-
- hWnd = CreateWindow (
- "GLSample", "Glut et l'API Win32.",
- WS_CAPTION | WS_POPUPWINDOW | WS_VISIBLE,
- 0, 0, 800, 600,
- NULL, NULL, hInstance, NULL);
-
- EnableOpenGL (hWnd, &hDC, &hRC);
-
- while (!bQuit)
- {
- if (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE))
- {
- if (msg.message == WM_QUIT)
- {
- bQuit = TRUE;
- }
- else
- {
- TranslateMessage (&msg);
- DispatchMessage (&msg);
- }
- }
- else
- {
- glClearColor (0.0f, 0.0f, 0.0f, 0.0f);
- glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- glMatrixMode(GL_MODELVIEW);
- gluLookAt (0,0,-1,0,0,0,0.5,1,0);
- glRotatef(0.2,0.0f,1.0f,0.0f);
-
- glPushMatrix ();
- glColor3f(1.0,1.0,1.0);
- glutWireSphere(0.5,5,5);
- glPopMatrix ();
-
- glPushMatrix ();
- glBegin (GL_LINE_LOOP);
- glColor3f(1.0,0.0,0.0);
- glVertex3f(-0.5,-0.5,-0.5);
- glColor3f(0.0,1.0,0.0);
- glVertex3f(0.5,0.01,0.2);
- glColor3f(0.0,0.0,1.0);
- glVertex3f(0.5,0.5,0.5);
- glColor3f(1.0,0.0,1.0);
- glVertex3f(0.2,0.05,0.03);
- glColor3f(0.0,1.0,1.0);
- glVertex3f(-0.5,-0.5,-0.5);
-
- glColor3f(1.0,0.0,0.0);
- glVertex3f(0.1,0.1,0.1);
- glColor3f(0.0,1.0,0.0);
- glVertex3f(-0.1,-0.01,-0.2);
- glColor3f(0.0,0.0,1.0);
- glVertex3f(-0.1,-0.1,-0.1);
- glColor3f(1.0,0.0,1.0);
- glVertex3f(-0.2,-0.05,-0.03);
- glColor3f(0.0,1.0,1.0);
- glVertex3f(0.1,0.1,0.1);
- glEnd ();
-
- glBegin (GL_LINE_LOOP);
- glColor3f(1.0,0.0,0.0);
- glVertex3f(0.5,0.5,0.5);
- glColor3f(0.0,1.0,0.0);
- glVertex3f(-0.5,-0.01,-0.2);
- glColor3f(0.0,0.0,1.0);
- glVertex3f(-0.5,-0.5,-0.5);
- glColor3f(1.0,0.0,1.0);
- glVertex3f(-0.2,-0.05,-0.03);
- glColor3f(0.0,1.0,1.0);
- glVertex3f(0.5,0.5,0.5);
-
- glColor3f(1.0,0.0,0.0);
- glVertex3f(-0.1,-0.1,-0.1);
- glColor3f(0.0,1.0,0.0);
- glVertex3f(0.1,0.01,0.2);
- glColor3f(0.0,0.0,1.0);
- glVertex3f(0.1,0.1,0.1);
- glColor3f(1.0,0.0,1.0);
- glVertex3f(0.2,0.05,0.03);
- glColor3f(0.0,1.0,1.0);
- glVertex3f(-0.1,-0.1,-0.1);
- glEnd ();
- glPopMatrix ();
-
-
-
- glPushMatrix ();
- gluLookAt (0,0,-1,0,0,0,-0.5,1,0);
- glColor3f(1.0,1.0,1.0);
- glutWireSphere(0.5,5,5);
- glPopMatrix ();
-
- glPushMatrix ();
- gluLookAt (0,0,-1,0,0,0,-0.5,1,0);
- glBegin (GL_LINE_LOOP);
- glColor3f(1.0,0.0,0.0);
- glVertex3f(-0.5,-0.5,-0.5);
- glColor3f(0.0,1.0,0.0);
- glVertex3f(0.5,0.01,0.2);
- glColor3f(0.0,0.0,1.0);
- glVertex3f(0.5,0.5,0.5);
- glColor3f(1.0,0.0,1.0);
- glVertex3f(0.2,0.05,0.03);
- glColor3f(0.0,1.0,1.0);
- glVertex3f(-0.5,-0.5,-0.5);
-
- glColor3f(1.0,0.0,0.0);
- glVertex3f(0.1,0.1,0.1);
- glColor3f(0.0,1.0,0.0);
- glVertex3f(-0.1,-0.01,-0.2);
- glColor3f(0.0,0.0,1.0);
- glVertex3f(-0.1,-0.1,-0.1);
- glColor3f(1.0,0.0,1.0);
- glVertex3f(-0.2,-0.05,-0.03);
- glColor3f(0.0,1.0,1.0);
- glVertex3f(0.1,0.1,0.1);
- glEnd ();
-
- glBegin (GL_LINE_LOOP);
- glColor3f(1.0,0.0,0.0);
- glVertex3f(0.5,0.5,0.5);
- glColor3f(0.0,1.0,0.0);
- glVertex3f(-0.5,-0.01,-0.2);
- glColor3f(0.0,0.0,1.0);
- glVertex3f(-0.5,-0.5,-0.5);
- glColor3f(1.0,0.0,1.0);
- glVertex3f(-0.2,-0.05,-0.03);
- glColor3f(0.0,1.0,1.0);
- glVertex3f(0.5,0.5,0.5);
-
- glColor3f(1.0,0.0,0.0);
- glVertex3f(-0.1,-0.1,-0.1);
- glColor3f(0.0,1.0,0.0);
- glVertex3f(0.1,0.01,0.2);
- glColor3f(0.0,0.0,1.0);
- glVertex3f(0.1,0.1,0.1);
- glColor3f(1.0,0.0,1.0);
- glVertex3f(0.2,0.05,0.03);
- glColor3f(0.0,1.0,1.0);
- glVertex3f(-0.1,-0.1,-0.1);
- glEnd ();
- glPopMatrix ();
-
- SwapBuffers (hDC);
- }
- }
- DisableOpenGL (hWnd, hDC, hRC);
-
- DestroyWindow (hWnd);
-
- return msg.wParam;
- }
-
- LRESULT CALLBACK WndProc (HWND hWnd, UINT message,
- WPARAM wParam, LPARAM lParam)
- {
-
- switch (message)
- {
- case WM_CREATE:
- return 0;
- case WM_CLOSE:
- PostQuitMessage (0);
- return 0;
-
- case WM_DESTROY:
- return 0;
-
- case WM_KEYDOWN:
- switch (wParam)
- {
- case VK_ESCAPE:
- PostQuitMessage(0);
- return 0;
- }
- return 0;
-
- default:
- return DefWindowProc (hWnd, message, wParam, lParam);
- }
- }
-
- void EnableOpenGL (HWND hWnd, HDC *hDC, HGLRC *hRC)
- {
- PIXELFORMATDESCRIPTOR pfd;
- int iFormat;
-
- *hDC = GetDC (hWnd);
-
- ZeroMemory (&pfd, sizeof (pfd));
- pfd.nSize = sizeof (pfd);
- pfd.nVersion = 1;
- pfd.dwFlags = PFD_DRAW_TO_WINDOW |
- PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
- pfd.iPixelType = PFD_TYPE_RGBA;
- pfd.cColorBits = 24;
- pfd.cDepthBits = 16;
- pfd.iLayerType = PFD_MAIN_PLANE;
- iFormat = ChoosePixelFormat (*hDC, &pfd);
- SetPixelFormat (*hDC, iFormat, &pfd);
-
- *hRC = wglCreateContext( *hDC );
- wglMakeCurrent( *hDC, *hRC );
-
- }
-
- void DisableOpenGL (HWND hWnd, HDC hDC, HGLRC hRC)
- {
- wglMakeCurrent (NULL, NULL);
- wglDeleteContext (hRC);
- ReleaseDC (hWnd, hDC);
- }
#include <stdio.h>
#include <windows.h>
#include <gl/gl.h>
#include <gl/glut.h>
#include <gl/glu.h>
LRESULT CALLBACK WndProc (HWND hWnd, UINT message,
WPARAM wParam, LPARAM lParam);
void EnableOpenGL (HWND hWnd, HDC *hDC, HGLRC *hRC);
void DisableOpenGL (HWND hWnd, HDC hDC, HGLRC hRC);
GLfloat rtri;
int WINAPI WinMain (HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int iCmdShow)
{
WNDCLASS wc;
HWND hWnd;
HDC hDC;
HGLRC hRC;
MSG msg;
BOOL bQuit = FALSE;
float theta = 0.0f;
wc.style = CS_OWNDC;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor (NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH) GetStockObject (BLACK_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = "GLSample";
RegisterClass (&wc);
hWnd = CreateWindow (
"GLSample", "Glut et l'API Win32.",
WS_CAPTION | WS_POPUPWINDOW | WS_VISIBLE,
0, 0, 800, 600,
NULL, NULL, hInstance, NULL);
EnableOpenGL (hWnd, &hDC, &hRC);
while (!bQuit)
{
if (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE))
{
if (msg.message == WM_QUIT)
{
bQuit = TRUE;
}
else
{
TranslateMessage (&msg);
DispatchMessage (&msg);
}
}
else
{
glClearColor (0.0f, 0.0f, 0.0f, 0.0f);
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
gluLookAt (0,0,-1,0,0,0,0.5,1,0);
glRotatef(0.2,0.0f,1.0f,0.0f);
glPushMatrix ();
glColor3f(1.0,1.0,1.0);
glutWireSphere(0.5,5,5);
glPopMatrix ();
glPushMatrix ();
glBegin (GL_LINE_LOOP);
glColor3f(1.0,0.0,0.0);
glVertex3f(-0.5,-0.5,-0.5);
glColor3f(0.0,1.0,0.0);
glVertex3f(0.5,0.01,0.2);
glColor3f(0.0,0.0,1.0);
glVertex3f(0.5,0.5,0.5);
glColor3f(1.0,0.0,1.0);
glVertex3f(0.2,0.05,0.03);
glColor3f(0.0,1.0,1.0);
glVertex3f(-0.5,-0.5,-0.5);
glColor3f(1.0,0.0,0.0);
glVertex3f(0.1,0.1,0.1);
glColor3f(0.0,1.0,0.0);
glVertex3f(-0.1,-0.01,-0.2);
glColor3f(0.0,0.0,1.0);
glVertex3f(-0.1,-0.1,-0.1);
glColor3f(1.0,0.0,1.0);
glVertex3f(-0.2,-0.05,-0.03);
glColor3f(0.0,1.0,1.0);
glVertex3f(0.1,0.1,0.1);
glEnd ();
glBegin (GL_LINE_LOOP);
glColor3f(1.0,0.0,0.0);
glVertex3f(0.5,0.5,0.5);
glColor3f(0.0,1.0,0.0);
glVertex3f(-0.5,-0.01,-0.2);
glColor3f(0.0,0.0,1.0);
glVertex3f(-0.5,-0.5,-0.5);
glColor3f(1.0,0.0,1.0);
glVertex3f(-0.2,-0.05,-0.03);
glColor3f(0.0,1.0,1.0);
glVertex3f(0.5,0.5,0.5);
glColor3f(1.0,0.0,0.0);
glVertex3f(-0.1,-0.1,-0.1);
glColor3f(0.0,1.0,0.0);
glVertex3f(0.1,0.01,0.2);
glColor3f(0.0,0.0,1.0);
glVertex3f(0.1,0.1,0.1);
glColor3f(1.0,0.0,1.0);
glVertex3f(0.2,0.05,0.03);
glColor3f(0.0,1.0,1.0);
glVertex3f(-0.1,-0.1,-0.1);
glEnd ();
glPopMatrix ();
glPushMatrix ();
gluLookAt (0,0,-1,0,0,0,-0.5,1,0);
glColor3f(1.0,1.0,1.0);
glutWireSphere(0.5,5,5);
glPopMatrix ();
glPushMatrix ();
gluLookAt (0,0,-1,0,0,0,-0.5,1,0);
glBegin (GL_LINE_LOOP);
glColor3f(1.0,0.0,0.0);
glVertex3f(-0.5,-0.5,-0.5);
glColor3f(0.0,1.0,0.0);
glVertex3f(0.5,0.01,0.2);
glColor3f(0.0,0.0,1.0);
glVertex3f(0.5,0.5,0.5);
glColor3f(1.0,0.0,1.0);
glVertex3f(0.2,0.05,0.03);
glColor3f(0.0,1.0,1.0);
glVertex3f(-0.5,-0.5,-0.5);
glColor3f(1.0,0.0,0.0);
glVertex3f(0.1,0.1,0.1);
glColor3f(0.0,1.0,0.0);
glVertex3f(-0.1,-0.01,-0.2);
glColor3f(0.0,0.0,1.0);
glVertex3f(-0.1,-0.1,-0.1);
glColor3f(1.0,0.0,1.0);
glVertex3f(-0.2,-0.05,-0.03);
glColor3f(0.0,1.0,1.0);
glVertex3f(0.1,0.1,0.1);
glEnd ();
glBegin (GL_LINE_LOOP);
glColor3f(1.0,0.0,0.0);
glVertex3f(0.5,0.5,0.5);
glColor3f(0.0,1.0,0.0);
glVertex3f(-0.5,-0.01,-0.2);
glColor3f(0.0,0.0,1.0);
glVertex3f(-0.5,-0.5,-0.5);
glColor3f(1.0,0.0,1.0);
glVertex3f(-0.2,-0.05,-0.03);
glColor3f(0.0,1.0,1.0);
glVertex3f(0.5,0.5,0.5);
glColor3f(1.0,0.0,0.0);
glVertex3f(-0.1,-0.1,-0.1);
glColor3f(0.0,1.0,0.0);
glVertex3f(0.1,0.01,0.2);
glColor3f(0.0,0.0,1.0);
glVertex3f(0.1,0.1,0.1);
glColor3f(1.0,0.0,1.0);
glVertex3f(0.2,0.05,0.03);
glColor3f(0.0,1.0,1.0);
glVertex3f(-0.1,-0.1,-0.1);
glEnd ();
glPopMatrix ();
SwapBuffers (hDC);
}
}
DisableOpenGL (hWnd, hDC, hRC);
DestroyWindow (hWnd);
return msg.wParam;
}
LRESULT CALLBACK WndProc (HWND hWnd, UINT message,
WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_CREATE:
return 0;
case WM_CLOSE:
PostQuitMessage (0);
return 0;
case WM_DESTROY:
return 0;
case WM_KEYDOWN:
switch (wParam)
{
case VK_ESCAPE:
PostQuitMessage(0);
return 0;
}
return 0;
default:
return DefWindowProc (hWnd, message, wParam, lParam);
}
}
void EnableOpenGL (HWND hWnd, HDC *hDC, HGLRC *hRC)
{
PIXELFORMATDESCRIPTOR pfd;
int iFormat;
*hDC = GetDC (hWnd);
ZeroMemory (&pfd, sizeof (pfd));
pfd.nSize = sizeof (pfd);
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_WINDOW |
PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 24;
pfd.cDepthBits = 16;
pfd.iLayerType = PFD_MAIN_PLANE;
iFormat = ChoosePixelFormat (*hDC, &pfd);
SetPixelFormat (*hDC, iFormat, &pfd);
*hRC = wglCreateContext( *hDC );
wglMakeCurrent( *hDC, *hRC );
}
void DisableOpenGL (HWND hWnd, HDC hDC, HGLRC hRC)
{
wglMakeCurrent (NULL, NULL);
wglDeleteContext (hRC);
ReleaseDC (hWnd, hDC);
}
Sources du même auteur
Sources de la même categorie
Commentaires et avis
|
Derniers Blogs
TECHDAYS PARIS 2012 : COMMENT SHAREPOINT A SAUVé MES TECHDAYSTECHDAYS PARIS 2012 : COMMENT SHAREPOINT A SAUVé MES TECHDAYS par ROMELARD Fabrice
Speakers : Lionel Limozin et Alain Marty La session commence par une découverte de SharePoint à travers la mise en place d'un environnement SharePoint pour la gestion des Sessions animées par BeWise. Le besoin est très ba...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice PERSPECTIVE 3.0 POUR SILVERLIGHT 5.0PERSPECTIVE 3.0 POUR SILVERLIGHT 5.0 par odewit
Je viens de publier la version 3.0 de Perspective pour Silverlight, qui regroupe un portage sous Silverlight 5.0 des fonctionnalités de Perspective 2.0, le framework 3D de haut-niveau introduit récemment et de nouveaux exemples de code. En voici la li...
Cliquez pour lire la suite de l'article par odewit TECHDAYS PARIS 2012 : TOP 10 DES BEST PRACTICES POUR SQL SERVERTECHDAYS PARIS 2012 : TOP 10 DES BEST PRACTICES POUR SQL SERVER par ROMELARD Fabrice
Speaker : Nadia Ben El Kadi Configuration machine La session commence par la toute première question à se poser lors de la mise en place d'environnement SQL Server, la configuration des machines : Type de mac...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice TECHDAYS PARIS 2012 : KINECT + OFFICE 365 UN BON GESTE POUR VOTRE SITECHDAYS PARIS 2012 : KINECT + OFFICE 365 UN BON GESTE POUR VOTRE SI par ROMELARD Fabrice
Speakers : Fabrice Barbin, Samuel Blanchard, Julien Lo Presti Titre Prometteur et attractif invitant à voir comment lier le composant ludique Kinect dans le cadre d'une structure IT classique, notamment au travers de la plat...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice TECHDAYS PARIS 2012 : PLEINIèRE DU PREMIER JOURTECHDAYS PARIS 2012 : PLEINIèRE DU PREMIER JOUR par ROMELARD Fabrice
KeyNotes du premier jour pour les développeurs. La session est principalement axée sur une des principales directions prise par Microsoft à travers tous ses nouveaux produits : Cloud privé ou public (Solution Azure) ...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice
Forum
C++ C++ par yesoun1
Cliquez pour lire la suite par yesoun1 OPNETOPNET par hth21
Cliquez pour lire la suite par hth21 RE : ARBRE BINAIRERE : ARBRE BINAIRE par pacotheking
Cliquez pour lire la suite par pacotheking
Logiciels
Academy System (17.2.1.0)ACADEMY SYSTEM (17.2.1.0)Logiciel de gestion des établissements.
- élèves/étudiants (inscription, dossier, absence...)
-... Cliquez pour télécharger Academy System Easy-Planning (1.0.0.1)EASY-PLANNING (1.0.0.1)Basé sur les mêmes principes que MyPlanning, Easy-Planning permet de créer des plannings sous la ... Cliquez pour télécharger Easy-Planning COLLECTOR PLUS (3.00B)COLLECTOR PLUS (3.00B)COLLECTOR PLUS version 3.00B est un logiciel utilisant une base de données alimentée par :
- L... Cliquez pour télécharger COLLECTOR PLUS PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V7.4)PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V7.4)PONAMEDIA TV DEVIENS HELLLOOO FLASH
LA TV SUR VOTRE ORDINATEUR.
Toute une plateforme Multi... Cliquez pour télécharger PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO LettresFaciles 2011 (8.0.0.1)LETTRESFACILES 2011 (8.0.0.1)LettresFaciles est un logiciel facilitant la création et la rédaction de lettres types.
Son inte... Cliquez pour télécharger LettresFaciles 2011
|