Brandon
Brandon

Reputation: 23515

Can someone explain this OpenGL code please?

I'm trying to reverse a game to see how it works using GLDebugger.. The window size if 765 x 553.

Texture2D 184 looks like: enter image description here

and Texture2D 203 looks like:

enter image description here

The result of the code is (ignore the dollar sign and exclamation mark): enter image description here

The code behind it all is:

glEnable(GL_SCISSOR_TEST)
glScissor(516, 335, 249, 168)
glEnable(GL_SCISSOR_TEST)
glScissor(550, 341, 154, 154)
glDisable(GL_TEXTURE_RECTANGLE)
glEnable(GL_TEXTURE_2D)

glBindTexture(GL_TEXTURE_2D, 184)
glActiveTextureARB(GL_TEXTURE1)
glEnable(GL_TEXTURE_RECTANGLE)
glBindTexture(GL_TEXTURE_RECTANGLE, 203)
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, 7681)
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, 8448)
glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB, 34168)
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, 768)

glBegin(GL_QUADS)
glColor3f(1, 1, 1)
glMultiTexCoord2fARB(GL_TEXTURE0, 0, 1)
glMultiTexCoord2fARB(GL_TEXTURE1, -194.55215, 353.57529)
glVertex2f(355.44785, -141.57529)
glMultiTexCoord2fARB(GL_TEXTURE0, 0, 0)
glMultiTexCoord2fARB(GL_TEXTURE1, -212.4122, -194.13358)
glVertex2f(337.5878, 406.13358)
glMultiTexCoord2fARB(GL_TEXTURE0, 1, 0)
glMultiTexCoord2fARB(GL_TEXTURE1, 335.29663, -211.99362)
glVertex2f(885.29663, 423.99362)
glMultiTexCoord2fARB(GL_TEXTURE0, 1, 1)
glMultiTexCoord2fARB(GL_TEXTURE1, 353.15674, 335.71524)
glVertex2f(903.15674, -123.71524)
glEnd()

I want to know what the above code does because I want to know how such a large map turns into something so tiny :S

Can someone perhaps break it down or use these images or different images or anything at all to explain it?

Upvotes: 3

Views: 392

Answers (1)

coder543
coder543

Reputation: 801

The big thing to recognize is that, quite simply, all this code does is to 'scissor' out the region you're standing in, apply a circular filter on it, and then draw it on the screen.

glEnable is needed in order to use the glScissor command. Why they enable it and use it twice in a row is beyond me. From what I understand, it only needs to be enabled and used once for this code.

We then see the main texture bound to GL_TEXTURE_2D and the smaller one bound to GL_TEXTURE_RECTANGLE. A number of environment flags are set so that the GL_TEXTURE_RECTANGLE being used as a filter produces the right result, by combining certain things and using source and operand on others.

Once we get into glBegin, we begin actually drawing to the screen. glEnd signifies the end of drawing to the screen.

Upvotes: 1

Related Questions