Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 5 of 5

Thread: No Render-Output after resizing

Hybrid View

  1. #1
    Junior Member Newbie
    Join Date
    May 2013
    Location
    Germany
    Posts
    6

    No Render-Output after resizing

    Hi there,

    I came across an issue with my rendering code. As the title says, I get no render output at specific window sizes. For example at 508x525 and less the expected output is visible, but at ~ 552x552 and higher it is not.
    Here is my Code:
    WndProc
    Code cpp:
    LRESULT CALLBACK Graphics::WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam){
        switch(msg){
            case WM_DESTROY:
                PostQuitMessage(0);
                break;
            case WM_SIZE:
                ResetViewport(LOWORD(lParam), HIWORD(lParam));
                break;
            case WM_KEYDOWN:
                int width = wndSize.iWidth;
                int height = wndSize.iHeight;
                break;
            default:
                return DefWindowProc(hWnd, msg, wParam, lParam);
                break;
        }
        return 0;
    }

    Init opengl function
    Code cpp:
    bool Graphics::InitGL(){
      // Window existing?
        if(!hMainWnd)
            return false;
     
        // Pixelformat
        PIXELFORMATDESCRIPTOR pfd;
        ZeroMemory(&pfd, sizeof(PIXELFORMATDESCRIPTOR));
     
        pfd.nVersion = 1;
        pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
        pfd.dwFlags = PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW | PFD_DOUBLEBUFFER;
        pfd.iPixelType = PFD_TYPE_RGBA;
        pfd.cColorBits = 24;
        pfd.cAlphaBits = 16;
        pfd.cDepthBits = 8;
     
        // Get the device context
        if(!(hDC = GetDC(hMainWnd)))
            return false;
     
        // Get appropriate pixel format
        int iFormat = 0;
        if(!(iFormat = ChoosePixelFormat(hDC, &pfd)))
            return false;
     
        if(!SetPixelFormat(hDC, iFormat, &pfd))
            return false;
     
        // Create render context
        if(!(hRC = wglCreateContext(hDC)))
            return false;
     
        // Make it the current context
        if(!wglMakeCurrent(hDC, hRC))
            return false;
     
     
        // set the viewport
        // get the client area size
        RECT clientArea;
        GetClientRect(hMainWnd, &clientArea);
        ResetViewport(clientArea.right - clientArea.left, clientArea.bottom - clientArea.top);
        return true;
    }

    ResetViewport function
    Code cpp:
    void Graphics::ResetViewport(int width, int height){
        if(width <= 0)
            width = 100;
        if(height <= 0)
            height = 100;
     
        wndSize.iWidth = width;
        wndSize.iHeight = height;
     
        glViewport(0, 0, width, height);
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        gluPerspective(45.0f, (float)(width/height), 0.1f, 100.0f);
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
    }

    Render function
    Code cpp:
    void Graphics::Render(){
        glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
        glClearColor(1.0f, 0.15f, 0.76f, 1.0f);
     
        glLoadIdentity();
        glBegin(GL_TRIANGLES);
            glColor3f(1.0f, 1.0f, 1.0f);
            glVertex3f(0.0f, 0.0f, 0.0f);
            glVertex3f(0.5f, 1.0f, 0.0f);
            glVertex3f(1.0f, 0.0f, 0.0f);
        glEnd();
     
        SwapBuffers(hDC);
    }

    Any suggestions?

    EDIT: Does anybody know why I can't change my profile settings?

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Mar 2009
    Location
    Singapore
    Posts
    800
    I am not sure if this helps but currently both your variables are integers in the second parameter here
    Code :
    gluPerspective(45.0f, (float)(width/height), 0.1f, 100.0f);

    You should instead cast one of them to float like this
    Code :
    gluPerspective(45.0f, ((float)width)/height, 0.1f, 100.0f);

    Regards,
    Mobeen

  3. #3
    Junior Member Newbie
    Join Date
    May 2013
    Location
    Germany
    Posts
    6
    I changed it the way you suggested but it didn't changed anything. Also your Code is hardly readable, try using the [highlight=cpp][/highlight] tag instead of the code tag. However thanks for your quick reply.

  4. #4
    Advanced Member Frequent Contributor
    Join Date
    Mar 2009
    Location
    Singapore
    Posts
    800
    I was writing my reply when you edited your post that caused the color codes all over the place. And one liner is not that difficult to read when using code tag.

    How about you keep a constant aspect ratio of say 1 does it show the output?
    Regards,
    Mobeen

  5. #5
    Junior Member Newbie
    Join Date
    May 2013
    Location
    Germany
    Posts
    6
    Quote Originally Posted by mobeen View Post
    I was writing my reply when you edited your post that caused the color codes all over the place. And one liner is not that difficult to read when using code tag.
    Yeah, it was the color-tags that distracted me.
    Quote Originally Posted by mobeen View Post
    How about you keep a constant aspect ratio of say 1 does it show the output?
    Using a fixed aspect ratio results in no output at all. However this function:
    Code cpp:
    void Graphics::DrawAxis(){
        // set new viewport at the bottom
       glViewport(0,0, 100, 100);
       glPushMatrix();
       glLoadIdentity();
       glTranslatef(0.0f, 0.0f, -1.0f);
       glRotatef(15.0f, 1.0f, 0.0f, 0.0f);
       //glRotatef(_angle, 0.0f, 1.0f, 0.0f);
       glBegin(GL_LINES);
    	// x-axis
    	glColor3f(0.8f, 0.0f, 0.0f);
    	glVertex3f(0.0f, 0.0f, 0.0f);
    	glVertex3f(1.0f, 0.0f, 0.0f);
    	// y-axis
    	glColor3f(0.0f, 0.8f, 0.0f);
    	glVertex3f(0.0f, 0.0f, 0.0f);
    	glVertex3f(0.0f, 1.0f, 0.0f);
    	// z-axis
    	glColor3f(0.0f, 0.0f, 0.8f);
    	glVertex3f(0.0f, 0.0f, 0.0f);
    	glVertex3f(0.0f, 0.0f, 1.0f);
       glEnd();
     
       glViewport(0, 0, wndSize.iWidth, wndSize.iHeight);
       glPopMatrix();
    }

    renders just fine.

    EDIT: Just sorted it out. Nothing is visible, because the "camera" and the object are both at (0,0,0). So after adding a translation on the -z Axis everything works just fine.
    Last edited by Lighttec; 05-07-2013 at 02:56 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •