<commit_before>#include "helpers.h"
#include <SDL_image.h>
#include "graphics/gl.h"
#include "res_path.h"

void logSDLError(const char *msg){
  printf("%s error: %s\n", msg, SDL_GetError());
}

SDL_Texture* loadTexture(const std::string &file, SDL_Renderer *ren){
  SDL_Texture *texture = IMG_LoadTexture(ren, file.c_str());
  if (texture == nullptr){
    logSDLError("LoadTexture");
  }
  return texture;
}

GLuint loadTexture(const std::string &path) {
  GLuint texture;

  SDL_Surface *surf = IMG_Load((getResourcePath() + path).c_str());
  if (surf == nullptr) {
    logSDLError("IMG_Load");
  }
  glGenTextures(1,&texture);
  glBindTexture(GL_TEXTURE_2D,texture);
  auto fmt = surf->format->BytesPerPixel == 4 ? GL_RGBA : GL_RGB;
  glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, surf->w,surf->h, 0, fmt, GL_UNSIGNED_BYTE,surf->pixels);
  glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
  glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
  SDL_FreeSurface(surf);

  return texture;
}

void renderTexture(SDL_Texture *tex, SDL_Renderer *ren, int x, int y, int w, int h){
  //Setup the destination rectangle to be at the position we want
  SDL_Rect dst;
  dst.x = x;
  dst.y = y;
  dst.w = w;
  dst.h = h;
  SDL_RenderCopy(ren, tex, NULL, &dst);
}

void renderTexture(GLuint texture, float x, float y, float w, float h) {
  renderTexture(texture, x, y, 1, w, h);
}

void renderTexture(GLuint texture, float x, float y, float z, float w, float h) {
  demoloop::Vertex vertices[6];<commit_msg>clamp textures to edge by default<commit_after>#include "helpers.h"
#include <SDL_image.h>
#include "graphics/gl.h"
#include "res_path.h"

void logSDLError(const char *msg){
  printf("%s error: %s\n", msg, SDL_GetError());
}

SDL_Texture* loadTexture(const std::string &file, SDL_Renderer *ren){
  SDL_Texture *texture = IMG_LoadTexture(ren, file.c_str());
  if (texture == nullptr){
    logSDLError("LoadTexture");
  }
  return texture;
}

GLuint loadTexture(const std::string &path) {
  GLuint texture;

  SDL_Surface *surf = IMG_Load((getResourcePath() + path).c_str());
  if (surf == nullptr) {
    logSDLError("IMG_Load");
  }
  glGenTextures(1,&texture);
  glBindTexture(GL_TEXTURE_2D,texture);
  auto fmt = surf->format->BytesPerPixel == 4 ? GL_RGBA : GL_RGB;
  glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, surf->w,surf->h, 0, fmt, GL_UNSIGNED_BYTE,surf->pixels);
  glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
  glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
  glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE);
  glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE);
  SDL_FreeSurface(surf);

  return texture;
}

void renderTexture(SDL_Texture *tex, SDL_Renderer *ren, int x, int y, int w, int h){
  //Setup the destination rectangle to be at the position we want
  SDL_Rect dst;
  dst.x = x;
  dst.y = y;
  dst.w = w;
  dst.h = h;
  SDL_RenderCopy(ren, tex, NULL, &dst);
}

void renderTexture(GLuint texture, float x, float y, float w, float h) {
  renderTexture(texture, x, y, 1, w, h);
}

void renderTexture(GLuint texture, float x, float y, float z, float w, float h) {
  demoloop::Vertex vertices[6];
{'fraction_non_alphanumeric': 0.13659147869674185, 'fraction_numerical': 0.007518796992481203, 'mean_word_length': 5.310276679841897, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, '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': '4129855', 'n_tokens_mistral': 1274, 'n_tokens_neox': 1218, 'n_words': 280}