Skip to main content
gamedev.net
🔒 Locked

Dialog box

Started by SKSlayer Sep 20, 2000 at 8:07 AM 41 replies 2.4k views
Original Post
SKSlayer
SKSlayer
Okay, I already asked this question but, I never had any understandable answer (sorry for the one who answered ) I an coding in pure Win32 AND I am using a dialog box I made with the Ressource editor (so the dialog box is a resource). It have its own call back and stuff. Let''s say I want to make a level editor or some stuff like that, I made my controls and all the stuff, BUT (there is always a but) I want some part of my window to be an OpenGL scene. How can I do that ? Does anyone have a sample ? Can anyone explain in an understandable way () ?
(you can find me on IRC : #opengl on undernet)
baskuenen
baskuenen
If you want OpenGL on your dialogbox, you need to do the following:
  • Register your OpenGL window (like always)
  • When editing your dialog resource, add a custom resource window, and give it the name of your registered window.
  • Remember to register BEFORE calling the DialogBox().


  • Woah, just made your own custom window control

    SKSlayer
    SKSlayer
    So, I got it, ...

    except for the custom control ...


    What do you mean exactly by
    quote:
    and give it the name of your registered window.
    (you can find me on IRC : #opengl on undernet)
    DemOSh
    DemOSh
    Im guessing what he means is that you give it the classname of the WindowClass you registered for the GL scene.

    ~DemOSh
    demosh@aewebdesign.com
    Strylinys
    Strylinys
    The name of the registered window in NeHe''s tuts is declared by....

    wc.lpszClassName = "OpenGL";

    S.
    SKSlayer
    SKSlayer
    Thanks a lot, I am going to try it right now
    (you can find me on IRC : #opengl on undernet)
    SKSlayer
    SKSlayer
    Couldn''t get it to work

    Hey, could anyone do a little sample app based on Nehe''s drawing polygons (the white square and triangle) with rendering in a DialogBox ... (I guess that person which would do it could send it to Nehe so he write an other Tutorial about setting up GL , just kidding, but NeHe would put it for sure in download )

    (And it would be very useful to me)
    (you can find me on IRC : #opengl on undernet)
    Strylinys
    Strylinys
    Another way you could do this is to have a window that is your dialog box with all your nifty values and inputs and forms and whatever else... blah blah blah... and then you have one corner, like you said, be your ogl scene. Create this window as you would a fullscreen window, but don''t use the fullscreen mode that is specified.

    This means you want to create a popup window (one without borders or anything)... Then, you can tie that down to the main window by moving it every time the window moves etc, etc, etc...

    S.
    baskuenen
    baskuenen
    Sorry for my somewhat short post. I haven''t read NeHe''s stuff yet, but maybe this could help?

        
    //---------------------------------------------------------------------------

    #define WIN32_MEAN_AND_LEAN
    #include <windows.h>
    #include <gl\gl.h>
    //---------------------------------------------------------------------------

    // VARS

    //---------------------------------------------------------------------------

    HWND hWnd;
    HDC hDC;
    HPALETTE hPalette;
    HGLRC hGLRC;
    //---------------------------------------------------------------

    void __fastcall SetupPixelFormat()
    {
    PIXELFORMATDESCRIPTOR pfd =
    { sizeof(PIXELFORMATDESCRIPTOR), /* size */
    1, /* version */
    PFD_SUPPORT_OPENGL |
    PFD_DRAW_TO_WINDOW |
    PFD_DOUBLEBUFFER, /* support double-buffering */
    PFD_TYPE_RGBA, /* color type */
    16, /* prefered color depth */
    0, 0, 0, 0, 0, 0, /* color bits (ignored) */
    0, /* no alpha buffer */
    0, /* alpha bits (ignored) */
    0, /* no accumulation buffer */
    0, 0, 0, 0, /* accum bits (ignored) */
    16, /* depth buffer */
    0, /* no stencil buffer */
    0, /* no auxiliary buffers */
    PFD_MAIN_PLANE, /* main layer */
    0, /* reserved */
    0, 0, 0, /* no layer, visible, damage masks */
    };
    int pixelFormat;

    if ((pixelFormat = ChoosePixelFormat(hDC, &pfd)) == 0)
    { MessageBox(WindowFromDC(hDC), "ChoosePixelFormat failed.", "Error",
    MB_ICONERROR | MB_OK);
    return;
    }

    if (SetPixelFormat(hDC, pixelFormat, &pfd) != TRUE)
    { MessageBox(WindowFromDC(hDC), "SetPixelFormat failed.", "Error",
    MB_ICONERROR | MB_OK);
    return;
    }
    }
    //---------------------------------------------------------------------------

    void __fastcall SetupPalette()
    {
    int pixelFormat = GetPixelFormat(hDC);
    PIXELFORMATDESCRIPTOR pfd;
    LOGPALETTE* pPal;
    int paletteSize;

    int redMask, greenMask, blueMask;
    int i;

    DescribePixelFormat(hDC, pixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &pfd);

    if (pfd.dwFlags & PFD_NEED_PALETTE)
    paletteSize = 1 << pfd.cColorBits;
    else
    return;

    pPal = (LOGPALETTE*)LocalAlloc(LPTR, sizeof(LOGPALETTE) + paletteSize * sizeof(PALETTEENTRY));
    pPal->palVersion = 0x300;
    pPal->palNumEntries = (short)paletteSize;

    /* build a simple RGB color palette */

    redMask = (1 << pfd.cRedBits) - 1;
    greenMask = (1 << pfd.cGreenBits) - 1;
    blueMask = (1 << pfd.cBlueBits) - 1;

    for (i=0; i<paletteSize; ++i)
    { pPal->palPalEntry<i>.peRed = (BYTE)(
    (((i >> pfd.cRedShift) & redMask) * 255) / redMask);
    pPal->palPalEntry[i].peGreen = (BYTE)(
    (((i >> pfd.cGreenShift) & greenMask) * 255) / greenMask);
    pPal->palPalEntry[i].peBlue = (BYTE)(
    (((i >> pfd.cBlueShift) & blueMask) * 255) / blueMask);
    pPal->palPalEntry[i].peFlags = 0;
    }

    hPalette = CreatePalette(pPal);
    LocalFree(pPal);

    if (hPalette)
    { SelectPalette(hDC, hPalette, FALSE);
    RealizePalette(hDC);
    }
    }
    //---------------------------------------------------------------------------

    LRESULT APIENTRY WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
    static RECT RClipOld;

    switch (message)
    { case WM_CREATE:
    { HINSTANCE hInst = (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE);

    hDC = GetDC(hWnd);
    SetupPixelFormat();
    SetupPalette();
    hGLRC = wglCreateContext(hDC);
    wglMakeCurrent(hDC, hGLRC);

    glDisable(GL_TEXTURE_2D);
    glDisable(GL_CULL_FACE);
    glShadeModel(GL_FLAT);
    glDisable(GL_DEPTH_TEST);
    return 0;
    }
    case WM_DESTROY:
    {
    if (hGLRC)
    { wglMakeCurrent(NULL, NULL);
    wglDeleteContext(hGLRC);
    }
    if (hPalette)
    { DeleteObject(hPalette);
    }
    ReleaseDC(hWnd, hDC);
    PostQuitMessage(0);
    return 0;
    }
    case WM_PALETTECHANGED:
    if (hGLRC && hPalette && (HWND)wParam != hWnd)
    { wglMakeCurrent(hDC, hGLRC);
    UnrealizeObject(hPalette);
    SelectPalette(hDC, hPalette, FALSE);
    RealizePalette(hDC);
    Draw();
    }
    return 0;

    case WM_QUERYNEWPALETTE:
    if (hGLRC && hPalette)
    { wglMakeCurrent(hDC, hGLRC);
    UnrealizeObject(hPalette);
    SelectPalette(hDC, hPalette, FALSE);
    RealizePalette(hDC);
    Draw();
    return TRUE;
    }
    return 0;

    case WM_PAINT:
    { PAINTSTRUCT ps;
    BeginPaint(hWnd, &ps);
    if (hGLRC)
    { Draw();
    }
    EndPaint(hWnd, &ps);
    return 0;
    }

    case WM_SIZE:
    if (wParam!=SIZE_MINIMIZED && hGLRC)
    { iWidth = (int)LOWORD(lParam);
    iHeight = (int)HIWORD(lParam);

    glViewport(0,0,iWidth,iHeight);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glFrustum(
    -0.5*iWidth/iHeight,
    0.5*iWidth/iHeight,
    -0.5*iHeight/iHeight,
    0.5*iHeight/iHeight, 1.0F, 65535.0F);

    Draw();
    }
    return 0;
    }
    return DefWindowProc(hWnd, message, wParam, lParam);
    }
    //---------------------------------------------------------------------------

    WINAPI WinMain(HINSTANCE hInst, HINSTANCE, LPSTR, int nCmdShow)
    {
    const char *szName = "CustomCtrl";

    // register window class

    WNDCLASS wndClass;
    wndClass.style = CS_OWNDC;
    wndClass.lpfnWndProc = WndProc;
    wndClass.cbClsExtra = 0;
    wndClass.cbWndExtra = 0;
    wndClass.hInstance = hInst;
    wndClass.hIcon = NULL;
    wndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
    wndClass.hbrBackground = NULL;
    wndClass.lpszMenuName = NULL;
    wndClass.lpszClassName = szName;
    RegisterClass(&wndClass);
    //---------------------------------------------------------------------------


    SKSlayer
    SKSlayer
    Could look stupid, but I played around with your code and I could''t get it to work

    Could anyone make a project with it, then zip it and post a link to it or mail it to me (link would be better, cuz a lot of people would get helped of)

    Sorry
    (you can find me on IRC : #opengl on undernet)
    emaurina
    emaurina
    Remember me:
    Topic : Looking for Editors (Scene, object, lightmap, et a

    SKSlayer:
    Couldn''t you make your own tools ???


    So, couldn''t you make your own dialog box?



    Life is short...live every day.
    SKSlayer
    SKSlayer
    I tried in every kind of possible way, I still can''t get it working, I got my dialog opening and nothing showind up in the custom control . Could someone just mail me an example ?
    (The problem comes mostly in leaks in Win32 Progamming, cuz, there is no good explaintion over INET... I will buy a book, which ones are good ?)



    emaurina << As you can see, I am not asking about where can I find an editor, I am trying to make it myself and I need help ... So your comment doesn''t have to do with anything :D
    (you can find me on IRC : #opengl on undernet)
    zedzeek
    zedzeek
        
    #include "resource.h" // all the defines IDOK IDD_DIALOG1 etc


    LRESULT APIENTRY DlgItemProc( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
    {
    switch (uMsg)
    { case WM_INITDIALOG:
    break;
    case WM_COMMAND:
    if (wParam==IDOK)
    { return 1;
    }
    break;
    }
    }

    // stick the following line where u want the dialog to be shown

    if (DialogBox(NULL, MAKEINTRESOURCE(IDD_DIALOG1), NULL,(DLGPROC)DlgItemProc )!=IDOK)
    return NULL;


    include the rc file in your project chuck this routine "LRESULT APIENTRY DlgItemProc( ....)" somewhere before u call the model dialog box , IDD_DIALOG1 is the id of your dialog box


    SKSlayer
    SKSlayer
    Errr ... I already know how to open a DialogBox ... I just can''t get OGL in ...
    (you can find me on IRC : #opengl on undernet)
    SKSlayer
    SKSlayer
    Well, I actually need it for one project, but, I need to know how to do it, even if I use an other way, I want to know, I want to understand, but I need a sample !!!
    (you can find me on IRC : #opengl on undernet)
    SKSlayer
    SKSlayer
    Code guru is a bit too much ... MFC oriented
    (you can find me on IRC : #opengl on undernet)
    SKSlayer
    SKSlayer
    I looked up the OGL section, and there is nothing about it
    (you can find me on IRC : #opengl on undernet)
    zedzeek
    zedzeek
    what about this one "This sample create an OpenGL rendering context in a dialog box and draw a simple cube" http://codeguru.earthweb.com/opengl/texture_mapping.shtml
    MFC is just bulit on the win32 API
    Strylinys
    Strylinys
    But mfc takes a lot more to learn, plus, you have to include way too many dll files for people to run the program if they don''t have them all, etc etc... Even though it may be coded in Win32, it doesn''t mean they''re the same, I don''t think I''ll ever want to know what a CShape is or how to call one, simply because I have looked at the entire MFC hierarical chart and it scares me.

    S.

    Topic Locked

    This topic has been locked by a moderator. New replies are not allowed.

    Sign in to reply to this topic.