Merge commit '7621e2f8dec938cf48181c8b10afc9b01f444e68' into beta

This commit is contained in:
Ilya Laktyushin
2025-12-06 02:17:48 +04:00
commit 8344b97e03
28070 changed files with 7995182 additions and 0 deletions
File diff suppressed because it is too large Load Diff
+44
View File
@@ -0,0 +1,44 @@
//
// animations.h
// IntroOpenGL
//
// Created by Ilya Rimchikov on 29/03/14.
// Copyright (c) 2014 IntroOpenGL. All rights reserved.
//
void on_surface_created();
void on_surface_changed(int a_width_px, int a_height_px, float a_scale_factor, int a1, int a2, int a3, int a4, int a5);
void on_draw_frame();
void set_touch_x(int a);
void set_date(double a);
void set_date0(double a);
void set_page(int page);
void set_pages_textures(int a1, int a2, int a3, int a4, int a5, int a6);
void set_ic_textures(int a_ic_bubble_dot, int a_ic_bubble, int a_ic_cam_lens, int a_ic_cam, int a_ic_pencil, int a_ic_pin, int a_ic_smile_eye, int a_ic_smile, int a_ic_videocam);
void set_telegram_textures(int a_telegram_sphere, int a_telegram_plane);
void set_fast_textures(int a_fast_body, int a_fast_spiral, int a_fast_arrow, int a_fast_arrow_shadow);
void set_free_textures(int a_knot_up, int a_knot_down);
void set_powerful_textures(int a_powerful_mask, int a_powerful_star, int a_powerful_infinity, int a_powerful_infinity_white);
void set_private_textures(int a_private_door, int a_private_screw);
void set_y_offset(float a);
void set_scroll_offset(float a_offset);
void inc_stars_rendered();
void set_elements_top_margins(int a_icon_y, int a_text_y, int a_button_y);
void set_intro_background_color(float r, float g, float b);
+19
View File
@@ -0,0 +1,19 @@
#include "buffer.h"
#include "platform_gl.h"
#include <assert.h>
#include <stdlib.h>
GLuint create_vbo(const GLsizeiptr size, const GLvoid* data, const GLenum usage) {
assert(data != NULL);
GLuint vbo_object;
glGenBuffers(1, &vbo_object);
assert(vbo_object != 0);
glBindBuffer(GL_ARRAY_BUFFER, vbo_object);
//glBufferData (GLenum target, GLsizeiptr size, const GLvoid* data, GLenum usage)
glBufferData(GL_ARRAY_BUFFER, size, data, usage);
glBindBuffer(GL_ARRAY_BUFFER, 0);
return vbo_object;
}
+6
View File
@@ -0,0 +1,6 @@
#include "platform_gl.h"
#define BUFFER_OFFSET(i) ((void*)(i))
GLuint create_vbo(const GLsizeiptr size, const GLvoid* data, const GLenum usage);
GLuint create_vbo2(const GLsizeiptr vertex_data_size, const GLvoid* vertex_data, const GLsizeiptr color_data_size, const GLvoid* color_data, const GLenum usage);
+1
View File
@@ -0,0 +1 @@
#define UNUSED(x) (void)(x)
+13
View File
@@ -0,0 +1,13 @@
#include <math.h>
static inline float deg_to_radf(float deg) {
return deg * (float)M_PI / 180.0f;
}
static inline double MAXf(float a, float b) {
return a > b ? a : b;
}
static inline double MINf(float a, float b) {
return a < b ? a : b;
}
+100
View File
@@ -0,0 +1,100 @@
#include "linmath.h"
#include <math.h>
#include <string.h>
/* Adapted from Android's OpenGL Matrix.java. */
static inline void mat4x4_perspective(mat4x4 m, float y_fov_in_degrees, float aspect, float n, float f)
{
const float angle_in_radians = (float) (y_fov_in_degrees * M_PI / 180.0);
const float a = (float) (1.0 / tan(angle_in_radians / 2.0));
m[0][0] = a / aspect;
m[1][0] = 0.0f;
m[2][0] = 0.0f;
m[3][0] = 0.0f;
m[1][0] = 0.0f;
m[1][1] = a;
m[1][2] = 0.0f;
m[1][3] = 0.0f;
m[2][0] = 0.0f;
m[2][1] = 0.0f;
m[2][2] = -((f + n) / (f - n));
m[2][3] = -1.0f;
m[3][0] = 0.0f;
m[3][1] = 0.0f;
m[3][2] = -((2.0f * f * n) / (f - n));
m[3][3] = 0.0f;
}
static inline void mat4x4_translate_in_place(mat4x4 m, float x, float y, float z)
{
int i;
for (i = 0; i < 4; ++i) {
m[3][i] += m[0][i] * x
+ m[1][i] * y
+ m[2][i] * z;
}
}
static inline void mat4x4_look_at(mat4x4 m,
float eyeX, float eyeY, float eyeZ,
float centerX, float centerY, float centerZ,
float upX, float upY, float upZ)
{
// See the OpenGL GLUT documentation for gluLookAt for a description
// of the algorithm. We implement it in a straightforward way:
float fx = centerX - eyeX;
float fy = centerY - eyeY;
float fz = centerZ - eyeZ;
// Normalize f
vec3 f_vec = {fx, fy, fz};
float rlf = 1.0f / vec3_len(f_vec);
fx *= rlf;
fy *= rlf;
fz *= rlf;
// compute s = f x up (x means "cross product")
float sx = fy * upZ - fz * upY;
float sy = fz * upX - fx * upZ;
float sz = fx * upY - fy * upX;
// and normalize s
vec3 s_vec = {sx, sy, sz};
float rls = 1.0f / vec3_len(s_vec);
sx *= rls;
sy *= rls;
sz *= rls;
// compute u = s x f
float ux = sy * fz - sz * fy;
float uy = sz * fx - sx * fz;
float uz = sx * fy - sy * fx;
m[0][0] = sx;
m[0][1] = ux;
m[0][2] = -fx;
m[0][3] = 0.0f;
m[1][0] = sy;
m[1][1] = uy;
m[1][2] = -fy;
m[1][3] = 0.0f;
m[2][0] = sz;
m[2][1] = uz;
m[2][2] = -fz;
m[2][3] = 0.0f;
m[3][0] = 0.0f;
m[3][1] = 0.0f;
m[3][2] = 0.0f;
m[3][3] = 1.0f;
mat4x4_translate_in_place(m, -eyeX, -eyeY, -eyeZ);
}
File diff suppressed because it is too large Load Diff
+177
View File
@@ -0,0 +1,177 @@
//
// objects.h
// IntroOpenGL
//
// Created by Ilya Rimchikov on 29/03/14.
// Copyright (c) 2014 IntroOpenGL. All rights reserved.
//
#include "platform_gl.h"
#include "program.h"
#include "linmath.h"
extern float scale_factor;
extern int width, height;
extern int y_offset_absolute;
typedef enum {NORMAL, NORMAL_ONE, RED, BLUE, LIGHT_RED, LIGHT_BLUE, DARK, LIGHT, DARK_BLUE} texture_program_type;
typedef struct {
float x;
float y;
} CPoint;
typedef struct {
float width;
float height;
} CSize;
typedef struct {
float r;
float g;
float b;
float a;
} CColor;
CPoint CPointMake(float x, float y);
CSize CSizeMake(float width, float height);
float D2R(float a);
float R2D(float a);
typedef struct {
float x;
float y;
float z;
} xyz;
xyz xyzMake(float x, float y, float z);
typedef struct {
float side_length;
float start_angle;
float end_angle;
float angle;
CSize size;
float radius;
float width;
} VarParams;
typedef struct {
int datasize;
int round_count;
GLenum triangle_mode;
int is_star;
} ConstParams;
typedef struct {
xyz anchor;
xyz position;
float rotation;
xyz scale;
} LayerParams;
typedef struct {
xyz anchor;
xyz position;
float rotation;
xyz scale;
float alpha;
VarParams var_params;
ConstParams const_params;
LayerParams *layer_params;
} Params;
typedef struct {
vec4 color;
CPoint *data;
GLuint buffer;
int num_points;
Params params;
} Shape;
typedef struct {
GLuint texture;
CPoint *data;
GLuint buffer;
int num_points;
Params params;
} TexturedShape;
Params default_params();
LayerParams default_layer_params();
void mat4x4_translate_independed(mat4x4 m, float x, float y, float z);
void set_y_offset_objects(float a);
void setup_shaders();
void draw_shape(const Shape* shape, mat4x4 view_projection_matrix);
void draw_colored_shape(const Shape* shape, mat4x4 view_projection_matrix, vec4 color);
void draw_textured_shape(const TexturedShape* shape, mat4x4 view_projection_matrix, texture_program_type program_type);
TexturedShape create_segmented_square(float side_length, float start_angle, float end_angle, GLuint texture);
void change_segmented_square(TexturedShape* shape, float side_length, float start_angle, float end_angle);
Shape create_rounded_rectangle(CSize size, float radius, int round_count, const vec4 color);
void change_rounded_rectangle(Shape* shape, CSize size, float radius);
Shape create_rectangle(CSize size, const vec4 color);
Shape create_circle(float radius, int vertex_count, const vec4 color);
void change_circle(Shape* shape, float radius);
void draw_colored_rectangle(const Shape* shape, mat4x4 view_projection_matrix);
TexturedShape create_textured_rectangle(CSize size, GLuint texture);
void change_textured_rectangle(TexturedShape* shape, CSize size);
Shape create_ribbon(float length, const vec4 color);
void change_ribbon(Shape* shape, float length);
Shape create_segmented_circle(float radius, int vertex_count, float start_angle, float angle, const vec4 color);
void change_segmented_circle(Shape* shape, float radius, float start_angle, float angle);
Shape create_infinity(float width, float angle, int segment_count, const vec4 color);
void change_infinity(Shape* shape, float angle);
void draw_infinity(const Shape* shape, mat4x4 view_projection_matrix);
Shape create_rounded_rectangle_stroked(CSize size, float radius, float stroke_width, int round_count, const vec4 color);
void change_rounded_rectangle_stroked(Shape* shape, CSize size, float radius, float stroke_width);
Shape create_rounded_rectangle(CSize size, float radius, int round_count, const vec4 color);
void change_rounded_rectangle(Shape* shape, CSize size, float radius);
void mat4x4_log(mat4x4 M);
+38
View File
@@ -0,0 +1,38 @@
#include "program.h"
#include "platform_gl.h"
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
TextureProgram get_texture_program(GLuint program)
{
return (TextureProgram) {
program,
glGetAttribLocation(program, "a_Position"),
glGetAttribLocation(program, "a_TextureCoordinates"),
glGetUniformLocation(program, "u_MvpMatrix"),
glGetUniformLocation(program, "u_TextureUnit"),
glGetUniformLocation(program, "u_Alpha")};
}
ColorProgram get_color_program(GLuint program)
{
return (ColorProgram) {
program,
glGetAttribLocation(program, "a_Position"),
glGetUniformLocation(program, "u_MvpMatrix"),
glGetUniformLocation(program, "u_Color"),
glGetUniformLocation(program, "u_Alpha")};
}
GradientProgram get_gradient_program(GLuint program)
{
return (GradientProgram) {
program,
glGetAttribLocation(program, "a_Position"),
glGetUniformLocation(program, "u_MvpMatrix"),
glGetAttribLocation(program, "a_Color"),
glGetUniformLocation(program, "u_Alpha")};
}
#pragma clang diagnostic pop
+37
View File
@@ -0,0 +1,37 @@
#pragma once
#include "platform_gl.h"
typedef struct {
GLuint program;
GLint a_position_location;
GLint a_texture_coordinates_location;
GLint u_mvp_matrix_location;
GLint u_texture_unit_location;
GLint u_alpha_loaction;
} TextureProgram;
typedef struct {
GLuint program;
GLint a_position_location;
GLint u_mvp_matrix_location;
GLint u_color_location;
GLint u_alpha_loaction;
} ColorProgram;
typedef struct {
GLuint program;
GLint a_position_location;
GLint u_mvp_matrix_location;
GLint a_color_location;
GLint u_alpha_loaction;
} GradientProgram;
TextureProgram get_texture_program(GLuint program);
ColorProgram get_color_program(GLuint program);
GradientProgram get_gradient_program(GLuint program);
+19
View File
@@ -0,0 +1,19 @@
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include "rngs.h"
float frand(float from, float to)
{
return (float)(((double)random()/RAND_MAX)*(to-from)+from);
}
int irand(int from, int to)
{
return (int)(((double)random()/RAND_MAX)*(to-from+1)+from);
}
int signrand()
{
return irand(0, 1)*2-1;
}
+7
View File
@@ -0,0 +1,7 @@
int irand(int from, int to);
float frand(float from, float to);
int signrand();
+119
View File
@@ -0,0 +1,119 @@
#include "shader.h"
#include "platform_gl.h"
#include "platform_log.h"
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#define TAG "shaders"
#ifndef LOGGING_ON
#define LOGGING_ON 0
#endif
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
static void log_v_fixed_length(const GLchar* source, const GLint length) {
if (LOGGING_ON) {
char log_buffer[length + 1];
memcpy(log_buffer, source, length);
log_buffer[length] = '\0';
DEBUG_LOG_WRITE_V(TAG, log_buffer);
}
}
static void log_shader_info_log(GLuint shader_object_id) {
if (LOGGING_ON) {
GLint log_length;
glGetShaderiv(shader_object_id, GL_INFO_LOG_LENGTH, &log_length);
GLchar log_buffer[log_length];
glGetShaderInfoLog(shader_object_id, log_length, NULL, log_buffer);
DEBUG_LOG_WRITE_V(TAG, log_buffer);
}
}
static void log_program_info_log(GLuint program_object_id) {
if (LOGGING_ON) {
GLint log_length;
glGetProgramiv(program_object_id, GL_INFO_LOG_LENGTH, &log_length);
GLchar log_buffer[log_length];
glGetProgramInfoLog(program_object_id, log_length, NULL, log_buffer);
DEBUG_LOG_WRITE_V(TAG, log_buffer);
}
}
GLuint compile_shader(const GLenum type, const GLchar* source, const GLint length) {
assert(source != NULL);
GLuint shader_object_id = glCreateShader(type);
GLint compile_status;
assert(shader_object_id != 0);
glShaderSource(shader_object_id, 1, (const GLchar **)&source, &length);
glCompileShader(shader_object_id);
glGetShaderiv(shader_object_id, GL_COMPILE_STATUS, &compile_status);
if (LOGGING_ON) {
DEBUG_LOG_WRITE_D(TAG, "Results of compiling shader source:");
log_v_fixed_length(source, length);
log_shader_info_log(shader_object_id);
}
assert(compile_status != 0);
return shader_object_id;
}
GLuint link_program(const GLuint vertex_shader, const GLuint fragment_shader) {
GLuint program_object_id = glCreateProgram();
GLint link_status;
assert(program_object_id != 0);
glAttachShader(program_object_id, vertex_shader);
glAttachShader(program_object_id, fragment_shader);
glLinkProgram(program_object_id);
glGetProgramiv(program_object_id, GL_LINK_STATUS, &link_status);
if (LOGGING_ON) {
DEBUG_LOG_WRITE_D(TAG, "Results of linking program:");
log_program_info_log(program_object_id);
}
assert(link_status != 0);
return program_object_id;
}
GLuint build_program(
const GLchar * vertex_shader_source, const GLint vertex_shader_source_length,
const GLchar * fragment_shader_source, const GLint fragment_shader_source_length) {
assert(vertex_shader_source != NULL);
assert(fragment_shader_source != NULL);
GLuint vertex_shader = compile_shader(
GL_VERTEX_SHADER, vertex_shader_source, vertex_shader_source_length);
GLuint fragment_shader = compile_shader(
GL_FRAGMENT_SHADER, fragment_shader_source, fragment_shader_source_length);
return link_program(vertex_shader, fragment_shader);
}
GLint validate_program(const GLuint program) {
if (LOGGING_ON) {
int validate_status;
glValidateProgram(program);
glGetProgramiv(program, GL_VALIDATE_STATUS, &validate_status);
DEBUG_LOG_PRINT_D(TAG, "Results of validating program: %d", validate_status);
log_program_info_log(program);
return validate_status;
}
return 0;
}
#pragma clang diagnostic pop
+10
View File
@@ -0,0 +1,10 @@
#include "platform_gl.h"
GLuint compile_shader(const GLenum type, const GLchar* source, const GLint length);
GLuint link_program(const GLuint vertex_shader, const GLuint fragment_shader);
GLuint build_program(
const GLchar * vertex_shader_source, const GLint vertex_shader_source_length,
const GLchar * fragment_shader_source, const GLint fragment_shader_source_length);
/* Should be called just before using a program to draw, if validation is needed. */
GLint validate_program(const GLuint program);
+130
View File
@@ -0,0 +1,130 @@
#include "timing.h"
static inline float evaluateAtParameterWithCoefficients(float t, float coefficients[])
{
return coefficients[0] + t*coefficients[1] + t*t*coefficients[2] + t*t*t*coefficients[3];
}
static inline float evaluateDerivationAtParameterWithCoefficients(float t, float coefficients[])
{
return coefficients[1] + 2*t*coefficients[2] + 3*t*t*coefficients[3];
}
static inline float calcParameterViaNewtonRaphsonUsingXAndCoefficientsForX(float x, float coefficientsX[])
{
// see http://en.wikipedia.org/wiki/Newton's_method
// start with X being the correct value
float t = x;
// iterate several times
//const float epsilon = 0.00001;
int i;
for(i = 0; i < 10; i++)
{
float x2 = evaluateAtParameterWithCoefficients(t, coefficientsX) - x;
float d = evaluateDerivationAtParameterWithCoefficients(t, coefficientsX);
float dt = x2/d;
t = t - dt;
}
return t;
}
static inline float calcParameterUsingXAndCoefficientsForX (float x, float coefficientsX[])
{
// for the time being, we'll guess Newton-Raphson always
// returns the correct value.
// if we find it doesn't find the solution often enough,
// we can add additional calculation methods.
float t = calcParameterViaNewtonRaphsonUsingXAndCoefficientsForX(x, coefficientsX);
return t;
}
static int is_initialized=0;
static float _coefficientsX[TIMING_NUM][4], _coefficientsY[TIMING_NUM][4];
static const float _c0x = 0.0;
static const float _c0y = 0.0;
static const float _c3x = 1.0;
static const float _c3y = 1.0;
float timing(float x, timing_type type)
{
if (is_initialized==0) {
is_initialized=1;
float c[TIMING_NUM][4];
c[Default][0]=0.25f;
c[Default][1]=0.1f;
c[Default][2]=0.25f;
c[Default][3]=1.0f;
c[EaseInEaseOut][0]=0.42f;
c[EaseInEaseOut][1]=0.0f;
c[EaseInEaseOut][2]=0.58f;
c[EaseInEaseOut][3]=1.0f;
c[EaseIn][0]=0.42f;
c[EaseIn][1]=0.0f;
c[EaseIn][2]=1.0f;
c[EaseIn][3]=1.0f;
c[EaseOut][0]=0.0f;
c[EaseOut][1]=0.0f;
c[EaseOut][2]=0.58f;
c[EaseOut][3]=1.0f;
c[EaseOutBounce][0]=0.0;
c[EaseOutBounce][1]=0.0;
c[EaseOutBounce][2]=0.;
c[EaseOutBounce][3]=1.25;
c[Linear][0]=0.0;
c[Linear][1]=0.0;
c[Linear][2]=1.0;
c[Linear][3]=1.0;
int i;
for (i=0; i<TIMING_NUM; i++) {
float _c1x = c[i][0];
float _c1y = c[i][1];
float _c2x = c[i][2];
float _c2y = c[i][3];
_coefficientsX[i][0] = _c0x; // t^0
_coefficientsX[i][1] = -3.0f*_c0x + 3.0f*_c1x; // t^1
_coefficientsX[i][2] = 3.0f*_c0x - 6.0f*_c1x + 3.0f*_c2x; // t^2
_coefficientsX[i][3] = -_c0x + 3.0f*_c1x - 3.0f*_c2x + _c3x; // t^3
_coefficientsY[i][0] = _c0y; // t^0
_coefficientsY[i][1] = -3.0f*_c0y + 3.0f*_c1y; // t^1
_coefficientsY[i][2] = 3.0f*_c0y - 6.0f*_c1y + 3.0f*_c2y; // t^2
_coefficientsY[i][3] = -_c0y + 3.0f*_c1y - 3.0f*_c2y + _c3y; // t^3
}
}
if (x==0.0 || x==1.0) {
return x;
}
float t = calcParameterUsingXAndCoefficientsForX(x, _coefficientsX[type]);
float y = evaluateAtParameterWithCoefficients(t, _coefficientsY[type]);
return y;
}
+22
View File
@@ -0,0 +1,22 @@
//
// timing.h
// IntroOpenGL
//
// Created by Ilya Rimchikov on 03/05/14.
// Copyright (c) 2014 IntroOpenGL. All rights reserved.
//
typedef enum
{
Default=0,
EaseIn=1,
EaseOut=2,
EaseInEaseOut=3,
Linear=4,
Sin=5,
EaseOutBounce,
TIMING_NUM
} timing_type;
float timing(float x, timing_type type);