cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

francis77
Journeyman III

Black stripes flashing in OpenGL

When I run my program, I get black stripes flashing on the screen.  Can someone tell me what may be wrong ? 

If you need some code, tell me.  This is how I initialize my pixel format :

 

BOOL InitPixelFormatARB(HDC hDC, int iBPP, PIXELFORMATDESCRIPTOR *pfd)
{

    BOOL Result;
    int accumBits = 0;

    int iAttribs[17] = {
        WGL_DRAW_TO_WINDOW_ARB, GL_TRUE,
        WGL_ACCELERATION_ARB,   WGL_FULL_ACCELERATION_ARB,
        WGL_DOUBLE_BUFFER_ARB,  GL_TRUE,
        WGL_COLOR_BITS_ARB,     pfd->cColorBits,
        WGL_DEPTH_BITS_ARB,     pfd->cDepthBits,
        WGL_STENCIL_BITS_ARB,   pfd->cStencilBits,
        WGL_ACCUM_BITS_ARB,     accumBits
    };

    int formats[256];
    unsigned int nformats;
    wglChoosePixelFormatARB(hDC, iAttribs, NULL, sizeof(formats) / sizeof(int), formats, &nformats);
    Result = SetPixelFormat(hDC, formats[0], pfd);

    return Result;
}

 

Tags (1)
0 Likes
4 Replies
gsellers
Staff
Staff

Black stripes flashing in OpenGL

Hi,

This sounds like it could be a driver bug, but there's not enough code there to be sure. What you have written looks fine. Is there any way that you can send us a more complete example that we can test with. We can use it to either let you know what you need to do differently or diagnose and fix the issue if it's our problem.

Thanks,

Graham

0 Likes
francis77
Journeyman III

Black stripes flashing in OpenGL

You said it may be a driver problem, I am using Catalyst version 2009.0929.2222.38284, I don't remember whether it was Catalyst 9 or 10.  My graphics card is a Radeon 9600.

What follows is what I use to initialize OpenGL.  I am only including this because the rest does not seem to have an influence on my issue.  Let me know if you need something else.

 

 

 

#include <windows.h>
#pragma hdrstop

#include <tchar.h>
#include <sys\timeb.h>
#include <float.h>                // _control87(MCW_EM, MCW_EM);
#include <gl/gl.h>
#include "resource.h"
#include "initGL.h"
#include "GLExtensions.h"


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

#pragma comment( lib, "opengl32.lib" )

/* Prototypes... */

LRESULT APIENTRY WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
BOOL InitOpenGLAPI(HWND hWnd, HDC hDC);
void InitEntryPoints(HWND hwnd, const PIXELFORMATDESCRIPTOR &pfd);
BOOL InitPixelFormatARB(HDC hDC, int iBPP, PIXELFORMATDESCRIPTOR *pfd);
static BOOL PrepareOpenGL(HANDLE, RECT *clientrect);


/* Globals... */
HWND hWnd;
HINSTANCE hInst;

#pragma argsused
WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
    char           AppName[] = "GL";
    MSG            msg;
    WNDCLASS       wndclass;
    HMODULE        Module = NULL;

    hInst = hInstance;

    _control87(MCW_EM, MCW_EM);

    if (!hPrevInstance)
    {
        wndclass.style         = 0;
        wndclass.lpfnWndProc   = WndProc;
        wndclass.cbClsExtra    = 0;
        wndclass.cbWndExtra    = 0;
        wndclass.hInstance     = hInstance;
        wndclass.hIcon         = NULL;
        wndclass.hCursor       = LoadCursor(NULL, IDC_ARROW);
        wndclass.hbrBackground = (HBRUSH) GetStockObject(BLACK_BRUSH);
        wndclass.lpszMenuName  = MAKEINTRESOURCE(IDR_MENU1);
        wndclass.lpszClassName = "GL";

        RegisterClass (&wndclass) ;
    }

    hWnd = CreateWindow (AppName, "GL",
                        WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
                        CW_USEDEFAULT, CW_USEDEFAULT,
                        CW_USEDEFAULT, CW_USEDEFAULT,
                        HWND_DESKTOP, NULL, hInstance, NULL);

    ShowWindow(hWnd, nCmdShow);
    UpdateWindow(hWnd);

    while (GetMessage(&msg, NULL, 0, 0))
    {
        TranslateMessage(&msg);
        DispatchMessage(&msg);
    }

    return msg.wParam;
}

