• Advertisement
Sign in to follow this  

Drawing Functions not working.

This topic is 4344 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello everyone, once again another problem here. I split up all of my code into 8 source files, thinking everything would be easier, but it's not now. When I go back to the old unsplit code, it drew to the screen and everything, but now in my split up code, same code and everything (just in a bunch of files) it won't draw to the screen. It will send out a messagebox in between glBegin() and glEnd(), but it wont draw anything. It wont even clear to cyan like I told it. Here's some code.
//main
int WINAPI WinMain (HINSTANCE hInstance,
                    HINSTANCE hPrevInstance,
                    LPSTR lpCmdLine,
                    int iCmdShow)
{
    WNDCLASS wc;
    HWND hWnd;
    HDC hDC;
    HGLRC hRC;
    MSG msg;
    bool playing = true;

    registerWndClass(hInstance, AppName, wc, WindowHeight, WindowWidth, hWnd);


    
    EnableOpenGL (hWnd, &hDC, &hRC);
    gameInit();

    while (playing)
    {

        if (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE))
        {

            if (msg.message == WM_QUIT)
            {
                playing = false;
            }
            else
            {
                TranslateMessage (&msg);
                DispatchMessage (&msg);
            }
        }
        else
        {
            gameRun(hDC);

        }
    }


    DisableOpenGL (hWnd, hDC, hRC);


    DestroyWindow (hWnd);

    return msg.wParam;
}

....

//gameRun(HDC)
void gameRun(HDC hDC)
{
    glClearColor(0.0f, 255.0f, 255.0f, 0.0f);
    glClear(GL_COLOR_BUFFER_BIT);
    glPushMatrix();
    if(GameBoard.currBlockPos == STARTING)
    {
        if(starting == 1)
        {
            GameBoard.currblock = new block(true);
            starting++;
        }
        else
        {
            GameBoard.currblock = GameBoard.nextblock;
        }
        GameBoard.nextblock = new block(false);
        GameBoard.currBlockPos = FALLING;
    }
    if(GameBoard.currBlockPos == FALLING)
    {
        if(!GameBoard.currblock->atBottom())
        {
            GameBoard.currblock->moveBlockDown();
        }
        else
        {
            GameBoard.currBlockPos = STARTING;
        }
    }
    GameBoard.drawBack();
    glPopMatrix();
    SwapBuffers(hDC);
    Sleep(1);
}

...

//DrawBack function with messagebox.
void board::drawBack()
{
    glBegin(GL_QUADS);
        glColor3f(0.0, 0.0, 0.0);
        glVertex2f(-0.95, 0.9);
        glVertex2f(-0.95, -0.9);
        glVertex2f(0.25, -0.9);
        glVertex2f(0.25, 0.9);
        MessageBox(NULL, "H", "J", NULL); //<- messagebox appears...?
    glEnd();
    glBegin(GL_QUADS);
        glColor3f(0.0f, 0.0f, 0.0f);
        glVertex2f(0.35, 0.9);
        glVertex2f(0.35, 0.6);
        glVertex2f(0.65, 0.6);
        glVertex2f(0.65, 0.9);
    glEnd();
}

Share this post


Link to post
Share on other sites
Advertisement
I still can't figure it out, I'm using the debugger but it's not telling me anything. Could someone help please?

Edit: Even a basic drawing function won't appear on the screen. The screen comes up like it's supposed to, but then won't do anything else. It's almost as OpenGL doesn't have a handle on the window.

Share this post


Link to post
Share on other sites
I'm not sure if this is entirely valid, but have you tried getting the HDC before initializting OpenGL (using GetDC, I think)? What is the definition of 'EnableOpenGL'? Is it user-defined, or in the library itself? Also, are you sure the last two arguments are supposed to be pointers? Since they are handles, I'm not sure if the compiler will be able to catch the difference in types, so that may be one problem.

EDIT: Disregard the type question. Tested it, and the compiler caught it.

Try finding some small examples of OpenGL and see how they do it, and compare.

EDIT: Well, I see you're using the Dev-C++ template for OpenGL. Your problem is that you did not create the window before you called EnableOpenGL. Try that, and then check back.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement