begin process at 2012 05 30 00:14:00
  Trouver un code source :
 
dans
 
Accueil > Forum > 

C

 > 

Linux

 > 

OpenGL

 > 

Open Gl pépin


Derniers messages déposésPoser une question dans le forum ou lancer une discussion

Open Gl pépin

samedi 22 mars 2008 à 14:40:12 | Open Gl pépin

DarkNavius

Chères personnes lisant mon message d'appel à l'aide.
J'ai besoin d'aide au sujet d'un programme en opengl que j'ai construit en copiant et collant quelques bouts de codes venant de droite à gauche. Malheureusement le code ne marche point: le compilateur compile mais la fenetre ouverte est noire.

J'aimerais l'aide de quelqu'un qui s'y connais un peu pour corriger le bug.
Voici mon code source: attention il est long
Merci d'avance à qui compte m'aidera.


#include <math.h>
#include <stdlib.h>
#include <windows.h>
#include <gl/gl.h>
#include <gl/glu.h>

void EnableOpenGL  (HWND hwnd, HDC *hDC, HGLRC *hRC);
void DisableOpenGL (HWND hwnd, HDC *hDC, HGLRC* hRC);
void RePaint       (HWND hwnd);


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);
BOOL Resolution          ();


void RePaint (HWND hwnd)
{
     glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glMatrixMode (GL_MODELVIEW);
    glLoadIdentity ();

    gluLookAt (7,7,-10,0,0,0,0,1,0);

    glEnable(GL_DEPTH_TEST);

    glBegin (GL_QUADS);
        glColor3d (0,1,1);glVertex3i (-1,-1,1);
        glColor3d (1,0,0);glVertex3i (-1,1,1);
        glColor3d (0,1,0);glVertex3i (1,1,1);
        glColor3d (1,0,1);glVertex3i (1,-1,1);

        glColor3d (0,0,1);glVertex3i (-1,-1,-1);
        glColor3d (1,1,0);glVertex3i (-1,1,-1);
        glColor3d (1,1,1);glVertex3i (1,1,-1);
        glColor3d (.5,.5,.5);glVertex3i (1,-1,-1);

        glColor3d (1,1,0);glVertex3i (-1,1,-1);
        glColor3d (1,1,1);glVertex3i (1,1,-1);
        glColor3d (0,1,0);glVertex3i (1,1,1);
        glColor3d (1,0,0);glVertex3i (-1,1,1);

        glColor3d (0,0,1);glVertex3i (-1,-1,-1);
        glColor3d (.5,.5,.5);glVertex3i (1,-1,-1);
        glColor3d (1,0,1);glVertex3i (1,-1,1);
        glColor3d (0,1,1);glVertex3i (-1,-1,1);

        glColor3d (0,0,1);glVertex3i (-1,-1,-1);
        glColor3d (0,1,1);glVertex3i (-1,-1,1);
        glColor3d (1,0,0);glVertex3i (-1,1,1);
        glColor3d (1,1,0);glVertex3i (-1,1,-1);

        glColor3d (.5,.5,.5);glVertex3i (1,-1,-1);
        glColor3d (1,0,1);glVertex3i (1,-1,1);
        glColor3d (0,1,0);glVertex3i (1,1,1);
        glColor3d (1,1,1);glVertex3i (1,1,-1);
    glEnd();

    glBegin (GL_QUADS);
    glColor3d (1,0,0);
        glVertex3i (-6,-1,1);
        glVertex3i (-6,1,1);
        glVertex3i (-4,1,1);
        glVertex3i (-4,-1,1);
    glColor3d (0,1,0);
        glVertex3i (-6,-1,-1);
        glVertex3i (-6,1,-1);
        glVertex3i (-4,1,-1);
        glVertex3i (-4,-1,-1);
    glColor3d (1,1,0);
        glVertex3i (-6,1,-1);
        glVertex3i (-4,1,-1);
        glVertex3i (-4,1,1);
        glVertex3i (-6,1,1);
    glColor3d (0,0,0);
        glVertex3i (-6,-1,-1);
        glVertex3i (-4,-1,-1);
        glVertex3i (-4,-1,1);
        glVertex3i (-6,-1,1);
    glColor3d (0,1,1);
        glVertex3i (-6,-1,-1);
        glVertex3i (-6,-1,1);
        glVertex3i (-6,1,1);
        glVertex3i (-6,1,-1);
    glColor3d (1,0,1);
        glVertex3i (-4,-1,-1);
        glVertex3i (-4,-1,1);
        glVertex3i (-4,1,1);
        glVertex3i (-4,1,-1);
    glEnd();

    glDisable(GL_DEPTH_TEST);

    glBegin (GL_QUADS);
        glColor3d (0,1,1);glVertex3i (4,-1,1);
        glColor3d (1,0,0);glVertex3i (4,1,1);
        glColor3d (0,1,0);glVertex3i (6,1,1);
        glColor3d (1,0,1);glVertex3i (6,-1,1);

        glColor3d (0,0,1);glVertex3i (4,-1,-1);
        glColor3d (1,1,0);glVertex3i (4,1,-1);
        glColor3d (1,1,1);glVertex3i (6,1,-1);
        glColor3d (.5,.5,.5);glVertex3i (6,-1,-1);

        glColor3d (1,1,0);glVertex3i (4,1,-1);
        glColor3d (1,1,1);glVertex3i (6,1,-1);
        glColor3d (0,1,0);glVertex3i (6,1,1);
        glColor3d (1,0,0);glVertex3i (4,1,1);

        glColor3d (0,0,1);glVertex3i (4,-1,-1);
        glColor3d (.5,.5,.5);glVertex3i (6,-1,-1);
        glColor3d (1,0,1);glVertex3i (6,-1,1);
        glColor3d (0,1,1);glVertex3i (4,-1,1);

        glColor3d (0,0,1);glVertex3i (4,-1,-1);
        glColor3d (0,1,1);glVertex3i (4,-1,1);
        glColor3d (1,0,0);glVertex3i (4,1,1);
        glColor3d (1,1,0);glVertex3i (4,1,-1);

        glColor3d (.5,.5,.5);glVertex3i (6,-1,-1);
        glColor3d (1,0,1);glVertex3i (6,-1,1);
        glColor3d (0,1,0);glVertex3i (6,1,1);
        glColor3d (1,1,1);glVertex3i (6,1,-1);
    glEnd();

    //SwapBuffers (DC);
    SwapBuffers (GetDC (hwnd));
}

