OpenGL draws game role shadow and opengl draws game roles
In game development, many Q-version games simply draw a translucent elliptical shadow, such:
The advantage of this method is that the implementation is simple, but the performance is obviously not true. As a Q-version style, it is acceptable for gamers. For real-time writing games, they mostly use images provided by art as shadow layers. This solution has the best effect. The disadvantage is that you need to make a large amount of image resources to increase the number of game packages.
In recent development, I came up with another method to draw a role shadow image. Here I will share it with you.
The principle is very simple. It is to use OpenGL's image deformation technology to adjust the role's image to make it a shadow image.
First:
Specific implementation:
OpenGL Image Rendering code
GLfloat vertex [8] = {exRatio, syRatio, sxRatio, syRatio, exRatio, eyRatio, sxRatio, eyRatio}; glBindTexture (vertex, texId); glVertexPointer (2, GL_FLOAT, 0, glVertices); glTexCoordPointer (2, GL_FLOAT, 0, textureCoords); glDrawArrays (GL_TRIANGLE_STRIP, 0, 4 );
The array textureCoords is the parameter used to draw the image shape. By changing these parameters, the image is halved along the Y axis, and the distance between the two vertices along the X axis is shifted to half the image to make the image shape.
However, this cannot completely achieve the effect, because the image is only a shape change, and the image is still a role image. We need to change it to black and translucent.
You only need to set glColor4f (0.0, 0.0, 0.0, 0.6.
Finally, the effect is drawn to the role: