Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1100273
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:51:18+00:00 2026-05-17T00:51:18+00:00

I have an application to show a 2D data MxN with the data value

  • 0

I have an application to show a 2D data MxN with the data value from 0-63. I am displaying it using a colormap which is 64×3.
I would like to do it this way:
Prepare the vertex points, prepare the index array which is the data values. I think this would be the best way which has both the space and performance efficiency. The code would be like this:

 p=colormap_matlab;
 glEnableClientState(GL_VERTEX_ARRAY);
 glEnableClientState(GL_COLOR_ARRAY);
 glEnableClientState(GL_INDEX_ARRAY);
 glVertexPointer(2, GL_INT, 0, vertices);
 glColorPointer(3, GL_FLOAT, 0, p);
 glIndexPointer(GL_UNSIGNED_BYTE,0,color_index);
 int iter = 0;
 int iterP = 0;
 for(i = 0; i < 127; i++)
 {
  iter = 0;
  iterP = 0;
  for(j = 0; j < 1000; j++)
  {
   id1 = (int) data[i*1000+j ];
   id2 = (int) data[(i+1)*1000 + j ];

   color_index[iter++]=id1;
   color_index[iter++]=id2;

   vertices[iterP++] = i;
   vertices[iterP++] = j;
   vertices[iterP++] = i+1;
   vertices[iterP++] = j;

  }

  //glDrawElements(GL_QUAD_STRIP, 999*2, GL_UNSIGNED_INT, indices);
  glDrawArrays(GL_QUAD_STRIP,0,1000*2);
  //glDrawArrays(GL_QUAD_STRIP,500*2,500*2);
 }
 glDisableClientState(GL_VERTEX_ARRAY);
 glDisableClientState(GL_COLOR_ARRAY);
 glDisableClientState(GL_INDEX_ARRAY);

However, it turns out the index pointer array does not work at all. It just draws the color from the colormap sequentially (and will cause data overflow since the colormap is only 64×3).

setting up the context would be like this:

  CSimple_drawView *pView  = (CSimple_drawView* ) pParam;
   HWND hWnd = (pView)->GetSafeHwnd();  
   HDC  hDC ;
   HGLRC hRC;
   hDC = ::GetDC(hWnd);
   SetupPixelFormat(hDC);
   hRC = wglCreateContext( hDC );
   wglMakeCurrent( hDC, hRC );
   readfile(0);
   init_index();
   init_mesh_index();
   int  i = 0;
   all_threads.SetEvent();
   // end added here 
   int startTime = GetTickCount();
    while(i < 200)
    {
        initialize(hWnd);
        //readfile(0);
        WaitForSingleObject(all_threads.m_hObject, INFINITE);
        glLoadIdentity();
        glClear(GL_COLOR_BUFFER_BIT);
        i++;
        Render4(0,count);
        ++count;
        SwapBuffers(hDC);

    }


BOOL SetupPixelFormat(HDC hDC)
{

    PIXELFORMATDESCRIPTOR pixelDesc=
    {
        sizeof(PIXELFORMATDESCRIPTOR),
        1,
        PFD_DRAW_TO_WINDOW|PFD_SUPPORT_OPENGL|
        PFD_DOUBLEBUFFER|PFD_SUPPORT_GDI,
        PFD_TYPE_RGBA,
        24,
        0,0,0,0,0,0,
        0,
        0,
        0,
        0,0,0,0,
        32,
        0,
        0,
        PFD_MAIN_PLANE,
        0,
        0,0,0
    };

    int pixelformat;

    if ( (pixelformat = ChoosePixelFormat(hDC, &pixelDesc)) == 0 )
    {
        MessageBox(NULL, "ChoosePixelFormat failed", "Error", MB_OK);
        return FALSE;
    }

    if (SetPixelFormat(hDC, pixelformat, &pixelDesc) == FALSE)
    {
        MessageBox(NULL, "SetPixelFormat failed", "Error", MB_OK);
        return FALSE;
    }
    return TRUE;

}

Anyone can give me some hints on this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T00:51:18+00:00Added an answer on May 17, 2026 at 12:51 am

    Make sure this doesn’t apply to you:

    glEnableClientState(GL_INDEX_ARRAY)

    What’s wrong with this code?

      glBindBuffer(GL_ARRAY_BUFFER, vboid);
      glVertexPointer(3, GL_FLOAT, sizeof(vertex_format), 0);
      glNormalPointer(GL_FLOAT, sizeof(vertex_format), 20);
      glEnableClientState(GL_VERTEX_ARRAY);
      glEnableClientState(GL_NORMAL_ARRAY);
      glEnableClientState(GL_INDEX_ARRAY);
      glBindBuffer(GL_ELEMENT_ARRAY, iboid);
      glDrawRangeElements(....);
    

    The problem is that GL_INDEX_ARRAY does not mean what this programmer
    thinks it does. GL_INDEX_ARRAY has nothing to do with indices for your
    glDrawRangeElements. This is for color index arrays.

    Never use these. Just use a color array, as follows.

      glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(vertex_format), X);
      glEnableClientState(GL_COLOR_ARRAY);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have created an application which show data from user current location. I want
I am developing an android application in which i have to show data from
In our application, we have some forms which need to show some data specifically
I have an application where I show data from a database. In fact we
I have an application which receives data from a news website (through rss) and
I have a Tabbar - Application and i want to show data (NSString) from
I have an application which downloads some data and I want to show that
I have one web page MyWebPage.aspx which while loading has to show data from
I am developing an android application in which i have to show large data
I have an application using FeedbackPanel to show the user the results of posting

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.