我正在尝试模拟 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 指针。
- 大步。
- 索引指针。