Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5933937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:02:38+00:00 2026-05-22T15:02:38+00:00

I have two textures, cloud and hill, each with 512 x 512 size, and

  • 0

I have two textures, cloud and hill, each with 512 x 512 size, and i intend to create a gl_FragColor output which will obtain the pixel values from the previous textures. In this case, i want to obtain the 1st pixel in gl_FragColor from the 1st pixel in the 1st texture, the 2nd pixel in the gl_FragColor from the 2nd pixel in the 2nd texture, the 3rd pixel in gl_FragColor from the 3rd pixel in the 1st texture an so on. Here is my fragment shader code:

 uniform sampler2D tex0;
 uniform sampler2D tex1;

 void main() {
     vec4 cloud = texture2D(tex0, gl_TexCoord[0].st);
     vec4 hill = texture2D(tex1, gl_TexCoord[0].st);
     for (int i=0;i<512;i++) {
       for (int j=0;j<512;j++) {
            if ( j%2 == 0)
                gl_FragColor =  cloud;
            else
                gl_FragColor =  hill;
          }
     }
  }

Here’s the texture unit setup:

t1 = loadTexture("pY.raw", 512, 512);
t2 = loadTexture("pZ.raw", 512, 512);

glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, t2);
glEnable(GL_TEXTURE_2D);

glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, t1);
glEnable(GL_TEXTURE_2D);

And here is the uniform setup:
glUseProgram(program);

GLuint t1Location = glGetUniformLocation(program, "tex0");
GLuint t2Location = glGetUniformLocation(program, "tex1");

glUniform1i(t1Location, 0);
glUniform1i(t2Location, 1);

The problem is, the output for the program is only the hill texture, and i don’t know how to fix this. Any suggestion?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T15:02:39+00:00Added an answer on May 22, 2026 at 3:02 pm

    You don’t need to do any iterations in your shader. Pixel shader will be called once for every pixel in your object. Instead use gl_TexCoord[0] to get current texture coordinates. Your code should look something like that:

    uniform sampler2D tex0;
    uniform sampler2D tex1;
    
    void main()
    {
        vec4 cloud = texture2D(tex0, gl_TexCoord[0].st);
        vec4 hill = texture2D(tex1, gl_TexCoord[0].st);
    
        if ( int(gl_TexCoord[0].x*512)%2 == 0)
            gl_FragColor =  cloud;
        else
            gl_FragColor =  hill;
    
        }
    }
    

    This one should work, even with older opengl:

    #ifdef GL_ES
    precision highp float;
    #endif
    
    uniform sampler2D tex0;
    uniform sampler2D tex1;
    
    void main(void)
    {
    
        if((gl_FragCoord/32.0- vec4(ivec4(gl_FragCoord/32.0))).x<0.5)
            gl_FragColor = texture2D(tex0, gl_FragCoord.xy/512.0);
        else
            gl_FragColor = texture2D(tex1, gl_FragCoord.xy/512.0);
    }
    

    You can try it out with WebGL at: http://www.iquilezles.org/apps/shadertoy/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two textures: background and mask. I need to make output that mask
I am working on a sample in which I have placed two textures one
I have two applications written in Java that communicate with each other using XML
I have two arrays of System.Data.DataRow objects which I want to compare. The rows
I have two webapplication, one is a simple authenticationsite which can authenticate the logged
I have two insert statements, almost exactly the same, which run in two different
I currently have two shaders, a processing shader (both vertex and pixel) - which
I have two arrays of animals (for example). $array = array( array( 'id' =>
I have two elements: <input a> <input b onclick=...> When b is clicked, I
I have two identical tables and need to copy rows from table to another.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.