updated makefile for supporting different target architectures

use "ARCH=arch_name make"

restructured project folder, implementations and headers together under sources/
This commit is contained in:
beno
2026-03-16 00:10:52 +01:00
parent 6c125fb35e
commit bbede61723
73 changed files with 786 additions and 379 deletions

View File

@@ -0,0 +1,28 @@
#include "ClockIterator.hpp"
#include <stdexcept>
ClockIterator::ClockIterator(unsigned int loopMillis) {
if(loopMillis == 0)
throw std::invalid_argument("ClockIterator: loop period must be greater than zero");
reset();
max = loopMillis;
}
void ClockIterator::reset() {
counter = 0;
}
unsigned int ClockIterator::step(unsigned int millis) {
counter += millis;
unsigned int res = counter / max;
counter %= max;
return res;
}
float ClockIterator::getPercentage() {
return (100.0f * counter) / max;
}
unsigned int ClockIterator::getPosition() {
return counter;
}

View File

@@ -0,0 +1,13 @@
#pragma once
class ClockIterator {
private:
unsigned int max;
unsigned int counter;
public:
ClockIterator(unsigned int loopMillis);
unsigned int step(unsigned int millis);
float getPercentage();
unsigned int getPosition();
void reset();
};

View File

@@ -0,0 +1,52 @@
#include "OnlyOnce.hpp"
/*
#include <GL/glew.h>
*/
extern "C" {
#ifndef STB_IMAGE_IMPLEMENTATION
#define STB_IMAGE_IMPLEMENTATION
#endif // !STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"
}
GLuint loadImg(const char* path) {
GLuint texture;
int width, height, nrChannels;
GLenum format;
unsigned char* data;
glGenTextures(1, &texture);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, texture);
//Gestione minification e magnification
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
data = stbi_load(path, &width, &height, &nrChannels, 0);
if (data)
{
if (nrChannels == 3)
format = GL_RGB;
if (nrChannels == 4)
format = GL_RGBA;
glTexImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, format, GL_UNSIGNED_BYTE, data);
glGenerateMipmap(GL_TEXTURE_2D);
printf("Tutto OK %d %d \n", width, height);
}
else
{
printf("LoadImage Errore nel caricare la texture\n");
printf("%s\n", stbi_failure_reason());
}
stbi_image_free(data);
glBindTexture(GL_TEXTURE_2D, 0);
return texture;
}

View File

@@ -0,0 +1,5 @@
#pragma once
#include <GLES2/gl2.h>
GLuint loadImg(const char* path);

View File

@@ -0,0 +1,22 @@
#include "ResourceCache.h"
#include "ShaderMaker.h"
ResourceCache::ResourceCache() {
images = map<string, GLuint>();
shaders = map<string, GLuint>();
}
GLuint ResourceCache::getImage(string path) {
if (images.count(path) == 0) {
images[path] = loadImg(&path[0]);
}
return images.find(path)->second;
}
GLuint ResourceCache::getShader(string vertPath, string fragPath) {
string mapName = string(vertPath).append(fragPath);
if (shaders.count(mapName) == 0) {
shaders[mapName] = ShaderMaker::createProgram(&vertPath[0], &fragPath[0]);
}
return shaders.find(mapName)->second;
}

View File

@@ -0,0 +1,21 @@
#pragma once
#include <string>
#include <vector>
#include <map>
#include "OnlyOnce.hpp"
using namespace std;
class ResourceCache {
private:
ResourceCache ();
map<string, GLuint> images;
map<string, GLuint> shaders;
public:
static ResourceCache& get() {
static ResourceCache instance;
return instance;
}
GLuint getImage(string path);
GLuint getShader(string vertPath, string fragPath);
};

View File

@@ -0,0 +1,100 @@
#include "ShaderMaker.h"
#include <iostream>
#include <fstream>
/* PORCATA AGGIUNTA IN SEGUITO */
#include <stdlib.h>
using namespace std;
char* ShaderMaker::readShaderSource(const char* shaderFile)
{
FILE* fp = fopen(shaderFile, "rb");
if (fp == NULL) { return NULL; }
fseek(fp, 0L, SEEK_END);
long size = ftell(fp);
fseek(fp, 0L, SEEK_SET);
char* buf = new char[size + 1];
fread(buf, 1, size, fp);
buf[size] = '\0';
fclose(fp);
return buf;
}
GLuint ShaderMaker::createProgram(char* vertexfilename, char *fragmentfilename)
{
GLenum ErrorCheckValue = glGetError();
// Creiamo gli eseguibili degli shader
//Leggiamo il codice del Vertex Shader
GLchar* VertexShader = readShaderSource(vertexfilename);
//Visualizzo sulla console il CODICE VERTEX SHADER
std::cout << VertexShader;
std::cout << "MACHEOH\n\n\n\n" << std::endl;
//Generiamo un identificativo per il vertex shader
GLuint vertexShaderId = glCreateShader(GL_VERTEX_SHADER);
//Associamo all'identificativo il codice del vertex shader
glShaderSource(vertexShaderId, 1, (const char**)&VertexShader, NULL);
//Compiliamo il Vertex SHader
glCompileShader(vertexShaderId);
int success;
GLchar infoLog[512];
int logLength;
glGetShaderiv(vertexShaderId, GL_COMPILE_STATUS, &success);
if ( GL_TRUE != success) {
glGetShaderInfoLog(vertexShaderId, 512, &logLength, infoLog);
std::cout << "ERROR::SHADER::VERTEX::COMPILATION_FAILED\n" << infoLog << std::endl;
}
//Leggiamo il codice del Fragment Shader
const GLchar* FragmentShader = readShaderSource(fragmentfilename);
//Visualizzo sulla console il CODICE FRAGMENT SHADER
std::cout << FragmentShader;
//Generiamo un identificativo per il FRAGMENT shader
GLuint fragmentShaderId = glCreateShader(GL_FRAGMENT_SHADER);
glShaderSource(fragmentShaderId, 1, (const char**)&FragmentShader, NULL);
//Compiliamo il FRAGMENT SHader
glCompileShader(fragmentShaderId);
glGetShaderiv(fragmentShaderId, GL_COMPILE_STATUS, &success);
if ( GL_TRUE != success) {
glGetShaderInfoLog(fragmentShaderId, 512, &logLength, infoLog);
std::cout << "ERROR::SHADER::FRAGMENT::COMPILATION_FAILED\n" << infoLog << std::endl;
}
ErrorCheckValue = glGetError();
cout << ErrorCheckValue;
if (ErrorCheckValue != GL_NO_ERROR)
{
fprintf(
stderr,
"ERROR: Could not create the shaders: %s | %x\n",
"(FIX MY SOURCE)",
ErrorCheckValue
);
exit(-1);
}
//Creiamo un identificativo di un eseguibile e gli colleghiamo i due shader compilati
GLuint programId = glCreateProgram();
glAttachShader(programId, vertexShaderId);
glAttachShader(programId, fragmentShaderId);
glLinkProgram(programId);
return programId;
}

View File

@@ -0,0 +1,12 @@
#pragma once
#include <GLES2/gl2.h>
class ShaderMaker
{
public:
static GLuint createProgram(char* vertexfilename, char *fragmentfilename);
static char* readShaderSource(const char* shaderFile);
private:
ShaderMaker() { }
};

7462
sources/GL_STUFF/UTILS/stb_image.h Executable file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff