begin process at 2012 02 08 09:19:11
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

OpenGL

 > WIN32 COMBINÉ AVEC GLUT...

WIN32 COMBINÉ AVEC GLUT...


 Information sur la source

Note :
Aucune note
Catégorie :OpenGL Niveau :Initié Date de création :27/09/2003 Vu / téléchargé :3 107 / 149

Auteur : Arkain

Ecrire un message privé
Site perso
Commentaire sur cette source (7)
Ajouter un commentaire et/ou une note

 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);
}


 Fichier Zip

Les Membres Club peuvent télécharger directement un fichier contenu dans le zip sans télécharger le zip en entier !
  •   Win32-Glut
    • main.cppTélécharger ce fichier [Réservé aux membres club]Voir ce fichier7 282 octets
    • main.oTélécharger ce fichier [Réservé aux membres club]6 529 octets
    • Makefile.winTélécharger ce fichier [Réservé aux membres club]755 octets
    • Win32-Glut.devTélécharger ce fichier [Réservé aux membres club]866 octets
    • Win32-Glut.exeTélécharger ce fichier [Réservé aux membres club]107 964 octets
    • Win32-Glut.layoutTélécharger ce fichier [Réservé aux membres club]111 octets

Télécharger le zip


 Sources du même auteur

Source avec Zip ARCHITECTURE COMMENTÉ DU PROJET NETAIM (NET ARTIFICIAL INTEL...
Source avec Zip DLL SCIENTIFIQUE, COMPILÉE AVEC VISUAL C++ 6
Source avec Zip UN T'CHAT EN C/C++
Source avec Zip NOUVELLE VERSION DE "JEU DE LUMIÈRE" EN OPENGL
Source avec Zip JEU DE LUMIÈRE AVEC GLUT

 Sources de la même categorie

Source avec Zip Source avec une capture AFFICHER DES COURBES DE BEZIER par shorzy
Source avec Zip Source avec une capture BASE/MOTEUR 3D EN QT/OPENGL (COMPLET ET FONCTIONNEL!) POUR U... par envi33
Source avec Zip Source avec une capture CLASSE AVEC OPENGL - OBJETS 3D ET ANIMATIONS par rasta63
Source avec Zip Source avec une capture LETTRES 3D AVEC OPENGL ET QT par opossum_farceur
Source avec Zip CUBE 3D GLUT32 VC++ ET DEVC++ par bobby03

Commentaires et avis

Commentaire de DHUCH le 28/09/2003 13:40:12

Bonjour,

A quoi sert votre système ?

Merçi de votre réponse.

Daniel HUCHETTE

Commentaire de Arkain le 28/09/2003 14:33:04

heu....bin a rien, juste a combiner glut et l'api win32.

Et a faire zoli lol^^ :)

Commentaire de Kirua le 03/10/2003 19:16:57

je ne comprends pas très bien quel avantage tu en tires.
glut = portable, win32 = pas portable. le seul avantage de glut étant d'ailleurs sa portabilité, puisque désormais plus suivi (depuis 1997 quand même)
comprends pas, tu m'expliques? parce que par exemple, la gestion clavier sous glut est pu*nte! mais sous windows elle rocks :-)

Commentaire de Arkain le 04/10/2003 18:34:03

arf kirua, j'ai fait ça juste pour voir si c'était compatible, rien d'autre...

Commentaire de Kirua le 04/10/2003 18:45:36

ah ok, un esprit expérimental, j'aime :-D

Commentaire de Arkain le 05/10/2003 22:20:13

lol^^

Commentaire de beg0 le 07/06/2006 18:38:28

j'avoue que je vois pas trop l'utilitée de glut, a part   glutWireSphere() tu utilise pas grand chose de glut, donc je trouve le titre un peu trompeur, mais sinon c'est un bon code d'exemple pour commencer a se familiariser avec ogl sous windows ;)

 Ajouter un commentaire




Nos sponsors


Sondage...

Comparez les prix

CalendriCode

Février 2012
LMMJVSD
  12345
6789101112
13141516171819
20212223242526
272829    

Consulter la suite du CalendriCode

Photothèque

 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 2,262 sec (3)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales