IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

OpenGL Discussion :

[debutant]ogl+windows.h compile ss erreurs mais marche pas


Sujet :

OpenGL

  1. #1
    Membre confirmé
    Avatar de heinquoi
    Homme Profil pro
    Consultant informatique
    Inscrit en
    Octobre 2003
    Messages
    85
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 53
    Localisation : Luxembourg

    Informations professionnelles :
    Activité : Consultant informatique

    Informations forums :
    Inscription : Octobre 2003
    Messages : 85
    Points : 491
    Points
    491
    Par défaut [debutant]ogl+windows.h compile ss erreurs mais marche pas
    Bjr,

    Je me suis remis à ogl, j'en avait pas fait depuis 5 ans.

    donc je reprends les bases:
    je fait une application win32 avec windows.h ( fenetre, menu)
    je compile & test: OK

    puis je rajoute les fonctions specifiques pour OGL.
    là, compilation OK, lais quand je lance, l'applis, pas de fenetre, rien.
    je lance un debug et constate que CreateWindows (...) refuse de me sortir un HWND valide.
    J'ai bidouller, permuté, les parametres, j'ai aussi brouté tout le web avec google rien sur mon pb ( à moins que ce soit en anglais, la y a des sites ou j'ai pas tout percuté ...)

    Cela dit je crois me souvenir, que OGL ne fonctionne pas avec tout les types de fenetre... Pourriez m'aider les gars !! s v p
    (le dieu processor vous le rendra )

  2. #2
    Membre éclairé
    Avatar de Edouard Kaiser
    Profil pro
    Inscrit en
    Février 2004
    Messages
    521
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Février 2004
    Messages : 521
    Points : 756
    Points
    756
    Par défaut
    Donne ton code et on va essayer de t'aider

  3. #3
    Membre confirmé
    Avatar de heinquoi
    Homme Profil pro
    Consultant informatique
    Inscrit en
    Octobre 2003
    Messages
    85
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 53
    Localisation : Luxembourg

    Informations professionnelles :
    Activité : Consultant informatique

    Informations forums :
    Inscription : Octobre 2003
    Messages : 85
    Points : 491
    Points
    491
    Par défaut voici le code
    voici le code mais c'est juste une pllication faite par wizzard auqu'elle j'ajoute les fonctions OGL

    // WIN_HELLO2.cpp : Defines the entry point for the application.
    //

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

    #include "resource.h"
    #define WIN32_LEAN_AND_MEAN


    #define MAX_LOADSTRING 100

    // Global Variables:
    HINSTANCE hInst; // current instance
    TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
    TCHAR szWindowClass[MAX_LOADSTRING]; // The title bar text

    // variable Global OPEN GL
    HDC DC;
    HGLRC RC;

    // Foward declarations of functions included in this code module:
    ATOM MyRegisterClass(HINSTANCE hInstance);
    BOOL InitInstance(HINSTANCE, int);
    LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
    LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM);

    // fonctions OPEN GL
    void Reshape (int width, int height );
    void InitGL ();
    void Draw ();
    void SetupPixelFormat (HDC hDC);

    int APIENTRY WinMain(HINSTANCE hInstance,
    HINSTANCE hPrevInstance,
    LPSTR lpCmdLine,
    int nCmdShow)
    {
    // TODO: Place code here.
    MSG msg;
    HACCEL hAccelTable;

    // Initialize global strings
    LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
    LoadString(hInstance, IDC_WIN_HELLO2, szWindowClass, MAX_LOADSTRING);
    MyRegisterClass(hInstance);

    // Perform application initialization:
    if (!InitInstance (hInstance, nCmdShow))
    {
    return FALSE;
    }

    hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_WIN_HELLO2);

    // Main message loop:
    while (GetMessage(&msg, NULL, 0, 0))
    {
    if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
    {
    TranslateMessage(&msg);
    DispatchMessage(&msg);
    }
    }

    return msg.wParam;
    }



    //
    // FUNCTION: MyRegisterClass()
    //
    // PURPOSE: Registers the window class.
    //
    // COMMENTS:
    //
    // This function and its usage is only necessary if you want this code
    // to be compatible with Win32 systems prior to the 'RegisterClassEx'
    // function that was added to Windows 95. It is important to call this function
    // so that the application will get 'well formed' small icons associated
    // with it.
    //
    ATOM MyRegisterClass(HINSTANCE hInstance)
    {
    WNDCLASSEX wcex;

    wcex.cbSize = sizeof(WNDCLASSEX);

    wcex.style = CS_OWNDC;
    wcex.lpfnWndProc = (WNDPROC)WndProc;
    wcex.cbClsExtra = 0;
    wcex.cbWndExtra = 0;
    wcex.hInstance = hInstance;
    wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_WIN_HELLO2);
    wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
    wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
    wcex.lpszMenuName = (LPCSTR)IDC_WIN_HELLO2;
    wcex.lpszClassName = szWindowClass;
    wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);

    return RegisterClassEx(&wcex);
    }

    //
    // FUNCTION: InitInstance(HANDLE, int)
    //
    // PURPOSE: Saves instance handle and creates main window
    //
    // COMMENTS:
    //
    // In this function, we save the instance handle in a global variable and
    // create and display the main program window.
    //
    BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
    {
    HWND hWnd=NULL;

    hInst = hInstance; // Store instance handle in our global variable

    hWnd = CreateWindow(szWindowClass, szTitle,WS_CLIPCHILDREN |WS_CLIPSIBLINGS,
    CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);

    if (!hWnd)
    {
    return FALSE;
    }

    ShowWindow(hWnd, nCmdShow);
    UpdateWindow(hWnd);

    return TRUE;
    }

    //
    // FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
    //
    // PURPOSE: Processes messages for the main window.
    //
    // WM_COMMAND - process the application menu
    // WM_PAINT - Paint the main window
    // WM_DESTROY - post a quit message and return
    //
    //
    LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
    int wmId, wmEvent;
    PAINTSTRUCT ps;
    HDC hdc;
    TCHAR szHello[MAX_LOADSTRING];
    LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING);

    switch (message)
    {
    case WM_COMMAND:
    wmId = LOWORD(wParam);
    wmEvent = HIWORD(wParam);
    // Parse the menu selections:
    switch (wmId)
    {
    case IDM_ABOUT:
    DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
    break;
    case IDM_EXIT:
    DestroyWindow(hWnd);
    break;
    default:
    return DefWindowProc(hWnd, message, wParam, lParam);
    }
    break;

    case WM_DESTROY:
    wglMakeCurrent (NULL,NULL);
    if (RC) wglDeleteContext (RC);
    ReleaseDC(hWnd, DC);
    PostQuitMessage(0);
    break;

    case WM_CREATE:
    DC=GetDC(hWnd);
    SetupPixelFormat (DC);
    if (!RC) SendMessage (hWnd, WM_CLOSE, 0, 0);
    wglMakeCurrent(DC, RC);
    InitGL();
    break;

    case WM_SIZE:
    ::Reshape(LOWORD(lParam),HIWORD(lParam));
    break;

    case WM_PAINT:
    Draw();
    break;

    default:
    return DefWindowProc(hWnd, message, wParam, lParam);
    }
    return 0;
    }

    // Mesage handler for about box.
    LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
    {
    switch (message)
    {
    case WM_INITDIALOG:
    return TRUE;

    case WM_COMMAND:
    if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
    {
    EndDialog(hDlg, LOWORD(wParam));
    return TRUE;
    }
    break;
    }
    return FALSE;
    }


    //////////////////////////////////////////////////////////////////
    //
    // FONCTION OPEN GL
    //

    void Draw()
    {
    ::glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    ::glMatrixMode (GL_MODELVIEW);
    ::glLoadIdentity();
    ::gluLookAt (0,0,-10,0,0,0,0,1,0);
    ::glBegin(GL_QUADS);
    ::glVertex2i(-1,-1);
    ::glVertex2i(1,-1);
    ::glVertex2i(1,1);
    ::glVertex2i(-1,1);
    ::glEnd();
    ::SwapBuffers (::DC);
    }

    void Reshape (int width, int height)
    {
    ::glViewport(0,0,width, height);
    ::glMatrixMode(GL_PROJECTION);
    ::glLoadIdentity();
    ::gluPerspective(45., float (width)/float(height),0, 100);
    }

    void InitGL()
    {
    }

    void SetupPixelFormat (HDC hDC)
    {
    PIXELFORMATDESCRIPTOR pfd={
    sizeof (PIXELFORMATDESCRIPTOR),
    1,
    PFD_SUPPORT_OPENGL|PFD_DRAW_TO_WINDOW|PFD_DOUBLEBUFFER,
    PFD_TYPE_RGBA,
    16,
    0,0,0,0,0,0,
    0,0,
    0,0,0,0,0,
    32,
    0,
    0,
    0,
    0,
    0,
    0,
    0
    };

    int pixelFormat = ::ChoosePixelFormat(hDC, &pfd);
    if (!pixelFormat)
    {
    ::MessageBox(WindowFromDC(hDC), "Mode graphique non supporté par \
    le driver.","Problème",
    MB_ICONERROR|MB_OK);
    exit(1);
    }

    if (!SetPixelFormat(hDC, pixelFormat, &pfd))
    {
    MessageBox(WindowFromDC(hDC), "Mode graphique non supporté par le driver.","Problème", MB_ICONERROR|MB_OK);
    exit(1);
    }
    }



  4. #4
    Membre actif
    Inscrit en
    Avril 2004
    Messages
    238
    Détails du profil
    Informations forums :
    Inscription : Avril 2004
    Messages : 238
    Points : 265
    Points
    265
    Par défaut
    Essaye d'aller voir la pour creer ton appli :
    http://progzone.free.fr/graphisme/opengl/OpenGLII/OpenGLII.htm

    Ya le code pour windows.h bien expliqué, ca pourra peut etre t'aider.

  5. #5
    Membre confirmé
    Avatar de heinquoi
    Homme Profil pro
    Consultant informatique
    Inscrit en
    Octobre 2003
    Messages
    85
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 53
    Localisation : Luxembourg

    Informations professionnelles :
    Activité : Consultant informatique

    Informations forums :
    Inscription : Octobre 2003
    Messages : 85
    Points : 491
    Points
    491
    Par défaut ouai, c'est resolu
    c'est resolu,
    merci pour l'aide, le pb venait de ma fonction CALLBACK WndProc qui n'utilisait pas correctement contextes de périph HDC.

Discussions similaires

  1. Réponses: 1
    Dernier message: 14/05/2015, 08h33
  2. Réponses: 3
    Dernier message: 28/01/2010, 13h54
  3. Réponses: 1
    Dernier message: 09/04/2009, 09h45
  4. Réponses: 7
    Dernier message: 27/06/2007, 23h32
  5. [Debutant][API Windows] Erreur sur SelectObject
    Par coolmaxou dans le forum Windows
    Réponses: 2
    Dernier message: 13/07/2005, 08h06

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo