<commit_before>#include <stdio.h>
#include <stdlib.h>
#include "esUtil.h"

typedef struct
{
   // Handle to a render-to-texture program object
   GLuint programObjectRed;
   GLuint programObjectBlue;
   // Handle to a texture-render-to-screen program object
   GLuint programObjectScr;

   // Attribute locations
   GLint  positionLocRed;
   GLint  texCoordLocRed;
   GLint  positionLocBlue;
   GLint  texCoordLocBlue;

   // Sampler location
   GLint samplerLoc;

   // FBO and its buffers handle 
   GLuint    framebuffer;
   GLuint    depthRenderbuffer;
   GLuint    texture;

} UserData;

int InitRedTriangle ( ESContext *esContext )
{
   UserData *userData = esContext->userData;
   GLbyte vShaderStr[] =  
      "attribute vec4 vposition;   \n"
      "void main()                  \n"
      "{                            \n"
      "   gl_Position = vposition; \n"
      "}                            \n";
   
   GLbyte fShaderStr[] =  
      "precision mediump float;                            \n"
      "void main()                                         \n"
      "{                                                   \n"
      "  gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);          \n"
      "}                                                   \n";

   // Load the shaders and get a linked program object
   userData->programObjectRed = esLoadProgram ( vShaderStr, fShaderStr );

   // Bind vPosition to attribute 0   
   glBindAttribLocation ( userData->programObject, 0, "vposition" );

   glClearColor ( 0.0f, 0.0f, 0.0f, 1.0f );
   return TRUE;
}

int InitBlueTriangle ( ESContext *esContext )
{
   UserData *userData = esContext->userData;
   GLbyte vShaderStr[] =  
      "attribute vec4 vposition;   \n"
      "void main()                  \n"
      "{                            \n"
      "   gl_Position = vposition; \n"
      "}                            \n";
   
   GLbyte fShaderStr[] =  
      "precision mediump float;                            \n"
      "void main()                                         \n"
      "{                                                   \n"
      "  gl_FragColor = vec4(0.0, 0.0, 1.0, 1.0);          \n"
      "}                                                   \n";

   // Load the shaders and get a linked program object
   userData->programObjectBlue = esLoadProgram ( vShaderStr, fShaderStr );

   // Bind vPosition to attribute 0   
   glBindAttribLocation ( userData->programObject, 0, "vposition" );

   glClearColor ( 0.0f, 0.0f, 0.0f, 1.0f );
   return TRUE;
}

int Init ( ESContext *esContext )
{
    return InitRedTriangle ( esContext ) && InitBlueTriangle ( esContext );
}
 
