<commit_before>//
//  BusyRenderer.cpp
//  G3MiOSSDK
//
//  Created by <NAME> on 20/07/12.
//  Copyright (c) 2012 IGO Software SL. All rights reserved.
//


#include <OpenGLES/ES2/gl.h>


#include "BusyRenderer.hpp"

#include "Context.hpp"
#include "GL.hpp"
#include "MutableMatrix44D.hpp"

int __agustin_note; // this function is already implemented in shaders branch
MutableMatrix44D createOrthographicProjectionMatrix(double left, double right,
                                                    double bottom, double top,
                                                    double znear, double zfar) 
{
  // set frustum matrix in double
  const double rl = right - left;
  const double tb = top - bottom;
  const double fn = zfar - znear;
  
  double P[16];
  P[0] = 2 / rl;
  P[1] = P[2] = P[3] = P[4] = 0;
  P[5] = 2 / tb;
  P[6] = P[7] = P[8] = P[9] = 0;
  P[10] = -2 / fn;
  P[11] = 0;
  P[12] = -(right+left) / rl;
  P[13] = -(top+bottom) / tb;
  P[14] = -(zfar+znear) / fn;
  P[15] = 1;
  
  return MutableMatrix44D(P);
}


void BusyRenderer::initialize(const InitializationContext* ic)
{
  unsigned int numVertices = 8;
  int numIndices = 4;
  float x=100, y=150;
  
  float v[] = {
    -x,   y,  0,
    -x,   -y, 0,
    x,    y,  0,
    x,    -y, 0
  };
  
  int i[] = { 0, 1, 2, 3};
  
  // create vertices and indices in dinamic memory
  float *vertices = new float [numVertices*3];
  memcpy(vertices, v, numVertices*3*sizeof(float));
  int *indices = new int [numIndices];
  memcpy(indices, i, numIndices*sizeof(int));  
  
  // create mesh
  Color *flatColor = new Color(Color::fromRGBA(1.0, 1.0, 0.0, 1.0));
  _mesh = IndexedMesh::CreateFromVector3D(true, TriangleStrip, NoCenter, Vector3D(0,0,0), 
                                           4, vertices, indices, 4, flatColor);
}  


int BusyRenderer::render(const RenderContext* rc) 
{  
  GL* gl = rc->getGL();
  
  // init modelview matrix
  GLint currentViewport[4];
  glGetIntegerv(GL_VIEWPORT, currentViewport);
  int halfWidth = currentViewport[2];
  int halfHeight = currentViewport[3];
  MutableMatrix44D M = createOrthographicProjectionMatrix(-halfWidth, halfWidth, -halfHeight, halfHeight, -1, 1);
  gl->setProjection(M);
  gl->loadMatrixf(MutableMatrix44D::identity());
  
  // clear screen
  gl->clearScreen(0.0f, 0.2f, 0.4f, 1.0f);
  
  // draw mesh
  _mesh->render(rc);

  return MAX_TIME_TO_RENDER;
}
<commit_msg>busy renderer is a semitransparent ring<commit_after>//
//  BusyRenderer.cpp
//  G3MiOSSDK
//
//  Created by <NAME> on 20/07/12.
//  Copyright (c) 2012 IGO Software SL. All rights reserved.
//


#include <OpenGLES/ES2/gl.h>


#include "BusyRenderer.hpp"

#include "Context.hpp"
#include "GL.hpp"
#include "MutableMatrix44D.hpp"

int __agustin_note; // this function is already implemented in shaders branch
MutableMatrix44D createOrthographicProjectionMatrix(double left, double right,
                                                    double bottom, double top,
                                                    double znear, double zfar) 
{
  // set frustum matrix in double
  const double rl = right - left;
  const double tb = top - bottom;
  const double fn = zfar - znear;
  
  double P[16];
  P[0] = 2 / rl;
  P[1] = P[2] = P[3] = P[4] = 0;
  P[5] = 2 / tb;
  P[6] = P[7] = P[8] = P[9] = 0;
  P[10] = -2 / fn;
  P[11] = 0;
  P[12] = -(right+left) / rl;
  P[13] = -(top+bottom) / tb;
  P[14] = -(zfar+znear) / fn;
  P[15] = 1;
  
  return MutableMatrix44D(P);
}


void BusyRenderer::initialize(const InitializationContext* ic)
{
  unsigned int numStrides = 60;
  unsigned int numVertices = numStrides * 2 + 2;
  int numIndices = numVertices;
  
  // create vertices and indices in dinamic memory
  float *vertices = new float [numVertices*3];
  int *indices = new int [numIndices];
  float *colors = new float [numVertices*4];
  
  // create vertices
  unsigned int nv=0, ni=0, nc=0;
  float r1=200, r2=230;
  for (unsigned int step=0; step<=numStrides; step++) {
    double angle = (double) step * 2 * M_PI / numStrides;
    double c = cos(angle);
    double s = sin(angle);
    vertices[nv++]  = (float) (r1 * c);
    vertices[nv++]  = (float) (r1 * s);
    vertices[nv++]  = 0.0;
    vertices[nv++]  = (float) (r2 * c);
    vertices[nv++]  = (float) (r2 * s);
    vertices[nv++]  = 0.0;
    indices[ni]     = ni;
    indices[ni+1]   = ni+1;
    ni+=2;    
    float col       = 1.1 * step / numStrides;
    if (col>1) {
      colors[nc++]    = 128;
      colors[nc++]    = 128;
      colors[nc++]    = 128;
      colors[nc++]    = 0;
      colors[nc++]    = 128;
      colors[nc++]    = 128;
      colors[nc++]    = 128;
      colors[nc++]    = 0;      
    } else {
      colors[nc++]    = 128;
      colors[nc++]    = 128;
      colors[nc++]    = 128;
      colors[nc++]    = 1-col;
      colors[nc++]    = 128;
      colors[nc++]    = 128;
      colors[nc++]    = 128;
      colors[nc++]    = 1-col;
    }
  }

  // the two last indices
  indices[ni++]     = 0;
  indices[ni++]     = 1;
  
  // create mesh
  //Color *flatColor = new Color(Color::fromRGBA(1.0, 1.0, 0.0, 1.0));

  _mesh = IndexedMesh::CreateFromVector3D(true, TriangleStrip, NoCenter, Vector3D(0,0,0), 
                                           numVertices, vertices, indices, numIndices, NULL, colors);
}  


int BusyRenderer::render(const RenderContext* rc) 
{  
  GL* gl = rc->getGL();
  
  // init modelview matrix
  GLint currentViewport[4];
  glGetIntegerv(GL_VIEWPORT, currentViewport);
  int halfWidth = currentViewport[2] / 2;
  int halfHeight = currentViewport[3] / 2;
  MutableMatrix44D M = createOrthographicProjectionMatrix(-halfWidth, halfWidth, -halfHeight, halfHeight, -halfWidth, halfWidth);
  gl->setProjection(M);
  gl->loadMatrixf(MutableMatrix44D::identity());
  
  // clear screen
  gl->clearScreen(0.0f, 0.2f, 0.4f, 1.0f);
  
  glEnable(GL_BLEND);
  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  
  gl-

  // draw mesh
  _mesh->render(rc);

  glDisable(GL_BLEND);
  
  return MAX_TIME_TO_RENDER;
}

{'fraction_non_alphanumeric': 0.14939277990351024, 'fraction_numerical': 0.042089502578605886, 'mean_word_length': 2.4551724137931035, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3220321', 'n_tokens_mistral': 2392, 'n_tokens_neox': 2227, 'n_words': 543}