ChangeDisplaySettings - Blank?

This is a discussion on ChangeDisplaySettings - Blank? within the Windows Programming forums, part of the Platform Specific Boards category; I have a very small section of code that is confusing me, and seems to be causing a blackscreen. The ...

  1. #1
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465

    ChangeDisplaySettings - Blank?

    I have a very small section of code that is confusing me, and seems to be causing a blackscreen. The codey goes something like this:

    Code:
            DEVMODE dm = { 0 };
            LONG ret = 0; DWORD i = 0;
            
    
            dm.dmSize = sizeof(DEVMODE);
            dm.dmDriverExtra = 0;
    
            while( ::EnumDisplaySettings( 0, i, &dm ) )
            {
                if(dm.dmPelsHeight == 600 &&
                    dm.dmPelsWidth == 800 &&
                    dm.dmBitsPerPel == 32)
                {
                    ret = 1;
                    break;
                }
                i++;
            }
    
            if(ret)
            {
                dm.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL;
                ret = ::ChangeDisplaySettings( &dm, CDS_FULLSCREEN );
                if( ret != DISP_CHANGE_SUCCESSFUL ) // Blarhgfadgigafdg.
            }
    When my current screen resolution in 800 x 600, and it is changing into fullscreen that way, this works, and I get stuff to show on the screen. However, when it is not, it says DISPLAY_CHANGE_SUCCESSFUL but of course I can not see anything being rendered. Is there a better way I should approach this?
    Last edited by Tonto; 12-03-2006 at 02:14 AM.

    ╔╗╔╦══╦╗╔╦══╦╗
    ║╚╝║╔╗║╚╝║╔╗║║
    ║╔╗║╠╣║╔╗║╠╣╠╣
    ╚╝╚╩╝╚╩╝╚╩╝╚╩╝

    codez http://code.google.com/p/zxcvbn/

  2. #2
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    Or, is there any more info I could provide to better help indentify the problem. Edit: I can see the cursor. So, it's not just completely busted. Kinda relevant?
    Last edited by Tonto; 12-03-2006 at 03:03 PM.

    ╔╗╔╦══╦╗╔╦══╦╗
    ║╚╝║╔╗║╚╝║╔╗║║
    ║╔╗║╠╣║╔╗║╠╣╠╣
    ╚╝╚╩╝╚╩╝╚╩╝╚╩╝

    codez http://code.google.com/p/zxcvbn/

  3. #3
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Is this for opengl? If so, make sure the viewport and perspective are being properly set for the new display.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  4. #4
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    Yes I'm sorry I didn't specify that. To initialize the window it goes:

    Code:
        if( fullscreen ) 
            changedisplaysettings();
    
        pixelformatstuff();
    
        glMatrixMode( GL_PROJECTION );
        glLoadIdentity();
        
        gluPerspective
            ( 45, double(width) / double(height), 0.1f, 2000.0f );
    
        glViewport( 0, 0, width, height );
        glMatrixMode( GL_MODELVIEW );
    And I have checked and the width and height are correctly at 800 x 600 or whatever values I specify them to be.

    ╔╗╔╦══╦╗╔╦══╦╗
    ║╚╝║╔╗║╚╝║╔╗║║
    ║╔╗║╠╣║╔╗║╠╣╠╣
    ╚╝╚╩╝╚╩╝╚╩╝╚╩╝

    codez http://code.google.com/p/zxcvbn/

  5. #5
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    To is a very strange problem and I am confused.

    Code:
        PIXELFORMATDESCRIPTOR    pfd = { 0 };
        unsigned int             pf = 0;
    
        if( isFullscreen() )
        {
            DEVMODE dm = { 0 };
            LONG ret = 0; DWORD i = 0;
    
            dm.dmSize = sizeof(DEVMODE);
            dm.dmDriverExtra = 0;
            
            while( ::EnumDisplaySettings( 0, i, &dm ) )
            {
                if( dm.dmPelsHeight == DWORD(getHeight()) &&
                    dm.dmPelsWidth == DWORD(getWidth()) &&
                    dm.dmBitsPerPel == 32 )
                {
                    ret = 1;
                    break;
                }
                i++;
            }
    
            if(ret)
            {    
                dm.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL;
                ret = ::ChangeDisplaySettings( &dm, CDS_FULLSCREEN );
    
                if( ret != DISP_CHANGE_SUCCESSFUL )
                {
                    throw CError( EDSPSTTGSCHANGE );
                }
            }
            else
            {
                throw CError( EDEVICENOTFOUND );
            }
        }
    
        pfd.nSize      = sizeof(PIXELFORMATDESCRIPTOR);
        pfd.nVersion   = 1;
        pfd.dwFlags    = 
            PFD_DRAW_TO_WINDOW | 
            PFD_SUPPORT_OPENGL | 
            PFD_DOUBLEBUFFER;
    
        pfd.iPixelType = PFD_TYPE_RGBA;
        pfd.cColorBits = 32;
        pfd.cDepthBits = 24;
    
        m_hDC = getDC();
        pf = ::ChoosePixelFormat( m_hDC, &pfd );
    
        if( !pf )
        {
            throw CError( ECHOOSEPIXELFMT );
        }
    
        if( !::SetPixelFormat( m_hDC, pf, &pfd ) )
        {
            throw CError( ESETPIXELFMT );
        }
    
        m_hRC = ::wglCreateContext( m_hDC );
        if( !m_hRC )
        {
            throw CError( ECREATERC );
        }
    
        if( !::wglMakeCurrent( m_hDC, m_hRC ) )
        {
            throw CError( EMAKECURRENTRC );
        }
    
        glMatrixMode( GL_PROJECTION );
        glLoadIdentity();
        
        gluPerspective
            ( 45, double(width) / double(height), 0.0f, 2000.0f );
    
        glViewport( 0, 0, width, height );
        glMatrixMode( GL_MODELVIEW );
    This code fails to go into fullscreen mode properly if the resolution that I pug into changedisplaysettings is different from the one I'm currently on I.E. I can get into fullscreen mode 800x600 fine because right now I am on an 800x600 setting, but when I change into 1280x768, the changedisplaysettings is successful but I do not see anything.

    ╔╗╔╦══╦╗╔╦══╦╗
    ║╚╝║╔╗║╚╝║╔╗║║
    ║╔╗║╠╣║╔╗║╠╣╠╣
    ╚╝╚╩╝╚╩╝╚╩╝╚╩╝

    codez http://code.google.com/p/zxcvbn/

  6. #6
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    I can't see anything obviously wrong with the code you have posted thus far. Could you post a minimal example that replicates the problem?

    Or, you could quickly try:

    a) Replacing 'width' and 'height' variables with 'getHeight()' and 'getWidth()' calls to ensure consistency in values.

    or

    b)
    Code:
    RECT rc={0};
    GetClientRect(hwnd,&rc);
    GLfloat x=(GLfloat)(rc.right-rc.left);
    GLfloat y=(GLfloat)(rc.bottom-rc.top);
    gluPerspective(45.0f, x / y, 0.0f, 2000.0f );
    
    glViewport( 0, 0, x, y);
    I'm once more suggesting perspective/viewport as a possible source of the problem because that's the only circumstances I can think of where I've encountered anything like the behaviour you describe.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  7. #7
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    Mmm. Very interesting. So basakikally, that code did something. I have my current display settings on 1600x1200, and I create my window with, for example, the parameters 800x600, the style WS_POPUP | WS_MAXIMIZE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN and WS_EX_APPWINDOW. Right after the window's creation, I try GetClientRect and it see's that the window is 1600x1200, and even up until I calculate the perspective and viewport, it thinks this. So basically, I think that the window should be 800x600, and GetClientRect tells me that it's 1600x1200. Should I resize the window, or just recalculate the perspective and viewport to deal with it, or what?

    ╔╗╔╦══╦╗╔╦══╦╗
    ║╚╝║╔╗║╚╝║╔╗║║
    ║╔╗║╠╣║╔╗║╠╣╠╣
    ╚╝╚╩╝╚╩╝╚╩╝╚╩╝

    codez http://code.google.com/p/zxcvbn/

  8. #8
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Should I resize the window, or just recalculate the perspective and viewport to deal with it?
    Probably both for maximum flexibility; having redundancy in start up code is not really going to be a problem since performance at this stage in program execution is arguably not really a critical issue.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  9. #9
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    I guess a better question would be, how would I resize the window and viewport in order to see what's being rendered? When I changedisplaysettings with dmpelswidth/height set to 800x600, and then change the aspect of the perspective to 1600/1200 (that equals 800/600) and the viewport width and height to 1600x1200, then I only see the top left corner of what is being rendered. When I have the 800x600 device (?) from changedisplaysettings, and then have the aspect of the perspective as 800x600, and the viewport widthxheight as 800x600, I see nothing.

    ╔╗╔╦══╦╗╔╦══╦╗
    ║╚╝║╔╗║╚╝║╔╗║║
    ║╔╗║╠╣║╔╗║╠╣╠╣
    ╚╝╚╩╝╚╩╝╚╩╝╚╩╝

    codez http://code.google.com/p/zxcvbn/

  10. #10
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    That seems very odd. It's probably a good idea to post that minimal example that reproduces the problem.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  11. #11
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    Okay. Collapsed down most everything into this. There's a nifty bonus of seeing some cool rasterizer wierdo pattern thingies if you solve the problem Oh yeah. so, to see the problem, change the values of what COGL and CGame are initialized with in Main.cpp

    Main.h

    Code:
    #pragma once
    
    #define _UNICODE
    #define UNICODE
    
    #define _USE_MATH_DEFINES
    #define _WIN32_WINNT 0x500
    
    #define WIN32_LEAN_AND_MEAN
    #define WIN32_WINNT
    
    #include <windows.h>
    
    #include <gl/gl.h>
    #include <gl/glu.h>
    
    #include <cstdio>
    #include <cmath>
    
    LRESULT CALLBACK WindowProcedure( HWND, UINT, WPARAM, LPARAM );
    INT WINAPI WinMain( HINSTANCE, HINSTANCE, LPSTR, INT );
    
    
    class CWindowClassEx
    {
    
    public:
    
        CWindowClassEx
            ( LPCTSTR szClassName, 
            WNDPROC fnWindowProc, 
            UINT uiStyle            = CS_HREDRAW | CS_VREDRAW,
            HICON hIcon             = ::LoadIcon( 0, IDI_APPLICATION ),
            HCURSOR hCursor         = ::LoadCursor( 0, IDC_ARROW ), 
            HBRUSH hbrBackground    = (HBRUSH) ::GetStockObject( WHITE_BRUSH ), 
            int iClassExtra         = 0, 
            int iWndExtra           = 0,
            LPCTSTR szMenuName      = 0 );
    
        ~CWindowClassEx( void );
    
        operator const WNDCLASSEX & ( void ) const;
        LPCTSTR getClassName( void ) const;
        HINSTANCE getHinstance( void ) const;
    
    private:
    
        WNDCLASSEX  m_windowClass;
    
    };
    
    
    
    class CWindow
    {
    
    private:
    
    	CWindowClassEx  m_windowClass;
    	HWND            m_window;
    
    	DWORD           m_style;
        DWORD           m_exStyle;
        LPCTSTR         m_windowName;
    
        int             m_width, m_height;
    
    public:
    
        CWindow
        ( 
            int     width, 
            int     height, 
            LPCTSTR className,
            WNDPROC windowProc      = 0,
            LPCTSTR windowName      = TEXT(""),
            DWORD   windowStyle     = WS_OVERLAPPEDWINDOW,
            DWORD   windowExStyle   = WS_EX_OVERLAPPEDWINDOW,
            LPVOID  createParams    = 0,
            UINT    classStyle      = CS_VREDRAW | CS_HREDRAW,
            HICON   icon            = ::LoadIcon( 0, IDI_APPLICATION ),
            HCURSOR cursor          = ::LoadCursor( 0, IDC_ARROW )
        );
    
    	virtual ~CWindow( void );
    
    
    	HWND getHwnd( void ) const;
    	const CWindowClassEx & getWindowClass( void ) const;
    
    	HDC getDC( void ) const;
    
        int getWidth( void ) const;
        int getHeight( void ) const;
    
        bool isFullscreen( void ) const;  
        bool show( int showCommand );
    
        virtual void resize( int width, int height );
    
    };
    
    class COGL : public CWindow
    {
    
    private:
        
        HGLRC       m_hRC;
        HDC         m_hDC;
        HICON       m_hIcon;
    
        bool        m_bFullscreen;
    
    public:
    
    
        explicit COGL( int width, int height, bool fullscreen );
        virtual ~COGL( void );
        
        bool showWindow( int nCmdShow );
    
        bool isFullscreen( void ) const;
        void swap( void ) const;
    
        virtual void resize( int width, int height );
    
        virtual void initialize( void );
        virtual void kill( void );
    
    };
    
    
    class CGame
    {
    
    public:
    
        CGame( int width, int height );
        ~CGame( void );
    
        void draw( void ) const;
        void update( double dt );
    
    private:
    
        int             m_width, m_height;
        int             m_gameStateNum;
    
        double          m_rgb[3][800];
        double          m_rgbRates[3][800];
    
        GLUquadricObj * m_x;
    
    };
    Main.cpp

    Code:
    #include "Main.h"
    
    INT WINAPI WinMain( HINSTANCE, HINSTANCE, LPSTR, INT )
    {
        COGL  *    window = 0;  // Our Open GL enabled window
        CGame *    game = 0;    // Our pong game
    
        LARGE_INTEGER       
            current,        // Performance time
            prevupdate,     // Last update time
            prevrender,     // Last render time
            frame,          // F.P.S.
            freq;           // Performance frequency
    
        MSG  msg = { 0 };
    
        window = new COGL( 1024, 768, true );
        game = new CGame( 1024, 768 );
        
        ::QueryPerformanceFrequency( &freq );
        ::QueryPerformanceCounter( &current );
    
        frame.QuadPart = freq.QuadPart / 30;    // 40 FPS
        prevrender = prevupdate = current;      // We're in the now
    
        while( msg.message != WM_QUIT )
        {
            if( ::PeekMessage( &msg, 0, 0, 0, PM_REMOVE ) )
            {
                ::TranslateMessage( &msg );
                ::DispatchMessage( &msg );
            }
    
            ::QueryPerformanceCounter( &current );
    
            // If elapsed > frame rate - render and swap the buffers out
            if( current.QuadPart - prevrender.QuadPart > frame.QuadPart )
            {
                game->draw();
                prevrender = current;
                window->swap();
            }
    
            //
            // Otherwise, just do some updating. 
            //  o Recieves deltatime, keyboard status
            //
    
            game->update
                ( double(current.QuadPart - prevupdate.QuadPart) / 
                double(freq.QuadPart) );
    
            prevupdate = current;
        }
        
        delete window;
        delete game;
        
    
        return 0;
    }
    
    
    
    LRESULT CALLBACK WindowProcedure
        ( HWND hWindow, UINT uMessage, 
        WPARAM wParam, LPARAM lParam )
    {
        static COGL * fogl = 0;
    
        switch( uMessage )
        {
            case WM_USER + 4337:
            {
                if( !lParam || !wParam )
                    return -1;
    
                fogl = reinterpret_cast< COGL * >( lParam );
    
                fogl->initialize();
                fogl->show( SW_SHOW );
    
                break;
            }
    
            case WM_SIZE:
            {
                if(fogl) 
                    fogl->resize( LOWORD(lParam), HIWORD(lParam) );
    
                break;
            }
    
            case WM_CLOSE:
            {
                ::PostQuitMessage( 0 );
                break;
            }
    
            case WM_DESTROY:
                break;
    
            default:
                return ::DefWindowProc( hWindow, uMessage, wParam, lParam );
        }
    
        return 0;
    }
    
    CWindow::CWindow
    ( 
            int     width, 
            int     height, 
            LPCTSTR className,
            WNDPROC windowProc      /* = 0 */,
            LPCTSTR windowName      /* = TEXT("") */, 
            DWORD   windowStyle     /* = WS_OVERLAPPEDWINDOW */,
            DWORD   windowExStyle   /* = WS_EX_OVERLAPPEDWINDOW */,
            LPVOID  createParams    /* = 0 */,
            UINT    classStyle      /* = CS_VREDRAW | CS_HREDRAW */,
            HICON   icon            /* = ::LoadIcon( 0, IDI_APPLICATION ) */,
            HCURSOR cursor          /* = ::LoadCursor( 0, IDC_ARROW ) */
    ) : 
    
    m_window( 0 ),
    
    m_windowClass( className, windowProc, classStyle, icon, cursor ),
    m_windowName( windowName ),
    
    m_width( width ),
    m_height( height ),
    
    m_style( windowStyle ),
    m_exStyle( windowExStyle )
    
    {
        RECT wr = { 0 };
    
        wr.left     = 0;
        wr.right    = width;
        wr.top      = 0;
        wr.bottom   = height;
    
        ::AdjustWindowRectEx( &wr, m_style, false, m_exStyle );
    
        m_window = ::CreateWindowEx( m_exStyle, m_windowClass.getClassName(), 
            m_windowName, m_style | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, 
            CW_USEDEFAULT, CW_USEDEFAULT, wr.right - wr.left, wr.bottom - wr.top, 
            0, 0, ::GetModuleHandle( 0 ), createParams );
    }
    
    CWindow::~CWindow( void ) { ::DestroyWindow( m_window ); }
    HWND CWindow::getHwnd( void ) const { return m_window; }
    HDC CWindow::getDC( void ) const { return ::GetDC( m_window ); }
    int CWindow::getWidth( void ) const { return m_width; }
    int CWindow::getHeight( void ) const { return m_height; }
    
    void CWindow::resize( int width, int height )
    {
        m_width = width;
        m_height = height;
    }
    
    
    
    bool CWindow::show( int showCommand )
    {
        ::SetForegroundWindow( m_window );
        return ::ShowWindow( m_window, showCommand ) == TRUE;
    }
    
    CWindowClassEx::CWindowClassEx
    ( 
        LPCTSTR className, 
        WNDPROC windowProc, 
        UINT classStyle         /* = CS_HREDRAW | CS_VREDRAW */,
        HICON icon              /* = ::LoadIcon( 0, IDI_APPLICATION ) */,
        HCURSOR cursor          /* = ::LoadCursor( 0, IDC_ARROW ) */,
        HBRUSH background       /* = (HBRUSH) ::GetStockObject( WHITE_BRUSH ) */, 
        int classExtra          /* = 0 */,  
        int windowExtra         /* = 0 */, 
        LPCTSTR menuName        /* = 0 */ 
    ) : 
    
    m_windowClass()
    
    {
        m_windowClass.cbSize          = sizeof(WNDCLASSEX);
        m_windowClass.hInstance       = ::GetModuleHandle( 0 );
    
        m_windowClass.hIcon           = icon;
        m_windowClass.hIconSm         = icon;
        m_windowClass.hCursor         = cursor;
    
        m_windowClass.lpfnWndProc     = windowProc;
        m_windowClass.cbWndExtra      = windowExtra;
        m_windowClass.cbClsExtra      = classExtra;
        m_windowClass.style           = classStyle;
        m_windowClass.hbrBackground   = background;
    
        m_windowClass.lpszClassName   = className;
        m_windowClass.lpszMenuName    = menuName;
    
        ::RegisterClassEx( &m_windowClass );
    }
    
    
    
    CWindowClassEx::~CWindowClassEx( void )
    {
        ::UnregisterClass( m_windowClass.lpszClassName, m_windowClass.hInstance );
    }
    
    CWindowClassEx::operator const WNDCLASSEX & ( void ) const { return m_windowClass; }
    LPCTSTR CWindowClassEx::getClassName( void ) const { return m_windowClass.lpszClassName; }
    HINSTANCE CWindowClassEx::getHinstance( void ) const { return m_windowClass.hInstance; }
    
    
    COGL::COGL( int width, int height, bool fullscreen  ) 
    
    :
    
    CWindow
    (
        width,
        height, 
        TEXT("GLTESTING"),
        &WindowProcedure,
        TEXT("GHETTO"),
        fullscreen ? WS_POPUP | WS_MAXIMIZE : WS_OVERLAPPEDWINDOW,
        WS_EX_APPWINDOW | (fullscreen ? 0 : WS_EX_WINDOWEDGE), 
        0,
        CS_VREDRAW | CS_HREDRAW | (fullscreen ? CS_OWNDC : 0)
    ),
    
    m_hRC( 0 ),
    m_hDC( 0 ),
    m_bFullscreen( fullscreen )
    
    {
        initialize();
        show( SW_SHOW );
    }
    
    COGL::~COGL( void ) { kill(); }
    void COGL::swap( void ) const { ::SwapBuffers( m_hDC ); }
    
    void COGL::initialize( void )
    {
        PIXELFORMATDESCRIPTOR    pfd = { 0 };
        unsigned int             pf = 0;
    
        if( isFullscreen() )
        {
            DEVMODE dm = { 0 };
            LONG ret = 0; DWORD i = 0;
    
            dm.dmSize = sizeof(DEVMODE);
            dm.dmDriverExtra = 0;
            
            while( ::EnumDisplaySettings( 0, i, &dm ) )
            {
                if( dm.dmPelsHeight == DWORD(getHeight()) &&
                    dm.dmPelsWidth == DWORD(getWidth()) &&
                    dm.dmBitsPerPel == 32 )
                {
                    ret = 1;
                    break;
                }
                i++;
            }
    
            if(ret)
            {    
                dm.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL;
                ret = ::ChangeDisplaySettings( &dm, CDS_FULLSCREEN );
            }
        }
    
        pfd.nSize      = sizeof(PIXELFORMATDESCRIPTOR);
        pfd.nVersion   = 1;
        pfd.dwFlags    = 
            PFD_DRAW_TO_WINDOW | 
            PFD_SUPPORT_OPENGL | 
            PFD_DOUBLEBUFFER;
    
        pfd.iPixelType = PFD_TYPE_RGBA;
        pfd.cColorBits = 32;
        pfd.cDepthBits = 24;
    
        m_hDC = getDC();
    
        pf = ::ChoosePixelFormat( m_hDC, &pfd );
        ::SetPixelFormat( m_hDC, pf, &pfd );
        m_hRC = ::wglCreateContext( m_hDC );
        ::wglMakeCurrent( m_hDC, m_hRC );
    
        resize( getWidth(), getHeight() );
    }
    
    
    
    void COGL::kill( void )
    {
        ::ChangeDisplaySettings( 0, 0 );
        ::ReleaseDC( getHwnd(), m_hDC );
    
        ::wglMakeCurrent( 0, 0 );
        ::wglDeleteContext( m_hRC );
    }
    
    
    
    void COGL::resize( int width, int height )
    {
        glMatrixMode( GL_PROJECTION );
        glLoadIdentity();
        
        gluPerspective
            ( 45, double(width) / double(height), 0.0f, 2000.0f );
    
        glViewport( 0, 0, width, height );
        glMatrixMode( GL_MODELVIEW );
    
        CWindow::resize( width, height );
    }
    
    
    
    bool COGL::isFullscreen( void ) const { return m_bFullscreen; }
    
    
    CGame::CGame( int width, int height )
    
    :
    
    m_width( width / 2 ), 
    m_height( height / 2 ),
    m_x( gluNewQuadric() )
    
    {
        for( int i = 0; i < 800; ++i )
        {
            m_rgbRates[0][i] = 0.008;
            m_rgbRates[1][i] = 0.01;
            m_rgbRates[2][i] = 0.005;
    
            m_rgb[0][i] = i / 4000.0 + 0.1;
            m_rgb[1][i] = i / 4000.0 + 0.1;
            m_rgb[2][i] = i / 4000.0 + 0.1;
        }
    }
    
    
    
    CGame::~CGame( void )
    {
        gluDeleteQuadric( m_x );
    }
    
    
    
    void CGame::update( double dt )
    {
        for( int i = 0; i < 800; ++i )
        {
            for( int j = 0; j < 3; ++j )
            {
                if( m_rgb[j][i] >= 0.3 || m_rgb[j][i] <= 0.1 )
                {
                    m_rgbRates[j][i] = -m_rgbRates[j][i];
                }
                m_rgb[j][i] += m_rgbRates[j][i];
            }
        }
    }
    
    
    
    void CGame::draw( void ) const
    {
        static double m = 0, rm = 10.0, k = 0, rk = 0.5;
        glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
    
        glMatrixMode( GL_MODELVIEW );
        glLoadIdentity();
    
        gluLookAt( 0, 0, 800 - m, 0, 0, 0, 0, 1, 0 );
        glRotatef( k, 1, 1, 1 );
    
        k += rk;
        m += rm;
    
        if( abs(m) > 800 ) 
            rm = -rm;
    
        for( double i = 1.0; i < 800; i += 2.5 )
        {
            glColor3d( 
                m_rgb[0][ int(i) ], 
                m_rgb[1][ int(i) ], 
                m_rgb[2][ int(i) ] );
    
            gluDisk( m_x, i, i+1, 1000, 2 );
        }
    }
    Last edited by Tonto; 12-24-2006 at 02:30 AM.

    ╔╗╔╦══╦╗╔╦══╦╗
    ║╚╝║╔╗║╚╝║╔╗║║
    ║╔╗║╠╣║╔╗║╠╣╠╣
    ╚╝╚╩╝╚╩╝╚╩╝╚╩╝

    codez http://code.google.com/p/zxcvbn/

  12. #12
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Now that I've seen your example, I don't think the problem is about viewport, screen or perspective, it's probably got more to do with how you're rendering your psychedelic pattern. For example, if you insert a call to glClearColor and set the background to a distinct, non-black colour you can see that viewport and screen match - your pattern is offset so presumably there's an issue with how/where you're doing the actual rendering on the screen.
    Code:
    void COGL::resize( int width, int height )
    {
        glMatrixMode( GL_PROJECTION );
        glLoadIdentity();
        
        gluPerspective
            ( 45, double(width) / double(height), 0.0f, 2000.0f );
    
        glViewport( 0, 0, width, height );
        glMatrixMode( GL_MODELVIEW );
        
        /*changing the background colour(red) shows that screen and viewport
        dimensions match and are as they should be; re-examine drawing algorithm/positioning */
        glClearColor(1.0f,0.0f,0.0f,0.0f); //inserted
    
        CWindow::resize( width, height );
    }
    I'm a bit busy today so I haven't managed to dig into your code much more than that; if I have time later, I'll look again but it may not be for a day or so.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  13. #13
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    The problem seems to be the WS_MAXIMIZE style which you apply by default and is probably responsible for the offset. If that style bit is absent then all appears as I assume you'd like it to appear.

    By way of illustration:
    Code:
    CWindow::CWindow(...): {/*initialiser stuff*/}
    {
        RECT wr = { 0,0,width,height };
    
        //m_style=WS_POPUP; //exclusive WS_POPUP style bit applied
        m_style=m_style&~WS_MAXIMIZE; //strip the WS_MAXIMIZE style bit
        
        ::AdjustWindowRectEx( &wr, m_style, false, m_exStyle );
    
        m_window = ::CreateWindowEx( m_exStyle, m_windowClass.getClassName(), 
            m_windowName, m_style | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, 
            CW_USEDEFAULT, CW_USEDEFAULT, wr.right - wr.left, wr.bottom - wr.top, 
            0, 0, ::GetModuleHandle( 0 ), createParams );
    }
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  14. #14
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    Breaking News: Fitlike Is The Man!

    ╔╗╔╦══╦╗╔╦══╦╗
    ║╚╝║╔╗║╚╝║╔╗║║
    ║╔╗║╠╣║╔╗║╠╣╠╣
    ╚╝╚╩╝╚╩╝╚╩╝╚╩╝

    codez http://code.google.com/p/zxcvbn/

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem opening blank files with ifstream.
    By Sclorch in forum C++ Programming
    Replies: 4
    Last Post: 02-07-2009, 11:43 AM
  2. Problem with deleting completely blank lines
    By dnguyen1022 in forum C Programming
    Replies: 3
    Last Post: 12-07-2008, 11:51 AM
  3. Discarding blank lines?
    By Blurr in forum C++ Programming
    Replies: 3
    Last Post: 12-02-2007, 12:30 PM
  4. Replies: 3
    Last Post: 04-27-2005, 12:50 PM
  5. Check for a blank cd-r
    By waldis in forum C++ Programming
    Replies: 3
    Last Post: 02-23-2003, 06:16 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21