VC++-OpenGL | Programm versteckt sich



  • Hi Leute,
    hab da mal WIEDER ein kleines Problem. Und zwar, immer wenn ich mein Programm compilen möchte, klappt eigentlich alles wunderbar. Er compilet auch schon und debuggt. Es wird auch abgefragt ob ich im Vollbild Modus oder im Fenster starten möchte, nachdem ich jetzt aber eines der beiden ausgewählt hab, verschwindet die MessageBox und nichts passiert. Egal bei welcher Auswahl.
    Das Programm lässt sich danach dann logischer Weise nicht mehr compilen und versteckt sich im Task-Prozesse Menü, aber nicht im einfachen Task-laufende Programme Menü.
    Woran kann das liegen ? Meiner Meinung nach hab ich alles richtig gesetzt und resettet.
    Währe sehr dankbar wenn mir einer helfen könnte !
    Wenn's hilft, hier der Code :

    Definition.h :
    
    #include <windows.h>
    #include <gl\gl.h>
    #include <gl\glu.h>
    #include <gl\glaux.h>
    
    HDC hDC=NULL;
    HGLRC hRC=NULL;
    HWND hWnd=NULL;
    HINSTANCE hInstance;
    
    bool keys[256];
    bool fullscreen=TRUE;
    bool active=TRUE;
    
    Main.cpp :
    
    #include "Definition.h"
    
    LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
    
    GLvoid ReSizeGLScene (GLsizei width,GLsizei height)
    {
    	if(height==0)
    	{
    		height=1;
    	}
    
    	glViewport(0,0,width,height);
    	glLoadIdentity();
    	glMatrixMode(GL_PROJECTION);
    
    	gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);
    
    	glMatrixMode(GL_MODELVIEW);
    	glLoadIdentity();
    
    }
    
    int InitGL(GLvoid)
    {
    	glShadeModel(GL_SMOOTH);
    	glClearColor(0.0f,0.0f,0.0f,0.0f);
    	glClearDepth(1.0f);
    	glEnable(GL_DEPTH_TEST);
    	glDepthFunc(GL_LEQUAL);
    
    	glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST);
    
    	return TRUE;
    }
    
    ///////////////////////////////////////////
    ////   Rendering-Context               ////
    ///////////////////////////////////////////
    
    int DrawGLScene(GLvoid)
    {
    
    	glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
    	glLoadIdentity();
    
    	return TRUE;
    }
    
    GLvoid KillGLWindow(GLvoid)
    {
    	if(fullscreen)
    	{
    		ChangeDisplaySettings(NULL,0);
    		ShowCursor(TRUE);
    	}
    }
    
    BOOL CreateGLWindow(char *Fenstertitel,int width,int height,int bits,bool fullscreenflag)
    {
    
    GLuint PixelFormat;
    WNDCLASS wc;
    DWORD dwExStyle;
    DWORD dwStyle;
    RECT WindowRect;
    WindowRect.left=(long)0;
    WindowRect.right=(long)width;
    WindowRect.top=(long)0;
    WindowRect.bottom=(long)height;
    
    fullscreenflag=fullscreen;
    
    hInstance=GetModuleHandle(NULL);
    wc.hInstance=hInstance;
    wc.style=CS_VREDRAW | CS_HREDRAW | CS_OWNDC;
    wc.lpfnWndProc=(WNDPROC) WndProc;
    wc.lpszMenuName=NULL;
    wc.lpszClassName="OpenGL";
    wc.hbrBackground=NULL;
    wc.cbClsExtra=0;
    wc.cbWndExtra=0;
    wc.hIcon=LoadIcon(NULL,IDI_WINLOGO);
    wc.hCursor=LoadCursor(NULL,IDC_ARROW);
    
    if(!RegisterClass(&wc))
    {
    MessageBox(NULL,"Konnte die Registerklassen nicht registrieren !","Fehler",MB_OK);
    return FALSE;
    }
    
    if(fullscreen)
    {
    DEVMODE dmScreenSettings;
    dmScreenSettings.dmPelsWidth=width;
    dmScreenSettings.dmPelsHeight=height;
    dmScreenSettings.dmBitsPerPel=bits;
    dmScreenSettings.dmFields=DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL;
    }
    
    if(fullscreen)
    {
    dwExStyle=WS_EX_APPWINDOW; 
    dwStyle=WS_POPUP;
    }
    else
    {
    dwExStyle=WS_EX_WINDOWEDGE  | WS_EX_APPWINDOW;
    dwStyle=WS_OVERLAPPEDWINDOW;
    }
    
    AdjustWindowRectEx(&WindowRect,dwStyle,FALSE,dwExStyle);
    
    if(!(hWnd=CreateWindowEx(
    dwExStyle,
    "OpenGL",
    Fenstertitel,
    WS_CLIPSIBLINGS |
    WS_CLIPCHILDREN |
    dwStyle,
    0,0,
    WindowRect.right-WindowRect.left,
    WindowRect.bottom-WindowRect.top,
    NULL,
    NULL,
    hInstance,
    NULL)))
    
    {
    KillGLWindow();
    MessageBox(NULL,"Konnte das Fenster nicht erstellen !","Fehler",MB_OK);
    return FALSE;
    }
    
    static PIXELFORMATDESCRIPTOR pfd=
    {
    sizeof(PIXELFORMATDESCRIPTOR),
    1,
    PFD_DRAW_TO_WINDOW |
    PFD_SUPPORT_OPENGL |
    PFD_DOUBLEBUFFER,
    PFD_TYPE_RGBA,
    bits,
    0,0,0,0,0,0,
    0,
    0,
    0,
    0,0,0,0,
    16,
    0,
    0,
    0,0,0
    };
    
    if(!(hDC=GetDC(hWnd)))
    {
    KillGLWindow();
    return FALSE;
    }
    
    if(!(PixelFormat=ChoosePixelFormat(hDC,&pfd)))
    {
    KillGLWindow();
    return 0;
    }
    
    if(!SetPixelFormat(hDC,PixelFormat,&pfd))
    {
    KillGLWindow();
    return FALSE;
    }
    
    if(!(hRC=wglCreateContext(hDC)))
    {
    KillGLWindow();
    return FALSE;
    }
    
    if(!wglMakeCurrent(hDC,hRC))
    {
    KillGLWindow();
    return FALSE;
    }
    
    ShowWindow(hWnd,SW_SHOW);
    SetForegroundWindow(hWnd);
    SetFocus(hWnd);
    ReSizeGLScene(width,height);
    
    if(!InitGL())
    {
    KillGLWindow();
    MessageBox(NULL,"Initialisierung ist fehlgeshclagen !","Fehler",MB_OK);
    return FALSE;
    }
    
    return TRUE;
    }
    
    LRESULT CALLBACK WndProc(HWND hWnd,UINT message,WPARAM wParam,LPARAM lParam)
    {
    switch(message)
    {
    
    case WM_ACTIVATE:
    {
    if(!HIWORD(wParam))
    {
    active=TRUE;
    }
    else
    {
    active=FALSE;
    }
    return 0;
    }
    
    case WM_SYSCOMMAND:
    {
    switch(wParam)
    {
     case SC_SCREENSAVE:
    case SC_MONITORPOWER:
    return 0;
    }
    return 0;
    }
    
    case WM_QUIT:
    {
    
    PostQuitMessage(0);
    return 0;
    }
    
    case WM_KEYDOWN:
         {
                    keys[wParam]=TRUE;
                    return 0;
                    }
    
    case WM_KEYUP:
         {
                       keys[wParam]=TRUE;
                       return 0;
                       }
    
    case WM_SIZE:
    {
    ReSizeGLScene(LOWORD(lParam),HIWORD(lParam));
    return 0;
    }
    
    }
    return DefWindowProc(hWnd,message,wParam,lParam);
    }
    
    int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR szCmdLine,int CmdShow)
    {
    
    MSG msg;
    bool done=FALSE;
    
    if(MessageBox(NULL,"Möchten sie im Vollbild Modus starten?","Start Fullscreen?",MB_YESNOCANCEL | MB_ICONQUESTION)==IDYES)
    {
    	fullscreen=TRUE;
    }
    else
    {
    	fullscreen=FALSE;
    }
    
    while(!done)
    {
    if(PeekMessage(&msg,NULL,0,0,PM_REMOVE))
    {
    if(msg.message==WM_QUIT)
    {
    done=TRUE;
    }
    else
    {
    TranslateMessage(&msg);
    DispatchMessage(&msg);
    }
    }
    
    else
    {
    if(active)
    {
    if(keys[VK_ESCAPE])
    {
    done=TRUE;
    }
    else
    {
    DrawGLScene();
    SwapBuffers(hDC);
    }
    }
    }
    }
    
    KillGLWindow();
    return(msg.wParam);
    }
    

    Wie gesagt, wäre sehr dankbar für Hilfe !



  • Diese funktion CreateGLWindow muss du schon aufrufen,
    sonst passirt rein garnichts. 😉



  • Du bist ein Schatz !!!!!!!!!!
    Ich dachte erst es sei unnütz es zu erstellen da ich es nur als Fenster haben wollte, aber ich ja klar man braucht ja überhaupt eine Funktion die das Fenster erstellt und ihr einen namen sowie PixelFormat gibt !
    Danke schöööön!


Anmelden zum Antworten