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 7603199
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:36:19+00:00 2026-05-30T23:36:19+00:00

I am having an OpenGL VBO problem. I downloaded the old VBO example called

  • 0

I am having an OpenGL VBO problem. I downloaded the old VBO example called Lesson45 from NeHe and I modified it to check something.

My end result is to create about 9 tiles, one of them being the origin. Then as the player moves on the screen, the top/bottom rows/columns update the data. But for now I want something basic:

I create one VBO and then I want to update the data in another thread. While the data is being uploaded, I do not want to draw the VBO because that would cause problems.

Here I create the VBO:

glGenBuffersARB( 1, &m_nVBOVertices );
glBindBufferARB(GL_ARRAY_BUFFER_ARB, m_nVBOVertices);
glBufferDataARB(GL_ARRAY_BUFFER_ARB, m_nVertexCount*3*sizeof(float), m_pVertices, GL_DYNAMIC_DRAW_ARB);

I create a thread, I set up an OpenGL context, I share lists. Then I process the data, when the user presses “R” on the keyboard:

    while(TerrainThreadRun)
    {
        //look for R
        if(window.keys->keyDown[82] == TRUE && keyactivated == false)
        {
            keyactivated = true;
            window.keys->keyDown[82] = FALSE;
        }

        if(keyactivated)
        {
            for(int i = 0; i < g_pMesh->m_nVertexCount; i++)
            {
                g_pMesh->m_pVertices[i].y = 800.0f;
            }
            while(!wglMakeCurrent(window.hDCThread,window.hRCThread))//This was removed
                Sleep(5);//This was removed
            glBindBufferARB(GL_ARRAY_BUFFER_ARB, g_pMesh->m_nVBOVertices);      
            glBufferSubDataARB(GL_ARRAY_BUFFER_ARB, 0, g_pMesh->m_nVertexCount*3*sizeof(float), g_pMesh->m_pVertices);
            keyactivated = false;
        }
    }

To draw the data:

if(!keyactivated)
{
    glEnableClientState( GL_VERTEX_ARRAY );

    glBindBufferARB(GL_ARRAY_BUFFER_ARB, g_pMesh->m_nVBOVertices);
    glVertexPointer(3, GL_FLOAT, 0, (char*)NULL);


    glDrawArrays(GL_TRIANGLES, 0, g_pMesh->m_nVertexCount);

    glDisableClientState(GL_VERTEX_ARRAY);
}

I know that using ARB extensions is not recommended, but this is just for a quick basic example.

The problem is that when I first press “R”, the data does not get updated. The VBO draws the same. The second time that I press “R”, it updates the data. What can I do to force the draw. Am I doing something wrong?

Does the data need to be forced to the video card? Am I missing something?

Update: I looked over my code and now I use wglMakeCurrent only once, when the context is initialized. In the thread, I use it after sharing the lists and on the main thread as soon as the lists are shared, like this:

window->hRC = wglCreateContext (window->hDC);
if (window->hRC ==0)
{
    // Failed
}

TerrainThreadRun = true;
TerrainThread = CreateThread(NULL, NULL,(LPTHREAD_START_ROUTINE)TerrainThreadProc, 0, NULL, NULL);

while(!sharedContext)
    Sleep(100);

if (wglMakeCurrent (window->hDC, window->hRC) == FALSE)

And in the thread:

    if (!(window.hRCThread=wglCreateContext(window.hDCThread)))
    {
//Error
    }

while(wglShareLists(window.hRC, window.hRCThread) == 0)
{
    DWORD err = GetLastError();
    Sleep(5);
}
sharedContext = true;
int cnt = 0;

while(!wglMakeCurrent(window.hDCThread,window.hRCThread))
    Sleep(5);
while(TerrainThreadRun)
{
    //look for R

Second update: I tried using glMapBuffer instead of glBuferSubData, but the application behaves the same. Here is the code:

        void *ptr = (void*)glMapBuffer(GL_ARRAY_BUFFER_ARB, GL_READ_WRITE_ARB);
        if(ptr)
        {
            memcpy(ptr, g_pMesh->m_pVertices, g_pMesh->m_nVertexCount*3*sizeof(float));
            glUnmapMapBuffer(GL_ARRAY_BUFFER_ARB);
        }

Update three:

I was doing some things wrong, so I modified them, but the problem remains the same. Here is how I do everything now:

When the application loads, I create two windows, each with its own HWND. Based on them, I create two device contexts.

Then I share the lists between them:

wglShareLists(window.hRC, window.hRCThread);

This is done only once when I initialize.
After that I show the OGL window, which renders; I make the context active. Then I load the function pointers and create the VBO.
After the main rendering OGL is done, I create the thread. When the thread is loaded, I make its device context active.

Then we do normal stuff.

So my question is: Do I need to update the function pointers for each device context? Could this be my problem?

As an update, if I run my test app in gDEBugger and I first press “R” and then pause, it doesn’t display correctly. I take a look at the memory (Textures, Buffers and Image Viewers) and GLContext1(I think the main rendering thread) device context has the OLD data. While GLContext2 (Shared-GL1) (I think the thread context) has the correct data.

The odd part, if I look back at GLContext1, with the program still in pause mode, now it displays the new data, like it “refreshed” it somehow. And then if I press play, it starts drawing correctly.

  • 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-30T23:36:20+00:00Added an answer on May 30, 2026 at 11:36 pm

    I found the solution, I need to call glFinish() in the worker thread after calling glUnmapBuffer. This will solve the problem and everything will render just fine.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having problem with rendering depth in OpenGL Following code is a simple example
I'm having a slight problem with my SDL/Opengl code, specifically, when i try to
So I just started switching over from SDL to OpenGL today and I'm having
I'm having an OpenGL texture that is binded to a simple quad. My problem
I am learning OpenGL and having a problem with gluPerspective. Here is the code
I'm having a very strange problem with XNA/OpenGL on Windows Phone 7. I'm drawing
I'm having a strange issue with image captures from OpenGL on iOS. I have
i'm having this issue with VBO's that I don't really understand. My problem is
I'm new to OpenGL ES and having a simple kind of problem in my
Having a lot of trouble getting texture maps to work in openGL ES (iphone).

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.