///
// Draw the rendered texture back to screen
//
void RenderToScreen ( ESContext *esContext)
{
   UserData *userData = esContext->userData;
   GLfloat vVertices[] = { -0.5f, -0.5f, 0.0f,  // Position 0
                            0.0f,  0.0f,        // TexCoord 0 
                            0.5f, -0.5f, 0.0f,  // Position 1
                            0.0f,  1.0f,        // TexCoord 1
                            0.5f,  0.5f, 0.0f,  // Position 2
                            1.0f,  1.0f,        // TexCoord 2
                           -0.5f,  0.5f, 0.0f,  // Position 3
                            1.0f,  0.0f         // TexCoord 3
                         };
   GLushort indices[] = { 0, 1, 2, 0, 2, 3 };

   GLbyte vShaderStr[] =  
      "attribute vec4 a_position1;   \n"
      "attribute vec2 a_texCoord1;   \n"
      "attribute vec4 a_position2;   \n"
      "attribute vec2 a_texCoord2;   \n"
      "varying vec2 v_texCoord;     \n"
      "void main()                  \n"
      "{                            \n"
      "   gl_Position = a_position; \n"
      "   v_texCoord = a_texCoord;  \n"
      "}                            \n";
   
   GLbyte fShaderStr[] =  
      "precision mediump float;                            \n"
      "varying vec2 v_texCoord;                            \n"
      "uniform sampler2D s_texture;                        \n"
      "void main()                                         \n"
      "{                                                   \n"
      "  gl_FragColor = texture2D( s_texture, v_texCoord );\n"
      "}                                                   \n";

   // Load the shaders and get a linked program object
   userData->programObjectScr = esLoadProgram ( vShaderStr, fShaderStr );

   // Get the attribute locations
   userData->positionLocRed = glGetAttribLocation ( userData->programObjectScr, "a_position1" );
   userData->texCoordLocRed = glGetAttribLocation ( userData->programObjectScr, "a_texCoord1" );
   
   // Get the sampler location
   userData->samplerLoc = glGetUniformLocation ( userData->programObjectScr, "s_texture" );

   // Set the viewport
   glViewport ( 0, 0, esContext->width, esContext->height );
   
   // Clear the color buffer
   glClear ( GL_COLOR_BUFFER_BIT );
<commit_msg>fragment shader completed for multi textures<commit_after>#include <stdio.h>
#include <stdlib.h>
#include "esUtil.h"

typedef struct
{
   // Handle to a render-to-texture program object
   GLuint programObjectRed;
   GLuint programObjectBlue;
   // Handle to a texture-render-to-screen program object
   GLuint programObjectScr;

   // Attribute locations
   GLint  positionLoc;
   GLint  texCoordLoc;

   // Sampler location
   GLint samplerLoc;

   // FBO and its buffers handle 
   GLuint    framebuffer;
   GLuint    depthRenderbuffer;
   GLuint    texture;

} UserData;

int InitRedTriangle ( ESContext *esContext )
{
   UserData *userData = esContext->userData;
   GLbyte vShaderStr[] =  
      "attribute vec4 vposition;   \n"
      "void main()                  \n"
      "{                            \n"
      "   gl_Position = vposition; \n"
      "}                            \n";
   
   GLbyte fShaderStr[] =  
      "precision mediump float;                            \n"
      "void main()                                         \n"
      "{                                                   \n"
      "  gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);          \n"
      "}                                                   \n";

   // Load the shaders and get a linked program object
   userData->programObjectRed = esLoadProgram ( vShaderStr, fShaderStr );

   // Bind vPosition to attribute 0   
   glBindAttribLocation ( userData->programObject, 0, "vposition" );

   glClearColor ( 0.0f, 0.0f, 0.0f, 1.0f );
   return TRUE;
}

int InitBlueTriangle ( ESContext *esContext )
{
   UserData *userData = esContext->userData;
   GLbyte vShaderStr[] =  
      "attribute vec4 vposition;   \n"
      "void main()                  \n"
      "{                            \n"
      "   gl_Position = vposition; \n"
      "}                            \n";
   
   GLbyte fShaderStr[] =  
      "precision mediump float;                            \n"
      "void main()                                         \n"
      "{                                                   \n"
      "  gl_FragColor = vec4(0.0, 0.0, 1.0, 1.0);          \n"
      "}                                                   \n";

   // Load the shaders and get a linked program object
   userData->programObjectBlue = esLoadProgram ( vShaderStr, fShaderStr );

   // Bind vPosition to attribute 0   
   glBindAttribLocation ( userData->programObject, 0, "vposition" );

   glClearColor ( 0.0f, 0.0f, 0.0f, 1.0f );
   return TRUE;
}

int Init ( ESContext *esContext )
{
    return InitRedTriangle ( esContext ) && InitBlueTriangle ( esContext );
}
 
///
// Draw the rendered texture back to screen
//
void RenderToScreen ( ESContext *esContext)
{
   UserData *userData = esContext->userData;
   GLfloat vVertices[] = { -0.5f, -0.5f, 0.0f,  // Position 0
                            0.0f,  0.0f,        // TexCoord 0 
                            0.5f, -0.5f, 0.0f,  // Position 1
                            0.0f,  1.0f,        // TexCoord 1
                            0.5f,  0.5f, 0.0f,  // Position 2
                            1.0f,  1.0f,        // TexCoord 2
                           -0.5f,  0.5f, 0.0f,  // Position 3
                            1.0f,  0.0f         // TexCoord 3
                         };
   GLushort indices[] = { 0, 1, 2, 0, 2, 3 };

   GLbyte vShaderStr[] =  
      "attribute vec4 a_position;   \n"
      "attribute vec2 a_texCoord;   \n"
      "varying vec2 v_texCoord;     \n"
      "void main()                  \n"
      "{                            \n"
      "   gl_Position = a_position; \n"
      "   v_texCoord = a_texCoord;  \n"
      "}                            \n";
   
   GLbyte fShaderStr[] =  
      "precision mediump float;                            \n"
      "varying vec2 v_texCoord;                            \n"
      "uniform sampler2D s_triangle_red;                        \n"
      "uniform sampler2D s_triangle_blue;                        \n"
      "void main()                                         \n"
      "{                                                   \n"
      "  vec4 redTriangle;                                 \n"
      "  vec4 blueTriangle;                                 \n"
      "                                                   \n"
      "  redTriangle = texture2D( s_triangle_red, v_texCoord );\n"
      "  blueTriangle = texture2D( s_triangle_blue, v_texCoord );\n"
      "                                                   \n"
      "  gl_FragColor = redTriangle + blueTriangle\n"
      "}                                                   \n";

   // Load the shaders and get a linked program object
   userData->programObjectScr = esLoadProgram ( vShaderStr, fShaderStr );

   // Get the attribute locations
   userData->positionLoc = glGetAttribLocation ( userData->programObjectScr, "a_position" );
   userData->texCoordLoc = glGetAttribLocation ( userData->programObjectScr, "a_texCoord" );
   
   // Get the sampler location
   userData->positionLoc = glGetUniformLocation ( userData->programObjectScr, "s_triangle_red" );
   userData->texCoordLoc = glGetUniformLocation ( userData->programObjectScr, "s_triangle_blue" );

   // Set the viewport
   glViewport ( 0, 0, esContext->width, esContext->height );
   
   // Clear the color buffer
   glClear ( GL_COLOR_BUFFER_BIT );

{'fraction_non_alphanumeric': 0.10027258566978194, 'fraction_numerical': 0.02102803738317757, 'mean_word_length': 1.2622770314908611, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 48, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5569637', 'n_tokens_mistral': 3136, 'n_tokens_neox': 3000, 'n_words': 735}