/////////////////////Lancement et destruction de OpenGl/////////////////////////
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;
   
    SetPixelFormat (*hDC, ChoosePixelFormat (*hDC, &pfd), &pfd);

    *hRC = wglCreateContext(*hDC);
    wglMakeCurrent(*hDC, *hRC);

}
void DisableOpenGL (HWND hwnd, HDC *hDC, HGLRC *hRC)
{
    wglMakeCurrent (NULL, NULL);
    wglDeleteContext (*hRC);
    ReleaseDC (hwnd, *hDC);
}
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
HINSTANCE hInst;
int WINAPI WinMain (HINSTANCE hInstance,
                    HINSTANCE hPrevInstance,
                    LPSTR lpCmdLine,
                    int iCmdShow)
{
    if(Resolution()==FALSE)
    {
         return 1;                     
    }
////////////Définition des variables paramétrant la fenêtre Windows////////////
    WNDCLASS wc;
    HWND     hwnd;
    HDC      hDC;
    HGLRC    hRC;       
    MSG      msg;
    RECT     rc;
   
    BOOL bQuit = FALSE;
    hInst      = hInstance;
/////////////////////////////////////////////////////////////////////////////// 
///////////////////////////////////////////////////////////////////////////////   


////////////////////Attribution des paramètres de base/////////////////////////
    wc.style         = CS_OWNDC;
    wc.lpfnWndProc   = WndProc;
    wc.cbClsExtra    = 0;
    wc.cbWndExtra    = 0;
    wc.hInstance     = hInst;
    wc.hIcon         = LoadIcon (NULL, IDI_APPLICATION);
    wc.hCursor       = LoadCursor (NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH) GetStockObject (LTGRAY_BRUSH);
    wc.lpszMenuName  = NULL;
    wc.lpszClassName = NOMSYTEME;
    RegisterClass (&wc);
   
    hwnd = CreateWindow (NOMSYTEME, NOMSYTEME,
                         WS_BORDER      | WS_MINIMIZEBOX | WS_CAPTION |
                         WS_POPUPWINDOW | WS_VISIBLE,
                         POSITION_X, POSITION_Y,
                         TAILLE_X,   TAILLE_Y,
                         NULL, NULL, hInst, NULL);

   
   
    EnableOpenGL (hwnd, &hDC, &hRC);
/////////////////////////////////////////////////////////////////////////////// 
///////////////////////////////////////////////////////////////////////////////   

///Cette fonction s'assure que l'on ait bien la fenêtre de Windows visible/////
    ShowWindow(hwnd, SW_NORMAL);
//////////////////////////////Boucle du processus//////////////////////////////
    while (!bQuit)
    {
        if (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE))
        {
            if (msg.message == WM_QUIT)
            {
                bQuit = TRUE;
            }
            else
            {
                TranslateMessage (&msg);
                DispatchMessage (&msg);
            }
        }
        else
        {
///////////La fonction servant à dessiner sur la fenêtre est appellé///////////
             RePaint(hwnd);
        }
    }
