<commit_before>// OpenGL ES 2.0

#include "../include/simple2d.h"

// Triangle shader
static GLuint shaderProgram;
static GLuint positionLocation;
static GLuint colorLocation;

// Texture shader
static GLuint texShaderProgram;
static GLuint texPositionLocation;
static GLuint texColorLocation;
static GLuint texCoordLocation;
static GLuint samplerLocation;

static GLuint indices[] =
  { 0, 1, 2,
    2, 3, 0 };


/*
 * Applies the matrix projection
 */
void S2D_GLES_ApplyProjection(GLfloat orthoMatrix[16]) {
  
  // Use the program object
  glUseProgram(shaderProgram);
  
  GLuint mMvpLocation = glGetUniformLocation(shaderProgram, "u_mvpMatrix");
  glUniformMatrix4fv(mMvpLocation, 1, GL_FALSE, orthoMatrix);
  
  // Use the texture program object
  glUseProgram(texShaderProgram);
  
  GLuint texmMvpLocation = glGetUniformLocation(texShaderProgram, "u_mvpMatrix");
  glUniformMatrix4fv(texmMvpLocation, 1, GL_FALSE, orthoMatrix);
}


/*
 * Initalize OpenGL ES
 */
int S2D_GLES_Init() {
  
  // Enable transparency
  glEnable(GL_BLEND);
  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  
  // Vertex shader source string
  GLchar vertexSource[] =
    // uniforms used by the vertex shader
    "uniform mat4 u_mvpMatrix;"   // model view and projection matrix
    
    // attributes input to the vertex shader
    "attribute vec4 a_position;"  // position value
    "attribute vec4 a_color;"     // input vertex color
    "attribute vec2 a_texcoord;"  // input texture
    
    // varying variables, input to the fragment shader
    "varying vec4 v_color;"       // output vertex color
    "varying vec2 v_texcoord;"    // output texture
    
    "void main()"
    "{"
    "  v_color = a_color;"
    "  v_texcoord = a_texcoord;"
    "  gl_Position = u_mvpMatrix * a_position;"
    "}";
  
  // Fragment shader source string
  GLchar fragmentSource[] =
    // input vertex color from vertex shader
    "varying vec4 v_color;"
    
    "void main()"
    "{"
    "  gl_FragColor = v_color;"
    "}";
  
  // Fragment shader source string for textures
  GLchar texFragmentSource[] =
    // input vertex color from vertex shader
    "varying vec4 v_color;"
    "varying vec2 v_texcoord;"
    "uniform sampler2D s_texture;"
    
    "void main()"
    "{"
    "  gl_FragColor = texture2D(s_texture, v_texcoord) * v_color;"
    "}";
  
  // Load the vertex and fragment shaders
  GLuint vertexShader      = S2D_GL_LoadShader(  GL_VERTEX_SHADER,      vertexSource, "GLES Vertex");
  GLuint fragmentShader    = S2D_GL_LoadShader(GL_FRAGMENT_SHADER,    fragmentSource, "GLES Fragment");
  GLuint texFragmentShader = S2D_GL_LoadShader(GL_FRAGMENT_SHADER, texFragmentSource, "GLES Texture Fragment");
  
  // Triangle Shader //<commit_msg>Add precision for GLES fragment shaders<commit_after>// OpenGL ES 2.0

#include "../include/simple2d.h"

// Triangle shader
static GLuint shaderProgram;
static GLuint positionLocation;
static GLuint colorLocation;

// Texture shader
static GLuint texShaderProgram;
static GLuint texPositionLocation;
static GLuint texColorLocation;
static GLuint texCoordLocation;
static GLuint samplerLocation;

static GLuint indices[] =
  { 0, 1, 2,
    2, 3, 0 };


/*
 * Applies the matrix projection
 */
void S2D_GLES_ApplyProjection(GLfloat orthoMatrix[16]) {
  
  // Use the program object
  glUseProgram(shaderProgram);
  
  GLuint mMvpLocation = glGetUniformLocation(shaderProgram, "u_mvpMatrix");
  glUniformMatrix4fv(mMvpLocation, 1, GL_FALSE, orthoMatrix);
  
  // Use the texture program object
  glUseProgram(texShaderProgram);
  
  GLuint texmMvpLocation = glGetUniformLocation(texShaderProgram, "u_mvpMatrix");
  glUniformMatrix4fv(texmMvpLocation, 1, GL_FALSE, orthoMatrix);
}


/*
 * Initalize OpenGL ES
 */
int S2D_GLES_Init() {
  
  // Enable transparency
  glEnable(GL_BLEND);
  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  
  // Vertex shader source string
  GLchar vertexSource[] =
    // uniforms used by the vertex shader
    "uniform mat4 u_mvpMatrix;"   // model view and projection matrix
    
    // attributes input to the vertex shader
    "attribute vec4 a_position;"  // position value
    "attribute vec4 a_color;"     // input vertex color
    "attribute vec2 a_texcoord;"  // input texture
    
    // varying variables, input to the fragment shader
    "varying vec4 v_color;"       // output vertex color
    "varying vec2 v_texcoord;"    // output texture
    
    "void main()"
    "{"
    "  v_color = a_color;"
    "  v_texcoord = a_texcoord;"
    "  gl_Position = u_mvpMatrix * a_position;"
    "}";
  
  // Fragment shader source string
  GLchar fragmentSource[] =
    "precision mediump float;"
    // input vertex color from vertex shader
    "varying vec4 v_color;"
    
    "void main()"
    "{"
    "  gl_FragColor = v_color;"
    "}";
  
  // Fragment shader source string for textures
  GLchar texFragmentSource[] =
    "precision mediump float;"
    // input vertex color from vertex shader
    "varying vec4 v_color;"
    "varying vec2 v_texcoord;"
    "uniform sampler2D s_texture;"
    
    "void main()"
    "{"
    "  gl_FragColor = texture2D(s_texture, v_texcoord) * v_color;"
    "}";
  
  // Load the vertex and fragment shaders
  GLuint vertexShader      = S2D_GL_LoadShader(  GL_VERTEX_SHADER,      vertexSource, "GLES Vertex");
  GLuint fragmentShader    = S2D_GL_LoadShader(GL_FRAGMENT_SHADER,    fragmentSource, "GLES Fragment");
  GLuint texFragmentShader = S2D_GL_LoadShader(GL_FRAGMENT_SHADER, texFragmentSource, "GLES Texture Fragment");
  
  // Triangle Shader //
{'fraction_non_alphanumeric': 0.09352517985611511, 'fraction_numerical': 0.011151079136690648, 'mean_word_length': 3.420508744038156, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4954091', 'n_tokens_mistral': 1874, 'n_tokens_neox': 1785, 'n_words': 475}