[vtkusers] Re: Scalar color / LookupTable / Interpolation problem...

de Boer Ingo I.deBoer at polytec.de
Tue May 4 09:03:11 EDT 2004


Hi,

>       glutInitDisplayMode: GLUT_RGB (the default) or GLUT_INDEX
I tried that under Windows... GLUT says with GLUT_INDEX:
"pixel format with necessary capabilities not found"
Kinda strange with ATI Radeon 9600 (128MB)

> Ingo, can you search your OpenGL application for "INDEX", 
> perhaps this is how it was done?
Yes, of course... I made a quick&dirty sample here, the result
is shown in the attached image.

> So besides requiring 'major surgery' in the vtk rendering code, use of
> INDEX mode might create a bunch of problems with other desireable OpenGL
> features? A texture map solution might not be so bad after all!?
All I do is:
- SetPixelFormat to PFD_TYPE_COLORINDEX
- Generate a palette for the DC
- use glIndex

I am not so deep into VTK... But the changes cannot be that much ?
I don't know the reaction with other features, like blending and other
stuff...

> It seems that VTK uses its LookupTables only for determining the colors of the 
> cell corners, but does not share this information with OpenGL, and therefore 
> the interior of the cells is rendered by interpolation the RGBA values of the 
> corners.
This fakes the shown results and is not acceptable in my opinion...
Like, I have a value in my color table which is by coincident the same color
as the rgba interpolation between two edges, but has some complete different
value...

greets
  Ingo

---
Dr.-Ing. Ingo H. de Boer

Polytec GmbH
Polytec-Platz 1-7, 76337 Waldbronn, Germany
phone: ++49 7243 604 106
fax  : ++49 7243 604 255

###########################################################################

#include <windows.h>
#include <stdio.h>
#include <GL/gl.h>
#include <GL/glu.h>

LONG WINAPI WndProc(HWND,UINT,WPARAM,LPARAM);
HGLRC SetUpOpenGL(HWND hwnd);
void DrawOpenGLScene(void);
void MakePalette(HWND hWnd);

int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
    static char szAppName[] = "OpenGL";
    static char szTitle[]="Palette Test";
    WNDCLASS wc;
    MSG      msg;
    HWND     hWnd;

    wc.style         = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
    wc.lpfnWndProc   = (WNDPROC)WndProc;
    wc.cbClsExtra    = 0;
    wc.cbWndExtra    = 0;
    wc.hInstance     = hInstance;
    wc.hIcon         = NULL;
    wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
    wc.lpszMenuName  = NULL;
    wc.lpszClassName = szAppName;

    RegisterClass( &wc );
  
    hWnd = CreateWindow(
                szAppName,
                szTitle,
                WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS,
                CW_USEDEFAULT, 0, CW_USEDEFAULT, 0,
                NULL,
                NULL,
                hInstance,
                NULL
        );

    if ( !hWnd )
       return( 0 );

    ShowWindow( hWnd, 1 );
    UpdateWindow( hWnd );

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

    return( msg.wParam );
}


LONG WINAPI WndProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
    HDC hDC;
    static HGLRC hRC;
    PAINTSTRUCT ps;
    GLdouble gldAspect;
    GLsizei glnWidth, glnHeight;

    switch(msg)
    {
    case WM_CREATE:
       hRC = SetUpOpenGL(hWnd);
       MakePalette(hWnd);
       return 0;

    case WM_SIZE:
       hDC = GetDC(hWnd);
       wglMakeCurrent(hDC,hRC);
       glnWidth  = (GLsizei) LOWORD (lParam);
       glnHeight = (GLsizei) HIWORD (lParam);
       gldAspect = (GLdouble)glnWidth/(GLdouble)glnHeight;
       glMatrixMode( GL_PROJECTION );
       glLoadIdentity();
       gluPerspective( 30.0, gldAspect, 1.0, 10.0 );
       glViewport( 0, 0, glnWidth, glnHeight );
       wglMakeCurrent( NULL, NULL );
       ReleaseDC( hWnd, hDC );
       return 0;

   case WM_PAINT:
        hDC = BeginPaint( hWnd, &ps );
        wglMakeCurrent( hDC, hRC );
        DrawOpenGLScene();
        wglMakeCurrent( NULL, NULL );
        EndPaint( hWnd, &ps );
        return 0;
         
   case WM_DESTROY:
        wglDeleteContext( hRC );
        PostQuitMessage( 0 );
        return 0;   
   }
   return DefWindowProc( hWnd, msg, wParam, lParam );
}

