English 中文(简体)
glDrawElements flicker and crash
原标题:

I m getting a fishy error when using glDrawElements(). I m trying to render simple primitives (mainly rectangles) to speed up drawing of text and so forth, but when I call glDrawElements() the WHOLE screen blinks black (not just my window area) for one frame or so. The next frame it turns back to the same "Windows colors" as before. And so it flickers for a couple of seconds, ending up in a message box saying

The NVIDIA OpenGL Driver encountered an unrecoverable error
and must close this application.

Error 12

Is there any setting for GL which I need to reset before calling glDrawElements()? I know it s not some dangling glEnableClientState(), I checked it (I used to have one of those, but then glDrawElements() crashed instead).

Come to think of it, it almost looks like some back buffer error... Any ideas on what to try?

最佳回答

Obviously you are mixing VBO mode and VA mode. This is perfectly possible but must be use with care.

When you call:

glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);

This means that next time you render something with glDrawElements(..., ..., ..., x), it will use x as a pointer on the indices data, and the last call to glVertexPointer points on the vertices data.

If you don t unbind the current VBO and IBO (with the above two glBindBuffer calls), this means that when rendering with the same glDrawElements, x will be use as an offset on the indices data in the IBO, and the last call to glVertexPointer as an offset on the vertices data in the VBO.

Depending values of x and glVertexPointer you can make the driver crash because the offsets go out of bounds and/or the underlying data is of the wrong type (NaN).

So for answering your question, after drawing with VBO mode and then drawing with VA mode:

  1. unbind the current VBO
  2. unbind the current IBO
  3. specify the right vertices address with glVertexPointer
  4. specify the right indices address with glDrawElements

and then it will be fine.

问题回答

Bah! Found it. When I did

glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);

before rendering the flickering+crashing stopped. Is this the expected behavior? Sorry for wasting time and space.





相关问题
how to reliable capture display setting changed

static void Main() { // Set the SystemEvents class to receive event notification when a user // when display settings change. SystemEvents.DisplaySettingsChanged += new ...

Why use CComBSTR instead of just passing a WCHAR*?

I m new to COM. What exactly is the advantage of replacing: L"String" with CComBSTR(L"String") I can see a changelist in the COM part of my .NET application where all strings are replaced in this ...

COM Basic links

folks can you provide me the tutorial link or .pdf for learning basic COM?. i do google it.. still i recommend answers of stackoverflow so please pass me.. Thanks

Statically linking Winsock?

I m using Winsock 1.1 in my project. I include wsock32.lib in "Additional Dependencies". I m looking at the DLL project using depends.exe and notice that the DLL depends on wsock32.dll. How can I ...

热门标签