LRESULT APIENTRY WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    HDC hDC = NULL;
    PIXELFORMATDESCRIPTOR pfd;

    switch (message)
    {
        case WM_CREATE:
            hDC = GetDC(hWnd);

            InitOpenGLAPI(hWnd, hDC);

            return 0;
        ...
    }

    return DefWindowProc(hWnd, message, wParam, lParam);

}


BOOL InitOpenGLAPI(HWND hWnd, HDC hDC)
{
    HGLRC hRC = NULL;
    BOOL bResult;
    HINSTANCE hInst;

    PIXELFORMATDESCRIPTOR pfdARB = {sizeof (PIXELFORMATDESCRIPTOR),    1,
                    PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,    PFD_TYPE_RGBA,
                    8,
                    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
                    24, 8,
                    0, PFD_MAIN_PLANE, 0, 0, 0, 0
                };
    HWND hWnd;

    hInst = (HINSTANCE) (LONG_PTR) GetWindowLongPtr(hWnd, GWLP_HINSTANCE);
    WNDCLASS wincl;
    wincl.hInstance = hInst;
    wincl.lpszClassName = "GLA";
    wincl.lpfnWndProc = DefWindowProc;
    wincl.style = 0;
    wincl.hIcon = NULL;
    wincl.hCursor = NULL;
    wincl.lpszMenuName = NULL;
    wincl.cbClsExtra = 0;
    wincl.cbWndExtra = 0;
    wincl.hbrBackground = NULL;
    RegisterClass(&wincl);

    hWnd = CreateWindow("GLAPI", "GLA", WS_POPUP | WS_CLIPCHILDREN | WS_CLIPSIBLINGS, 0, 0, 8, 8, HWND_DESKTOP, NULL, hInst, NULL);
    InitEntryPoints(hWnd, pfdARB);

    SendMessage(hWnd, WM_CLOSE, 0, 0);

    if (InitPixelFormatARB(hDC, GetDeviceCaps(hDC, BITSPIXEL) * GetDeviceCaps(hDC, PLANES), &pfdARB))
    {
        hRC = wglCreateContext(hDC);

        bResult = wglMakeCurrent(hDC, hRC);
        if (bResult)
        {
            initExtensions();
            initWGLExtensions(hDC);
        }
    }

    return bResult;
}


void InitEntryPoints(HWND hwnd, const PIXELFORMATDESCRIPTOR &pfd){
    HDC hdc = GetDC(hwnd);
    SetPixelFormat(hdc, ChoosePixelFormat(hdc, &pfd), &pfd);

    HGLRC hglrc = wglCreateContext(hdc);
    wglMakeCurrent(hdc, hglrc);
    initWGLExtensions(hdc);

    wglMakeCurrent(NULL, NULL);
    wglDeleteContext(hglrc);
    ReleaseDC(hwnd, hdc);
}

BOOL InitPixelFormatARB(HDC hDC, int iBPP, PIXELFORMATDESCRIPTOR *pfd)
{

    BOOL Result;
    int accumBits = 0;

    int iAttribs[17] = {
        WGL_DRAW_TO_WINDOW_ARB, GL_TRUE,
        WGL_ACCELERATION_ARB,   WGL_FULL_ACCELERATION_ARB,
        WGL_DOUBLE_BUFFER_ARB,  GL_TRUE,
        WGL_COLOR_BITS_ARB,     pfd->cColorBits,
        WGL_DEPTH_BITS_ARB,     pfd->cDepthBits,
        WGL_STENCIL_BITS_ARB,   pfd->cStencilBits,
        WGL_ACCUM_BITS_ARB,     accumBits
    };

    int formats[256];
    unsigned int nformats;
    wglChoosePixelFormatARB(hDC, iAttribs, NULL, sizeof(formats) / sizeof(int), formats, &nformats); Result = SetPixelFormat(hDC, formats[0], pfd);

   return Result

}


static BOOL PrepareOpenGL(HANDLE hWnd, RECT *clientrect)
{
    if (clientrect->bottom <= 0)
        return FALSE;

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glFrustum(-1.0, 1.0, -1.0, 1.0, 1.5, 20.0);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    glTranslatef(0.0f, 0.0f, -20.0f);

    glViewport(0, 0, clientrect->right - clientrect->left, clientrect->bottom - clientrect->top);

    Initialize();

    return TRUE;
}

0 Likes
mmonir_09
Journeyman III

Black stripes flashing in OpenGL

This tutorial will explain drawing every possible type of primitive in OpenGL except points and lines because they are trivial to understand. If you are still a bit

0 Likes
francis77
Journeyman III

Black stripes flashing in OpenGL

What tutorial are you talking about ?

0 Likes