HGLRC SetUpOpenGL( HWND hWnd )
{
    static PIXELFORMATDESCRIPTOR pfd = {
        sizeof (PIXELFORMATDESCRIPTOR), // struct size 
        1,                              // Version number
        PFD_DRAW_TO_WINDOW |    // Flags, draw to a window,
        PFD_SUPPORT_OPENGL,     // use OpenGL
        PFD_TYPE_COLORINDEX,    // index pixel values
        24,                     // 24-bit color
        0, 0, 0,                // RGB bits & shift sizes.
        0, 0, 0,                // Don't care about them
        0, 0,                   // No alpha buffer info
        0, 0, 0, 0, 0,          // No accumulation buffer
        32,                     // 32-bit depth buffer
        0,                      // No stencil buffer
        0,                      // No auxiliary buffers
        PFD_MAIN_PLANE,         // Layer type
        0,                      // Reserved (must be 0)
        0,                      // No layer mask
        0,                      // No visible mask
        0                       // No damage mask
    };

    int nMyPixelFormatID;
    HDC hDC;
    HGLRC hRC;
    hDC = GetDC( hWnd );
    nMyPixelFormatID = ChoosePixelFormat( hDC, &pfd );
    SetPixelFormat( hDC, nMyPixelFormatID, &pfd );
    hRC = wglCreateContext( hDC );
    ReleaseDC( hWnd, hDC );

    return hRC;
}


void DrawOpenGLScene( )
{
   glClearIndex(0);
   glClear(GL_COLOR_BUFFER_BIT);
   glMatrixMode(GL_MODELVIEW);
   glLoadIdentity();
   glTranslatef( 0.0f, 0.0f, -5.0f );

   //make triangle
   glBegin(GL_POLYGON);
      glIndexi(0);
      glVertex3f(-0.75, -0.75, 0.0);

      glIndexi(0);
      glVertex3f(0.75, -0.75, 0.0);

      glIndexi(255);
      glVertex3f(0.0, 0.75, 0.0);
   glEnd();
   
   glFlush();
}

void MakePalette(HWND hWnd)
{
   HDC hdc = :: GetDC (hWnd);

   char* chSizePal = new char[2*sizeof(WORD)+ 256*sizeof(PALETTEENTRY)];
   LPLOGPALETTE lpLogPalette = (LPLOGPALETTE) chSizePal;
   lpLogPalette->palVersion = 0x300;
   lpLogPalette->palNumEntries = 256;

   // white for background
   lpLogPalette->palPalEntry[0].peRed   = 255;
   lpLogPalette->palPalEntry[0].peGreen = 255;
   lpLogPalette->palPalEntry[0].peBlue  = 255;
   lpLogPalette->palPalEntry[0].peFlags = PC_NOCOLLAPSE;

   // make red-black-green color table
   for (int i = 1; i < 127; i++)
   {
       lpLogPalette->palPalEntry[i].peRed   = 255-(i-1)*2;
       lpLogPalette->palPalEntry[i].peGreen = 0;
       lpLogPalette->palPalEntry[i].peBlue  = 0;
       lpLogPalette->palPalEntry[i].peFlags = PC_NOCOLLAPSE;
   }
   lpLogPalette->palPalEntry[128].peRed   = 0;
   lpLogPalette->palPalEntry[128].peGreen = 0;
   lpLogPalette->palPalEntry[128].peBlue  = 0;
   lpLogPalette->palPalEntry[128].peFlags = PC_NOCOLLAPSE;
   for (int i = 127; i < 256; i++)
   {
       lpLogPalette->palPalEntry[i].peRed   = 0;
       lpLogPalette->palPalEntry[i].peGreen = (i-127)*2;
       lpLogPalette->palPalEntry[i].peBlue  = 0;
       lpLogPalette->palPalEntry[i].peFlags = PC_NOCOLLAPSE;
   }

   HPALETTE hpal = ::CreatePalette(lpLogPalette);
   ::SelectPalette(hdc, hpal, FALSE);
   ::RealizePalette(hdc);

   delete [] chSizePal;
}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: triangle.png
Type: image/png
Size: 5520 bytes
Desc: triangle.png
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20040504/dd4648dc/attachment.png>


More information about the vtkusers mailing list