/////////////////////////////////////////////////////////////////////////////// 
///////////////////////////////////////////////////////////////////////////////   



//////////////////Gestion de la fermeture du programme//////////////////////////  
    DisableOpenGL (hwnd, &hDC, &hRC);
    DestroyWindow (hwnd);
/////////////////////////////////////////////////////////////////////////////// 
///////////////////////////////////////////////////////////////////////////////   
    return msg.wParam;
}



/////////////////Gestion des messages internes//////////////////////////////////
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_PAINT:
        RePaint (hwnd);
    case WM_DESTROY:
        return 0;

//////////////////////Gestion du clavier de l'ordinateur////////////////////////
    case WM_KEYDOWN:
        switch (wParam)
        {
        case VK_ESCAPE:
            PostQuitMessage(0);
            return 0;
        case VK_SPACE:
        
            break;
        case VK_DOWN:
            break;
        case VK_UP:
            break;
        case VK_SUBTRACT:
            break;
        case VK_ADD:
            break;
        case VK_LEFT:
            break;
        case VK_RIGHT:
            break;
        case VK_F5:
            break;
        case VK_F6:
            break;
        case VK_F7:
            break;
        case VK_F8:
            break;
        }
        break;   
   
//////////////////////////////Gestion de la souris/////////////////////////////
    case WM_MOUSEMOVE:
           
        if(wParam & MK_LBUTTON)
        {
              
        }
        break;   
   
///////////////////////////////////////////////////////////////////////////////   
    case WM_SIZE:
        glViewport (0,0,LOWORD (lParam),HIWORD (lParam));
        glMatrixMode (GL_PROJECTION);
        glLoadIdentity ();
        gluPerspective (45,(float)(LOWORD(lParam))/(float)(HIWORD(lParam)),1,100);
       
        break;
      
        return 0;
    default:
        return DefWindowProc (hwnd, message, wParam, lParam);
    }
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////

