【发布时间】:2013-05-04 06:50:52
【问题描述】:
我正在尝试模拟 OpenGL 的 GL_POINT 进行调试和逆向工程 OpenGL。我正在尝试迭代顶点缓冲区给定它的指针、索引缓冲区指针和步幅。
所以我做了什么:
- 我连接了一个使用 OpenGL 的应用程序。
- 我使用 gDebugger 监控调用 (AMD 为调试创建的应用程序)
要渲染单个模型,调用是:
glPushMatrix()
glViewport(4, 165, 512, 334)
glMultMatrixf({1, 0, 0, 0}
{0, 1, 0, 0}
{0, 0, 1, 0}
{26880, -741, 26368, 1})
glGenBuffersARB(1, 0x0A2B79D4)
glBindBufferARB(GL_ARRAY_BUFFER, 15)
glBufferDataARB(GL_ARRAY_BUFFER, 17460, 0x0C85DE1C, GL_STATIC_DRAW)
glGenBuffersARB(1, 0x0A2B79D4)
glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER, 16)
glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER, 8946, 0x0C85DE1C, GL_STATIC_DRAW)
glBindBufferARB(GL_ARRAY_BUFFER, 0)
glVertexPointer(3, GL_FLOAT, 12, 0x31CB24C9)
glEnableClientState(GL_VERTEX_ARRAY)
glDisableClientState(GL_NORMAL_ARRAY)
glBindBufferARB(GL_ARRAY_BUFFER, 15)
glColorPointer(4, GL_UNSIGNED_BYTE, 12, 0x00000000)
glEnableClientState(GL_COLOR_ARRAY)
glTexCoordPointer(2, GL_FLOAT, 12, 0x00000004)
glEnableClientState(GL_TEXTURE_COORD_ARRAY)
glDrawElements(GL_TRIANGLES, 4473, GL_UNSIGNED_SHORT, 0x00000000)
glPopMatrix()
我挂钩了每个调用并将所有参数存储到一个类和一些变量中。
typedef struct //A struct to hold information about every buffer the application uses.
{
GLint ID;
GLsizei Size;
GLboolean Reserved;
GLboolean Bound;
GLenum Type, Usage;
uint32_t CheckSum;
const GLvoid* BufferPointer;
} BufferObject;
BufferObject CurrentBuffer; //Keep track of the currently bound buffer.
std::vector<BufferObject> ListOfBuffers; //A list of all buffers used in the application.
//Detours the OpenGL function so that it calls this one first before calling the original one. (OpenGL call interception.)
void HookglVertexPointer(GLint size, GLenum type, GLsizei stride, const GLvoid *pointer)
{
if ((size == 3) && (pointer != nullptr) && type == GL_FLOAT) //A model is rendering..
{
ModelRendering = true;
CurrentModel.Stride = stride;
CurrentModel.VertexPointer = pointer; //Store the pointer.
ListOfModels.push_back(CurrentModel); //Store the model.
}
(*original_glVertexPointer) (size, type, stride, pointer); //Call the original function.
}
//Hook the drawing function and get each vertex being rendered.
void HookglDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices)
{
Model* ModelPtr = &ListOfModels.back();
if (ModelPtr != nullptr)
{
for (int I = 0; I < count / 3; ++I) //So for every triangle, I want to get the vertex of it and store it in my Vertices vector..
{
//This needs to somehow use the stride to get the right vertex.
//Perhaps CurrentBuffer.BufferPointer instead of ModelPtr->VertexPointer.
int X = *reinterpret_cast<const GLfloat*>(reinterpret_cast<const char*>(ModelPtr->VertexPointer) * I);
int Y = *reinterpret_cast<const GLfloat*>(reinterpret_cast<const char*>(ModelPtr->VertexPointer) * I + 1);
int Z = *reinterpret_cast<const GLfloat*>(reinterpret_cast<const char*>(ModelPtr->VertexPointer) * I + 2);
ModelPtr->Vertices.push_back(Vector3D(X, Y, Z));
}
}
(*original_glDrawElements) (mode, count, type, indices); //call the original function.
}
如果有的话,如何获取每个三角形的顶点:
- VBO 指针。
- 大步前进。
- 索引指针。
【问题讨论】:
-
我看不出这与
GL_POINTS有什么关系。 -
GL_POINT 在您将它与 glDrawElements 一起使用时会执行此操作。如果我设置 GL_FILL,它会填充整个模型。如果我设置 GL_POINTS,它只会显示每个顶点。我想得到每个顶点,就像函数在使用 GL_POINTS 时所做的那样。我想我正试图弄清楚 gl_drawelements 是如何工作并模拟它的。
-
我仍然对这与
GL_POINTS渲染有什么关系感到困惑。他们正在使用GL_TRIANGLES。您是在谈论 多边形模式,还是在谈论传递给绘图函数的原始类型?