Multi-texture Mixing

Source: Internet
Author: User
Multi-texture textures

Xiongbincsu@yahoo.com.cn

2007.06.25

About Multi-texture: If a video card supports multi-texture, it means that it can combine several renders for one time. During this rendering process, you can add 0th, 1st, and 2nd objects to be rendered in different texture units. when the program draws a screen, the rendering results are superimposed to display the final results to the screen. each Texture unit has its own texture environment, which specifies the rendered texture image, rendering parameters, filtering parameters, and so on. An important item indicates that, in the process of overlapping rendering results one by one, the content in the current Texture unit is mixed with the previous content. these parameters include:. the source of the texture to be mixed. The source must be specified in two steps: 1. which Texture unit the object comes from [such as gl_texture0, gl_texture1], 2. in this unit, [for example, gl_src_color, gl_one_minus_src_color] B. mixed functions such as gl_add, gl_modulate, and gl_interplate To put it simply, if we want to perform multiple rendering at a time, we need to perform a mathematical operation on the two textures to deliver the results to the screen. Of course, this mathematical operation requires you to specify the operation type, operand source, and operand value, just like the following simple algebraic formula: C = a + B to calculate this result, we first need to specify the operation to be performed (here is +), and then specify the two operands of this operation (here is a and B, for rendering, you need to know which Texture unit they come from ). these parameters are specified by calling gltexenv with different parameters. Then we can perform operations. This C is the final result of our rendering. Specifically, if we want to perform multiple rendering: first, we need to put different texture images in each Texture unit, for example, the image corresponding to texture [0] in unit 0th: dimensions (dimensions); gl_texture_2d); glbindtexture (gl_texture_2d, texture [0]); for example, put the image corresponding to texture [1] In unit 1st: glactivetexturearb (dimensions ); glbindtexture (gl_texture_2d); glbindtexture (gl_texture_2d, texture [1]); then we start to specify our algebra: First tell OpenGL that we need to mix the textures of two units: gltexenvi (gl_texture_env, gl_text Ure_env_mode, gl_combine_arb); then, it tells OpenGL the operation we want to perform: gltexenvi (gl_texture_env, callback, gl_interpolate_arb); here interpolate refers to linear interpolation, and its formula is as follows: C = arg0 * arg2 + arg1 * (1-arg2); it is translated into algebra as follows: C = A * ω + B * (1-ω ); now we can clearly see that it is a linear interpolation expression, where arg0 is the first operand, arg1 is the second operand, and arg2 is the linear interpolation coefficient that is the ω. These parameters must be specified through the following function calls. Of course, the mixed function can also be gl_add "plus", gl_subtract "minus", gl_modulate "multiplication", and so on. in the following example, arg0, arg1, and arg2 are specified: to specify an operand, you must specify the Texture unit from which it comes from, and the part from which it comes from: so we can see below that two sentences are used to specify an arg. The first one specifies the Texture unit from which the content of this operand comes from, the second part specifies the part from the Texture unit: // The first part refers to the gltexenvi (gl_texture_env, gl_source0_rgb_arb, gl_previus_arb) of unit 0 ); // The color part of unit 0 is RGB gltexenvi (gl_texture_env, lag, gl_src_color); // This gl_texture refers to the currently active Texture unit, that is, the gltexenvi (gl_texture_env, gradient, gl_texture); gltexenvi (gl_texture_env, gradient, gl_src_color); // The value gltexenvi (gradient, entropy, entropy) specified by the texture environment variable struct; gltexenvi (gl_texture_env, suffix, gl_src_color); with this, they have completed the designation of the hybrid function. The following thing to do is to add different textures to a geometric image and let them mix according to the above formula: glbegin (gl_quads); glnormal3f (0.0, 0.0, 1.0); glmultitexcoord2farb (California, 0.0, 0.0); glmultitexcoord2farb (California, 0.0, 0.0); glvertex3f (0.0f, 0.0f, 0.0f); glnormal3f (0.0, 0.0, 1.0); glmultitexcoord2farb (California, 0.0, 1.0); glmultitexcoord2farb (California, 0.0, 1.0); glvertex3f (0.0f, 1.0f, 0.0f ); glnormal3f (0.0, 0.0, 1.0); glmultitexcoord2farb (1.0, 1.0); glmultitexcoord2farb (California, 1.0, 1.0); glvertex3f (1.0f, 1.0f, 0.0f); glnormal3f (0.0, 0.0, 1.0); glmultitexcoord2farb (latency, 1.0, 0.0); glmultitexcoord2farb (gl_texture1_arb, 1.0, 0.0); glvertex3f (1.0f, 0.0f, 0.0f); glend (); the above is my understanding, not necessarily accurate. however, the basic steps are clear. welcome to contact me ...... ========================================= ============================== float arr0 [4] = {g_t0blend, g_t0blend, g_t0blend, g_t0blend };
Float arr1 [4] = {g_t1blend, g_t1blend, g_t1blend, g_t1blend };
Float arr2 [4] = {g_t2blend, g_t2blend, g_t2blend, g_t2blend}; If: g_t0blend = 0.5f
G_t1blend = 0.25f
G_t2blend = 0.25frn is the return value of mixer n.
TN is the texture value of Unit N // texture0
Glactivetexturearb (gl_texture0_arb );
Glable (gl_texture_2d );
Glbindtexture (gl_texture_2d, tobjects [to_earth1]); gltexenvi (gl_texture_env, gl_texture_env_mode, gl_combine );
Gltexenvi (gl_texture_env, gl_combine_rgb, gl_modulate); gltexenvi (gl_texture_env, gl_source0_rgb, gl_constant );
Gltexenvi (gl_texture_env, gl_operand0_rgb, gl_src_color );
Gltexenvfv (gl_texture_env, gl_texture_env_color, arr0); gltexenvi (gl_texture_env, gl_source1_rgb, gl_texture );
Gltexenvi (gl_texture_env, gl_operand1_rgb, gl_src_color); the preceding operations for Texture unit 0 are as follows:
R0 = 0.5 * t0 // texture1
Glactivetexturearb (gl_texturew.arb );
Glable (gl_texture_2d );
Glbindtexture (gl_texture_2d, tobjects [to_earth1]); gltexenvi (gl_texture_env, gl_texture_env_mode, gl_combine );
Gltexenvi (gl_texture_env, gl_combine_rgb, gl_interpolate); gltexenvi (gl_texture_env, gl_source0_rgb, gl_texture );
Gltexenvi (gl_texture_env, gl_operand0_rgb, gl_src_color); gltexenvi (gl_texture_env, gl_source1_rgb, gl_previous );
Gltexenvi (gl_texture_env, gl_operand1_rgb, gl_src_color); gltexenvi (gl_texture_env, gl_source2_rgb, gl_constant );
Gltexenvi (gl_texture_env, gl_operand2_rgb, gl_src_color );
Gltexenvfv (gl_texture_env, gl_texture_env_color, arr1); the corresponding formula is
R1 = (0.25 * T1) + (1-0.25) * R0) = 0.25 * t1 + 0.375 * t0 // texture2
Glactivetexturearb (gl_texture2_arb );
Glable (gl_texture_2d );
Glbindtexture (gl_texture_2d, tobjects [to_ear2]); gltexenvi (gl_texture_env, gl_texture_env_mode, gl_combine );
Gltexenvi (gl_texture_env, gl_combine_rgb, gl_interpolate );
Gltexenvi (gl_texture_env, gl_source0_rgb, gl_texture );
Gltexenvi (gl_texture_env, gl_operand0_rgb, gl_src_color );
Gltexenvi (gl_texture_env, gl_source1_rgb, gl_previous );
Gltexenvi (gl_texture_env, gl_operand1_rgb, gl_src_color );
Gltexenvi (gl_texture_env, gl_source2_rgb, gl_constant );
Gltexenvi (gl_texture_env, gl_operand2_rgb, gl_src_color );
Gltexenvfv (gl_texture_env, gl_texture_env_color, arr2); formula: r2 = (0.25 * t2) + (1-0.25) * R1) = 0.25 * t2 + 0.1875 * t1 + 0.2813 * t0

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.