//////Cette fonction s'assure que les paramètres de résolution sont corrects////
BOOL Resolution()
{    
     if(GetSystemMetrics(SM_CYSCREEN)!=RESOLUTION_Y)
     {
          MessageBox(NULL, TEXT("Impossible de lancer l'application.\n"
                                "Les paramètres de résolution de l'écran ou "
                                "de l'ordinateur ne sont pas compatibles\n\n"
                                "Résolution adéquate: 1280*800"),
          TEXT("Erreur de résolution"), MB_OK | MB_ICONERROR);
          return FALSE;
     }
     if(GetSystemMetrics(SM_CXSCREEN)!=RESOLUTION_X)
     {
          MessageBox(NULL, TEXT("Impossible de lancer l'application.\n"
                                "Les paramètres de résolution de l'écran ou "
                                "de l'ordinateur ne sont pas compatibles\n\n"
                                "Résolution adéquate: 1280*800"),
          TEXT("Erreur de résolution"), MB_OK | MB_ICONERROR);
          return FALSE;
     }
     return TRUE;
}




DarkNavius

samedi 22 mars 2008 à 17:36:50 | Re : Open Gl pépin

luhtor

Et si tu mets ca, t'as une fenetre rouge ?

void RePaint (HWND hwnd)
{
    glClearColor(1.0f, 0.0f, 0.0f, 1.0);
     glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glMatrixMode (GL_MODELVIEW);
    glLoadIdentity ();
...
samedi 22 mars 2008 à 17:43:18 | Re : Open Gl pépin

DarkNavius

Oui luhtor

DarkNavius

mardi 25 mars 2008 à 17:56:49 | Re : Open Gl pépin

luhtor

dans ce cas, c'est simplement un problème de paramétrage de matrice (de ta caméra).


Cette discussion est classée dans : case, hwnd, hdc, glvertex3i, glcolor3d


Répondre à ce message

Sujets en rapport avec ce message

Screenmate defectueux [ par anthraxx ] Anthrax ignisque -- Le charbon et le feu J'essaye de faire un screenmate (une petite bestiole se promenant sur les fenetres), mais n'etant pas tres ex comment recuperer des données chiffrées contenues dans une editbox ? [ par pidoumtimo ] Bonjour a tous.Je suis actuellement sur un pgm permettant de faire des calcul a partir de donnée insérées par un utilisateur sous forme de chiffres da Un bouton imagé [ par victorcoasne ] Comment faire pour que sur un bouton apparaisse l'image ?J'ai trouvé comment faire apparaître une image : void PrintBmp(HWND hWnd, char *filename, i OpenGL dans une fenetre Win32 ou SDL [ par Dante41 ] Alors , je voulais afficher un cube dans ma fenetre donc voila mon code : #include #include #include #include #include #include WNDCLASS dessiner dans une zone Picture [ par pidoumtimo ] Bonjour a tous.Je possede deux tableau de valeurs et j'aimerai tracer la courbe issue de ces deux tableau dans une zone Picture.Malheureusement mon co problème avec bitblt [ par gregory6 ] GringoBonjour,je suis développeur débutant sous visual C++ et les MFC. Je cherche à afficher le contenu d'un répertoire sur une page graphique que je Affichage bitmap [ par gregory6 ] GringoBonjour, je suis débutant ss visual C++ et j'aurai besoin d'un peu d'aide. Je crée un projet MFC ds lequel je crée une fenetre. Cette fenetre cr Couleur de fenêtre [ par CyberP ] Comment changer la couleur d'arrière plan d'une fenêtre après l'avoir créée ?PAINTSTRUCT pps;HDC hdc;hdc = BeginPaint(hWnd, &pps);SelectObject(hdc, Cr envoyer un msg a un tab control pour changer de tab [ par youpiyoyo ] bon j'aimerais changer la current tab de mon tab controlj'ai cacase WM_NOTIFY:{ switch((int)wParam) { case IDC_TAB_ICO: //m HELP!! comment rafraichir [ par kuruma ] LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam){   static string chemin;  static int count=0;  static bool se


Nos sponsors


Sondage...

CalendriCode

Mai 2012
LMMJVSD
 123456
78910111213
14151617181920
21222324252627
28293031   

Consulter la suite du CalendriCode

A découvrir



 
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 : 0,546 sec (3)

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