Thread: 'triangle' won't appear in window

  1. #1
    The Right Honourable psychopath's Avatar
    Join Date
    Mar 2004
    Location
    Where circles begin.
    Posts
    1,071

    Unhappy 'triangle' won't appear in window

    In my app, I have to windows...I have (attempted) to allow one (the edit window) to support OpenGL....the 'triangle' rendered fine before i added the edit window. after adding the edit window, and specifying that I wanted to inititilize OGL for the window 'edit_box', it diddn't work..my code is as follows:

    Code:
    // Include files
    #include <windows.h>
    #include <gl/gl.h>
    //end include files
    
    HWND edit_box = NULL;
    
    // Function Declarations
    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 );
    
    // WinMain
    int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int iCmdShow )
    {
    WNDCLASS wc;
    WNDCLASS ed;
    HWND hwnd;
    HDC hdc;
    HGLRC gl_hrc;
    MSG msg;
    BOOL bQuit = FALSE;
    float theta = 0.0f;
    
    // register window class
    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( GRAY_BRUSH );
    wc.lpszMenuName = NULL;
    wc.lpszClassName = "PsychoEngine";
    RegisterClass( &wc );
    
    //regester edit class
    ed.style = CS_OWNDC;
    ed.lpfnWndProc = WndProc;
    ed.cbClsExtra = 0;
    ed.cbWndExtra = 0;
    ed.hInstance = hInstance;
    ed.hIcon = LoadIcon( NULL, IDI_APPLICATION );
    ed.hCursor = LoadCursor( NULL, IDC_ARROW );
    ed.hbrBackground = (HBRUSH)GetStockObject( BLACK_BRUSH );
    ed.lpszMenuName = NULL;
    ed.lpszClassName = "EDIT";
    RegisterClass( &ed );
    
    // create main window
    hwnd = CreateWindow(
    "PsychoEngine", "PsychoEngine | PsychopathProductions",
    WS_CAPTION | WS_POPUPWINDOW | WS_VISIBLE,
    0, 0, 800, 570,
    NULL, NULL, hInstance, NULL );
    
    // enable OpenGL for the window
    EnableOpenGL( edit_box, &hdc, &gl_hrc );
    
    // program main loop
    while ( !bQuit ) {
    
    // check for messages
    if ( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) ) {
    
    // handle or dispatch messages
    if ( msg.message == WM_QUIT ) {
    bQuit = TRUE;
    } else {
    TranslateMessage( &msg );
    DispatchMessage( &msg );
    }
    
    } else {
    
    // OpenGL animation code goes here
    glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
    glClear( GL_COLOR_BUFFER_BIT );
    
    glPushMatrix();
    glBegin( GL_TRIANGLES );
    glColor3f( 1.0f, 0.0f, 0.0f ); glVertex2f( 0.0f, 1.0f );
    glColor3f( 0.0f, 1.0f, 0.0f ); glVertex2f( 0.87f, -0.5f );
    glColor3f( 0.0f, 0.0f, 1.0f ); glVertex2f( -0.87f, -0.5f );
    glEnd();
    glPopMatrix();
    
    SwapBuffers( hdc );
    
    theta += 1.0f;
    
    }
    
    }
    
    // shutdown OpenGL
    DisableOpenGL( hwnd, hdc, gl_hrc );
    
    // destroy the window explicitly
    DestroyWindow( hwnd );
    
    return msg.wParam;
    
    }
    
    // Window Procedure
    
    LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam )
    {
    HWND edit_box = NULL;
    
    switch ( message )
    {
    case WM_CREATE:
    RECT rect;
               GetClientRect(hwnd,&rect);
               edit_box = CreateWindow("EDIT", "Edit Window",WS_CHILD | WS_BORDER | WS_CAPTION | WS_POPUPWINDOW | WS_VISIBLE,
    									0, 30, 600, 538, hwnd, NULL,
    									((LPCREATESTRUCT)lparam)->hInstance, NULL);
    break;
    
    case WM_CLOSE:
    MessageBox (NULL, "Are you sure you want to close the program?\nAll un-saved data will be lost." , "Exiting...", 0 + MB_YESNO + MB_DEFBUTTON2 + MB_ICONQUESTION);
    PostQuitMessage( 0 );
    break;
    return 0;
    
    case WM_DESTROY:
    break;
    return 0;
    
    case WM_KEYDOWN:
    switch ( wparam ) {
    
    case VK_ESCAPE:
    PostQuitMessage( 0 );
    break;
    return 0;
    
    }
    return 0;
    
    default:
    return DefWindowProc( hwnd, message, wparam, lparam );
    
    }
    
    }
    
    // Enable OpenGL
    
    VOID EnableOpenGL( HWND edit_box, HDC * hdc, HGLRC * gl_hrc )
    {
    PIXELFORMATDESCRIPTOR pfd;
    int iFormat;
    
    // get the device context (DC)
    *hdc = GetDC( edit_box );
    
    // set the pixel format for the DC
    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 );
    
    // create and enable the render context (RC)
    *gl_hrc = wglCreateContext( *hdc );
    wglMakeCurrent( *hdc, *gl_hrc );
    
    }
    
    // Disable OpenGL
    
    VOID DisableOpenGL( HWND edit_box, HDC hdc, HGLRC gl_hrc )
    {
    wglMakeCurrent( NULL, NULL );
    wglDeleteContext( gl_hrc );
    ReleaseDC( edit_box, hdc );
    }
    ...sorry...codes a little lengthy...anyway any help will be appreciated...

    -psychopath
    Last edited by psychopath; 04-17-2004 at 03:18 PM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    The Right Honourable psychopath's Avatar
    Join Date
    Mar 2004
    Location
    Where circles begin.
    Posts
    1,071
    sorry...a little new to the board...added the code tags...anyway...can anyone help???

  4. #4
    mov.w #$1337,D0 Jeremy G's Avatar
    Join Date
    Nov 2001
    Posts
    704
    use glvertex3f( x , y, z).
    And I think you can get THAT code to show you a triangle if you
    gltranslatef(0, 0, -2).
    before glBegin().
    c++->visualc++->directx->opengl->c++;
    (it should be realized my posts are all in a light hearted manner. And should not be taken offense to.)

  5. #5
    The Right Honourable psychopath's Avatar
    Join Date
    Mar 2004
    Location
    Where circles begin.
    Posts
    1,071
    no difference....remember the triangle DID show...but now that there are TWO windows, it wont show...which makes me think i diddn't specify openGL for the 'edit_box' window properly...?

  6. #6
    The Right Honourable psychopath's Avatar
    Join Date
    Mar 2004
    Location
    Where circles begin.
    Posts
    1,071
    nvm...got it working :Þ

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C or C++
    By AcerN30 in forum Game Programming
    Replies: 41
    Last Post: 05-30-2008, 06:57 PM
  2. WM_CAPTION causing CreateWindowEx() to fail.
    By Necrofear in forum Windows Programming
    Replies: 8
    Last Post: 04-06-2007, 08:23 AM
  3. 6 measly errors
    By beene in forum Game Programming
    Replies: 11
    Last Post: 11-14-2006, 11:06 AM
  4. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 12:34 PM
  5. problem with open gl engine.
    By gell10 in forum Game Programming
    Replies: 1
    Last Post: 08-21-2003, 04:10 AM