OpenGL draws game role shadow and opengl draws game roles

Source: Internet
Author: User

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:



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.