Initial commit

This commit is contained in:
2025-11-17 10:28:09 +01:00
parent 7bff81691f
commit 6ee36e26be
391 changed files with 110253 additions and 0 deletions

View File

@@ -0,0 +1,231 @@
/*
* This file is automaticaly generated, Please dont edit this file!
*/
#include <array.h>
int array_length( array * this ) {
return this->total;
}
void * * array_data( array * this ) {
return this->items;
}
void * array_get( array * this, int index ) {
if ( index >= 0 && index < this->total ){
return this->items[index];
}
return NULL;
}
void array_set( array * this, int index, void * item ) {
if ( index >= 0 && index < this->total ){
this->items[ index ] = item;
}
}
void array_resize( array * this, int capacity ) {
void * * items = realloc( this->items, sizeof( void * ) * capacity );
this->items = items;
this->capacity = capacity;
}
void array_add( array * this, void * item ) {
if ( this->capacity == this->total ){
array_resize( this, this->capacity * 2 );
}
this->items[ this->total++ ] = item;
}
char * array_join( array * this, char * separator ) {
int count = array_length( this );
text * result = text_newPointer( "" );
for (int i = 0; i < count; ++i)
{
char * currentPart = this->items[ i ];
if( i > 0 ) {
text_append( result, separator );
}
text_append( result, currentPart );
}
return result->value;
}
void array_delete( array * this, int index ) {
if ( index < 0 || index >= this->total ){
return;
}
this->items[index] = NULL;
for ( int i = index; i < this->total - 1; i++ ) {
this->items[i] = this->items[i + 1];
this->items[i + 1] = NULL;
}
this->total--;
if ( this->total > 0 && this->total == this->capacity / 4 ){
array_resize( this, this->capacity / 2 );
}
}
int array_array_push( array * this, void * item ) {
array_add( this, item );
return this->total;
}
void array_unshift( array * this, void * item ) {
int length = this->total;
this->total++;
if ( this->capacity == this->total ){
array_resize( this, this->capacity * 2 );
}
for ( int i = length - 1; i >= 0; --i ) {
this->items[ i + 1 ] = this->items[ i ];
}
this->items[ 0 ] = item;
}
void * array_pop( array * this ) {
int length = this->total;
int lastIndex = length - 1;
void * lastItem = array_get( this, lastIndex );
array_delete( this, lastIndex );
return lastItem;
}
bool array_includes( array * this, char * value ) {
int count = array_length( this );
for ( int index = 0; index < count; ++index )
{
char * currentText = array_get( this, index);
if( char_operator_compare( currentText , value) ) {
return true;
}
}
return false;
}
array array_new() {
array instance;
instance.capacity = 10;
instance.total = 0;
instance.items = malloc( 10000000 );
return instance;
}
array * array_newPointer() {
struct array * pointer = malloc( sizeof ( struct array ) );
pointer->capacity = 10;
pointer->total = 0;
pointer->items = malloc( 10000000 );
return pointer;
}

View File

@@ -0,0 +1,71 @@
#ifndef _array
#define _array
// Macros
#include "stdlib.h"
extern char * __ClassNames[];
// Includes
#include <text.h>
#include <char.h>
#include <stdbool.h>
#include <stdlib.h>
typedef struct array{
int capacity;
int total;
void * * items;
} array;
int array_length( array * this );
void * * array_data( array * this );
void * array_get( array * this, int index );
void array_set( array * this, int index, void * item );
void array_resize( array * this, int capacity );
void array_add( array * this, void * item );
char * array_join( array * this, char * separator );
void array_delete( array * this, int index );
int array_array_push( array * this, void * item );
void array_unshift( array * this, void * item );
void * array_pop( array * this );
bool array_includes( array * this, char * value );
array array_new( );
array * array_newPointer( );
#endif
typedef struct array array;

View File

@@ -0,0 +1,93 @@
/*
* This file is automaticaly generated, Please dont edit this file!
*/
#include <cache.h>
text * cache_getFile( cache * this, char * filePath ) {
struct file * currentFile = cache_getCachedFileByPath( this, filePath );
if( currentFile == NULL ) {
struct text * content = fileSystem_readFile( filesystem, filePath, "binary" );
cache_addFile( this, filePath, content );
return content;
} else {
return currentFile->content;
}
}
void cache_addFile( cache * this, char * filePath, struct text * content ) {
struct file * newFile = file_newPointer();
newFile->filePath = filePath;
newFile->content = content;
array_add( this->files, newFile );
}
struct file * cache_getCachedFileByPath( cache * this, char * filePath ) {
struct array * files = this->files;
int count = array_length( files );
for (int i = 0; i < count; ++i)
{
file * currentFile = array_get( files, i );
if( char_operator_compare( currentFile->filePath , filePath) ) {
return currentFile;
}
}
return NULL;
}
cache cache_new() {
cache instance;
instance.files = array_newPointer();
return instance;
}
cache * cache_newPointer() {
struct cache * pointer = malloc( sizeof ( struct cache ) );
pointer->files = array_newPointer();
return pointer;
}

View File

@@ -0,0 +1,49 @@
#ifndef _cache
#define _cache
// Macros
#include "stdlib.h"
extern char * __ClassNames[];
// Includes
#include "fileSystem.h"
#include "file.h"
#include "text.h"
#include "array.h"
typedef struct cache{
struct array * files;
} cache;
text * cache_getFile( cache * this, char * filePath );
void cache_addFile( cache * this, char * filePath, struct text * content );
struct file * cache_getCachedFileByPath( cache * this, char * filePath );
cache cache_new( );
cache * cache_newPointer( );
#endif
typedef struct cache cache;

View File

@@ -0,0 +1,169 @@
/*
* This file is automaticaly generated, Please dont edit this file!
*/
#include <char.h>
int char_operator_compare( char * this, char * b ) {
return char_compare( this, b );
}
void char_operator_add( char * this, char * b ) {
strcat( this, b );
}
char * char_operator_plus( char * this, char * b ) {
return char_concatenate( this, b );
}
int char_compare( char * this, char * b ) {
return strcmp( this, b ) == 0;
}
char * char_concatenate( char * this, char * b ) {
int lengthA = strlen( this );
int lengthB = strlen( b );
char * pointer = this;
char * copy = ( char * ) malloc( ( lengthA + lengthB + 1 ) * sizeof( char ) );
int idx = 0;
while ( * pointer != '\0' ){
copy[idx++] = *pointer++;
}
pointer = &b[0];
while ( * pointer != '\0' ){
copy[idx++] = *pointer++;
}
copy[ idx++ ] = '\0';
return &copy[0];
}
int char_includes( char * this, char * compare ) {
if ( strstr( this, compare ) != NULL ) {
return 1;
} else {
return 0;
}
}
char * char_clone( char * this ) {
char * newCopy = malloc( sizeof( char ) * strlen( this ) );
strcpy( newCopy, this );
return newCopy;
}
char * char_copy( char * this ) {
char * newCopy = malloc( sizeof( char ) * strlen( this ) );
strcpy( newCopy, this );
return newCopy;
}
struct array * char_split( char * this, char * needle ) {
char * haystack = char_clone( this );
struct array * keys = array_newPointer();
int count = 0;
char * tmp = haystack;
char * token = strtok( haystack, needle );
int i = 0;
while ( token ) {
array_add( keys, token );
token = (char *) strtok( NULL, needle );
}
return keys;
}
char * char_removeWhitespaceLeft( char * this ) {
char * s = this;
while(isspace(*s)) s++;
return s;
}
char * char_removeWhitespaceRight( char * this ) {
char * s = this;
char* back = s + strlen(s);
while( isspace( *--back ) );
*( back + 1 ) = '\0';
return s;
}
char * char_removeWhitespace( char * this ) {
return char_removeWhitespaceRight(char_removeWhitespaceLeft( this ) );
}

View File

@@ -0,0 +1,56 @@
#ifndef _char
#define _char
// Macros
#include "stdlib.h"
extern char * __ClassNames[];
// Includes
#include <string.h>
#include <ctype.h>
#include <dirent.h>
#include <array.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
int char_operator_compare( char * this, char * b );
void char_operator_add( char * this, char * b );
char * char_operator_plus( char * this, char * b );
int char_compare( char * this, char * b );
char * char_concatenate( char * this, char * b );
int char_includes( char * this, char * compare );
char * char_clone( char * this );
char * char_copy( char * this );
struct array * char_split( char * this, char * needle );
char * char_removeWhitespaceLeft( char * this );
char * char_removeWhitespaceRight( char * this );
char * char_removeWhitespace( char * this );
#endif

View File

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,133 @@
#ifndef __classConfiguration
#define __classConfiguration
#include <stddef.h>
#include <engine/opengl.h>
#include <engine/event.h>
#include <vector2.h>
#include <engine/vector.h>
#include <int.h>
#include <engine/quadMesh.h>
#include <engine/element.h>
#include <engine/vector4.h>
#include <engine/windowManager.h>
#include <engine/hints.h>
#include <engine/resourceManager.h>
#include <engine/texture2D.h>
#include <engine/renderPasses/renderPassTesselation.h>
#include <engine/mesh.h>
#include <engine/unsignedIntegerArray.h>
#include <engine/floatArray.h>
#include <engine/program.h>
#include <engine/shader.h>
#include <engine/sampler2D.h>
#include <vector3.h>
#include <array.h>
#include <text.h>
#include <char.h>
#include <fileSystem.h>
#include <console.h>
#include <http.h>
#include <headers.h>
#include <header.h>
#include <request.h>
#include <cache.h>
#include <file.h>
#include <mimeTypes.h>
#include <engine/uniform.h>
#include <engine/member.h>
#include <engine/block.h>
#include <engine/fontRenderer.h>
#include <engine/renderPasses/renderPass.h>
#include <engine/renderPasses/renderPassCompute2.h>
#include <engine/renderPasses/renderPassCompute.h>
#include <engine/renderPasses/renderPassFont.h>
#include <engine/renderPasses/renderPassQuads.h>
#include <engine/pipeline.h>
#include <engine/eventManager.h>
#define TOTAL_CLASS_COUNT 52
extern char * __ClassNames[TOTAL_CLASS_COUNT];
extern int __ClassPropertyCount[TOTAL_CLASS_COUNT];
extern char * __ClassPropertyNames[TOTAL_CLASS_COUNT][30];
extern int __ClassPropertyOffsets[TOTAL_CLASS_COUNT][30];
extern int __ClassPropertyOffsets[TOTAL_CLASS_COUNT][30];
#include <string.h>
int getPropertyIndexOfClassIndex( int propertyCount, char ** propertyNames );
void getArrayByClassIndex( int size, void * * voidArray, int * structByteSize, int classIndex );
int getClassIndexByClassName( char * className );
char * getClassName( int classIndex );
int getPropertyCountByClassIndex( int classIndex );
char * * getPropertiesByClassIndex( int classIndex );
int * getPropertyOffsetsByClassIndex( int classIndex );
int getPropertyOffsetByPropertyIndex( int * propertyOffsets, int propertyIndex );
int getPropertyIndexByPropertyName( int classID, char * propertyName );
int * getPropertyDatatypeIndexesByClassIndex( int classIndex );
int getPropertyDatatypeIndex( int * propertyDatatypeIndices, int propertyIndex );
int getMethodCountByClassIndex( int classIndex );
char * * getMethodNamesByClassIndex( int classIndex );
int getMethodIndexByPropertyName( int classID, char * propertyName );
void callMethodOfClass( int classIndex, int methodIndex, void * object );
#endif

View File

@@ -0,0 +1,269 @@
/*
* This file is automaticaly generated, Please dont edit this file!
*/
#include <console.h>
struct consoleManager * console;
char * consoleManager_whiteSpace( consoleManager * this, int whiteSpaceCount ) {
char * output = malloc( whiteSpaceCount + 1 );
for (int i = 0; i < whiteSpaceCount; ++i)
{
strcat( output, " " );
}
output[whiteSpaceCount] = 0;
return output;
}
void consoleManager_logObject( consoleManager * this, void * voidPointer, int classIndex, int level ) {
char * whiteSpace = consoleManager_whiteSpace( this, level );
level++;
char * className = getClassName( classIndex );
printf( "\n\n" );
printf( whiteSpace );
printf(" %s : {\n", className );
char * * propertyNames = getPropertiesByClassIndex( classIndex );
int propertyCount = getPropertyCountByClassIndex( classIndex );
int * propertyOffsets = getPropertyOffsetsByClassIndex( classIndex );
int * datatypeIndices = getPropertyDatatypeIndexesByClassIndex( classIndex );
char * pointer = voidPointer;
for (int propertyIndex = 0; propertyIndex < propertyCount; ++propertyIndex)
{
char * propertyName = propertyNames[propertyIndex];
printf( whiteSpace );
printf(" %-20s : ", propertyName);
int propertyDatatypeIndex = getPropertyDatatypeIndex( datatypeIndices, propertyIndex );
int propertyOffset = getPropertyOffsetByPropertyIndex( propertyOffsets, propertyIndex );
if( propertyDatatypeIndex == -5 ) {
int value = *( int * )(pointer + propertyOffset);
printf( whiteSpace );
printf("%-20i ", value );
} else if( propertyDatatypeIndex == -3 ) {
uintptr_t * value = ( uintptr_t * ) ( pointer + propertyOffset );
printf( whiteSpace );
printf( "%-20s", ( char * ) * value );
} else if( propertyDatatypeIndex > 0 ) {
char * memberClassName = getClassName( propertyDatatypeIndex );
if( strcmp( memberClassName, "array" ) == 0 ) {
struct array * memberArray = *(struct array ** )(pointer + propertyOffset) ;
if( memberArray == NULL ) {
printf(" this has to be fixed, array is not created.\n");
continue;
}
int numberRows = array_length( memberArray );
int * arrayPointer = ( int * ) memberArray->items;
for (int k = 0; k < numberRows; ++k)
{
void * pointer = array_get( memberArray, k );
short * row = (short*)(pointer);
consoleManager_logObject( this, pointer, (int) *row, level );
}
}
}
printf("\n");
}
printf( whiteSpace );
printf( " }\n" );
}
void consoleManager_log( consoleManager * this, int count, int datatypes[], ... ) {
int level = 0;
va_list args;
va_start( args, count );
for (int i = 0; i < count; ++i)
{
int datatype = datatypes[i];
if( datatype == -2 ) {
char * message = va_arg( args, char * );
printf("%s", message);
}
if( datatype == -1 ) {
int message = va_arg( args, int );
printf("%i", message);
}
if( datatype > 0 ) {
void * voidPointer = va_arg( args, void * );
consoleManager_logObject( this, voidPointer, datatype, level++ );
}
printf(" ");
}
printf("\n");
va_end( args);
}
void consoleManager_error( consoleManager * this, char * message ) {
#define ANSI_COLOR_RED "\x1b[31m"
#define ANSI_COLOR_GREEN "\x1b[32m"
#define ANSI_COLOR_DIM_YELLOW "\x1b[33m"
#define ANSI_COLOR_BLUE "\x1b[34m"
#define ANSI_COLOR_MAGENTA "\x1b[35m"
#define ANSI_COLOR_CYAN "\x1b[36m"
#define ANSI_COLOR_RESET "\x1b[0m"
#define ANSI_COLOR_BRIGHT_YELLOW "\x1b[93m"
printf( ANSI_COLOR_RED );
printf( "\n\n Error: " );
printf( "%s\n\n", message );
printf( ANSI_COLOR_RESET );
exit( 0 );
}
void consoleManager_createHorisontalLine( consoleManager * this ) {
struct winsize w;
ioctl(STDOUT_FILENO, TIOCGWINSZ, &w);
for (int i = 0; i < w.ws_col; ++i)
{
printf("-");
};
printf("\n");
}
consoleManager consoleManager_new() {
consoleManager instance;
return instance;
}
consoleManager * consoleManager_newPointer() {
struct consoleManager * pointer = malloc( sizeof ( struct consoleManager ) );
return pointer;
}

View File

@@ -0,0 +1,66 @@
#ifndef _console
#define _console
// Macros
#define isCompatible(x, type) _Generic(x, type: true, default: false)
#include "stdlib.h"
extern char * __ClassNames[];
// Includes
#include <vector2.h>
#include <stdarg.h>
#include <stdio.h>
#include <unistd.h>
#include <stdio.h>
#include <sys/ioctl.h>
#include <stdio.h>
#include <stdbool.h>
#include <classConfiguration.h>
typedef struct consoleManager{
} consoleManager;
char * consoleManager_whiteSpace( consoleManager * this, int whiteSpaceCount );
void consoleManager_logObject( consoleManager * this, void * voidPointer, int classIndex, int level );
void consoleManager_log( consoleManager * this, int count, int datatypes[], ... );
void consoleManager_error( consoleManager * this, char * message );
void consoleManager_createHorisontalLine( consoleManager * this );
extern struct consoleManager * console;
consoleManager consoleManager_new( );
consoleManager * consoleManager_newPointer( );
#endif
typedef struct consoleManager consoleManager;

View File

@@ -0,0 +1,583 @@
/*
* This file is automaticaly generated, Please dont edit this file!
*/
#include <engine/block.h>
void block_add( block * this, struct member * memberInstance ) {
array_add( this->members, memberInstance );
}
void block_enableAutoUpload( block * this ) {
this->autoUpload = 1;
}
char * block_getBufferTypeText( block * this ) {
switch( this->bufferType ) {
case GL_SHADER_STORAGE_BUFFER:
return "GL_SHADER_STORAGE_BUFFER";
break;
case GL_UNIFORM_BUFFER:
return "GL_UNIFORM_BUFFER";
break;
}
return "buffer message not found";
}
void block_createBuffer( block * this ) {
unsigned int blockBufferSize = this->bufferSize;
this->data = ( float * ) malloc( blockBufferSize );
glGenBuffers( 1, &this->buffer );
glBindBuffer( this->bufferType, this->buffer );
glBindBufferBase( this->bufferType, this->index, this->buffer );
glBufferData( this->bufferType, blockBufferSize, 0, GL_DYNAMIC_DRAW );
}
void block_upload( block * this ) {
glBindBuffer( this->bufferType, this->buffer );
glBindBufferBase( this->bufferType, this->bindingPoint, this->buffer );
glBufferSubData( this->bufferType, 0, this->bufferSize, this->data );
}
void block_mapBufferError( block * this, void * pointer ) {
if ( pointer == NULL ){
GLenum errorCode = glGetError();
switch( errorCode ) {
case GL_INVALID_ENUM:
printf("GL_INVALID_ENUM\n");
break;
case GL_INVALID_OPERATION:
printf("GL_INVALID_OPERATION\n");
break;
case GL_INVALID_VALUE:
printf("GL_INVALID_VALUE\n");
break;
}
printf("null pointer on buffer: %i\n", errorCode);
return;
}
}
void * block_getMemberArray( block * this, char * name ) {
glMemoryBarrier( GL_SHADER_STORAGE_BARRIER_BIT );
vector_vector2 * output = vector_vector2_newPointer();
int uniformCount = array_length( this->members );
for (int i = 0; i < uniformCount; ++i)
{
member * currentMember = array_get( this->members, i );
char * memberName = ( char * ) currentMember->name;
if( char_operator_compare( memberName , name) ) {
int size = currentMember->size * 8;
int offset = currentMember->offset / 4;
output->items = glMapBufferRange( GL_SHADER_STORAGE_BUFFER, 0, size, GL_MAP_WRITE_BIT );
output->total = currentMember->size;
block_mapBufferError( this, output->items );
}
}
glUnmapBuffer( GL_SHADER_STORAGE_BUFFER );
return output;
}
void block_setMemberArrayRow( block * this, char * name, int arrayIndex, float * data ) {
int memberCount = array_length( this->members );
for (int i = 0; i < memberCount; ++i)
{
member * currentMember = array_get( this->members, i );
char * memberName = ( char * ) currentMember->name;
if( char_operator_compare( memberName , name) ) {
int size = currentMember->size * 8;
int arrayStride = currentMember->arrayStride;
int offset = arrayStride * arrayIndex;
if( this->autoUpload ) {
glBindBuffer( this->bufferType, this->buffer );
glBindBufferBase( this->bufferType, this->bindingPoint, this->buffer );
glBufferSubData( this->bufferType, offset, arrayStride, data );
}
memcpy( this->data + offset, data, arrayStride );
}
}
}
void block_setMemberArray( block * this, char * name, float * data ) {
int memberCount = array_length( this->members );
for (int i = 0; i < memberCount; ++i)
{
member * currentMember = array_get( this->members, i );
char * memberName = ( char * ) currentMember->name;
if( char_operator_compare( memberName , name) ) {
int size = currentMember->size * 8;
int offset = currentMember->offset / 4;
memcpy( this->data + offset, data, size );
}
}
}
void block_setMemberItem( block * this, char * name, int index, void * value ) {
int uniformCount = array_length( this->members );
for (int i = 0; i < uniformCount; ++i)
{
member * currentMember = array_get( this->members, i );
char * memberName = ( char * ) currentMember->name;
if( char_operator_compare( memberName , name) ) {
int stride;
int strideNormalized;
int size;
int offset;
switch( currentMember->type ) {
case GL_FLOAT_VEC2:
stride = currentMember->arrayStride;
strideNormalized = stride / sizeof( float ) ;
vector2 * vector2Value = ( vector2 * ) value;
size = 8;
offset = currentMember->offset;
if( this->autoUpload ) {
GLint arrayIndex = ( strideNormalized * index * 2 * 8 );
float data[2] = { vector2Value->x, vector2Value->y };
printf("%i: (size:%i) %f %f\n", arrayIndex, data[0], data[1]);
glBindBuffer( this->bufferType, this->buffer );
glBindBufferBase( this->bufferType, this->bindingPoint, this->buffer );
glBufferSubData( this->bufferType, arrayIndex, size, data );
} else {
GLint dataOffset = offset / sizeof( float );
GLint arrayIndex = ( strideNormalized * index );
if( currentMember->topLevelSize == 1 ) {
}
this->data[ dataOffset + arrayIndex ] = vector2Value->x;
this->data[ dataOffset + 1 + arrayIndex ] = vector2Value->y;
}
break;
case GL_FLOAT_VEC3:
stride = currentMember->arrayStride;
strideNormalized = stride / sizeof( float ) ;
vector3 * vector3Value = ( vector3 * ) value;
size = 12;
offset = currentMember->offset;
if( this->autoUpload ) {
float data[3] = { vector3Value->x, vector3Value->y, vector3Value->z };
glBindBuffer( this->bufferType, this->buffer );
glBindBufferBase( this->bufferType, this->bindingPoint, this->buffer );
glBufferSubData( this->bufferType, offset, size, data );
} else {
GLint dataOffset = offset / sizeof( float );
GLint arrayIndex = ( strideNormalized * index );
this->data[ dataOffset + arrayIndex ] = vector3Value->x;
this->data[ dataOffset + 1 + arrayIndex ] = vector3Value->y;
this->data[ dataOffset + 2 + arrayIndex ] = vector3Value->z;
}
break;
case GL_SAMPLER_2D:
break;
}
}
}
}
void block_setData( block * this, float * data ) {
this->data = data;
}
void block_setMember( block * this, char * name, void * value ) {
int uniformCount = array_length( this->members );
for (int i = 0; i < uniformCount; ++i)
{
member * currentMember = array_get( this->members, i );
char * memberName = ( char * ) currentMember->name;
if( char_operator_compare( memberName , name) ) {
GLuint size = 8;
GLint offset = currentMember->offset;
switch( currentMember->type ) {
case GL_INT:
int intValue = *( int * ) value;
printf("set int value: %i offset: %i\n", intValue, offset);
if( this->autoUpload ) {
float data[1] = { value };
glBindBuffer( this->bufferType, this->buffer );
glBindBufferBase( this->bufferType, this->bindingPoint, this->buffer );
glBufferSubData( this->bufferType, offset, size, data );
} else {
GLint dataOffset = offset / sizeof( float );
this->data[ dataOffset ] = intValue;
}
break;
case GL_FLOAT:
float floatValue = *( float * ) value;
printf("set int value: %f offset: %i\n", floatValue, offset);
if( this->autoUpload ) {
float data[1] = { value };
glBindBuffer( this->bufferType, this->buffer );
glBindBufferBase( this->bufferType, this->bindingPoint, this->buffer );
glBufferSubData( this->bufferType, offset, size, data );
} else {
GLint dataOffset = offset / sizeof( float );
this->data[ dataOffset ] = floatValue;
}
break;
case GL_FLOAT_VEC2:
vector2 * vector2Value = ( vector2 * ) value;
if( this->autoUpload ) {
float data[2] = { vector2Value->x, vector2Value->y };
glBindBuffer( this->bufferType, this->buffer );
glBindBufferBase( this->bufferType, this->bindingPoint, this->buffer );
glBufferSubData( this->bufferType, offset, size, data );
} else {
GLint dataOffset = offset / sizeof( float );
this->data[ dataOffset ] = vector2Value->x;
this->data[ dataOffset + 1 ] = vector2Value->y;
}
break;
case GL_FLOAT_VEC3:
vector3 * vector3Value = ( vector3 * ) value;
break;
case GL_SAMPLER_2D:
break;
}
}
}
}
block block_new() {
block instance;
instance.members = array_newPointer();
instance.autoUpload = 0;
return instance;
}
block * block_newPointer() {
struct block * pointer = malloc( sizeof ( struct block ) );
pointer->members = array_newPointer();
pointer->autoUpload = 0;
return pointer;
}

View File

@@ -0,0 +1,96 @@
#ifndef _block
#define _block
// Macros
#define GL_GLEXT_PROTOTYPES
#include "stdlib.h"
extern char * __ClassNames[];
// Includes
#include "member.h"
#include "sampler2D.h"
#include "char.h"
#include "array.h"
#include "fileSystem.h"
#include <stdio.h>
#include <GL/glx.h>
#include <GL/gl.h>
#include <GL/glext.h>
typedef struct block{
array * members;
GLint buffer;
GLuint index;
GLenum bufferType;
GLint bufferSize;
GLint bindingPoint;
GLchar * name;
float * data;
GLint autoUpload;
} block;
void block_add( block * this, struct member * memberInstance );
void block_enableAutoUpload( block * this );
char * block_getBufferTypeText( block * this );
void block_createBuffer( block * this );
void block_upload( block * this );
void block_mapBufferError( block * this, void * pointer );
void * block_getMemberArray( block * this, char * name );
void block_setMemberArrayRow( block * this, char * name, int arrayIndex, float * data );
void block_setMemberArray( block * this, char * name, float * data );
void block_setMemberItem( block * this, char * name, int index, void * value );
void block_setData( block * this, float * data );
void block_setMember( block * this, char * name, void * value );
block block_new( );
block * block_newPointer( );
#endif
typedef struct block block;

View File

@@ -0,0 +1,366 @@
/*
* This file is automaticaly generated, Please dont edit this file!
*/
#include <engine/element.h>
void element_constructor( element * this ) {
vector_char_pointer_add( this->featureNames, "useBackgroundImage" );
vector_char_pointer_add( this->featureNames, "useBorder" );
}
vector4 element_colorConverter( element * this, char * hexValue ) {
int r;
int g;
int b;
int a;
sscanf( hexValue, "%02x%02x%02x%02x", &r, &g, &b, &a );
printf("opacity: %i\n");
struct vector4 rgbColor = vector4_new( r, g, b, (float)a );
return rgbColor;
}
void element_setOriginal( element * this ) {
this->originalSize = this->size;
this->originalPosition = this->position;
this->originalBackgroundColor = this->backgroundColor;
}
void element_setter_size( element * this, vector2 a ) {
this->size.x = a.x;
this->size.y = a.y;
printf("set size: %f %f\n", this->size.x, this->size.y);
}
void element_setter_position( element * this, vector3 a ) {
this->position.x = a.x;
this->position.y = a.y;
this->position.z = a.z;
printf("set position: %f %f\n", this->position.x, this->position.y);
}
bool element_featureIsEnabled( element * this, int featureValue ) {
return ( this->features & featureValue ) > 0;
}
int element_getFeatureValueByFeatureName( element * this, char * featureName ) {
int count = vector_char_pointer_length( this->featureNames );
for (int i = 0; i < count; ++i)
{
char * currentFeatureName = vector_char_pointer_get( this->featureNames, i );
if( char_operator_compare( featureName , currentFeatureName) ) {
return powf( 2, i );
}
}
return 0;
}
int element_updateFeature( element * this ) {
int currentFeatureValue;
currentFeatureValue = element_getFeatureValueByFeatureName( this, "useBackgroundImage" );
if( element_featureIsEnabled( this, currentFeatureValue ) ) {
if( !this->useBackgroundImage ) {
this->features -= currentFeatureValue;
}
} else {
if( this->useBackgroundImage ) {
this->features += currentFeatureValue;
}
}
return this->features;
}
void element_setter_background( element * this, int count, int datatypes[], ... ) {
va_list args;
va_start( args, count );
int datatype = datatypes[0];
printf("datatype: %i\n\n\n", datatype);
if( datatype == -2 ) {
char * message = va_arg( args, char * );
if( ( char ) message[0] == 35 ) {
printf("Hex color\n\n\n");
message++;
vector4 rgba = element_colorConverter( this, message );
this->backgroundColor = vector3_new( rgba.x, rgba.y, rgba.z );
this->opacity = rgba.w / 256;
this->useBackgroundImage = false;
} else {
this->backgroundImagePath = message;
this->useBackgroundImage = true;
printf("path\n\n\n");
}
printf(" char *: %s\n\n\n ", message);
}
if( datatype > 0 ) {
char * className = getClassName( datatype );
if( char_operator_compare( className , "vector3") ) {
vector3 message = va_arg( args, vector3 );
this->backgroundColor = message;
this->useBackgroundImage = false;
}
if( char_operator_compare( className , "vector4") ) {
vector4 message = va_arg( args, vector4 );
this->backgroundColor = vector3_new( message.x, message.y, message.z );
this->opacity = message.w;
this->useBackgroundImage = false;
}
}
}
void element_click( element * this ) {
this->backgroundColor = vector3_new( 0, 256, 256 );
}
void element_mousedown( element * this ) {
this->backgroundColor = vector3_new( 0, 256, 256 );
element_setter_position( this, vector3_new( 256, 256, 100 ) );
}
void element_mouseup( element * this ) {
this->backgroundColor = this->originalBackgroundColor;
element_setter_position( this, this->originalPosition );
}
void element_mouseover( element * this ) {
this->backgroundColor = vector3_new( 256, 256, 256 );
}
void element_mouseleave( element * this ) {
printf("mouse leave\n");
this->backgroundColor = this->originalBackgroundColor;
}
element element_new() {
element instance;
instance.position = vector3_new( 0, 0, 0 );
instance.size = vector2_new( 0, 0 );
instance.backgroundColor = vector3_new( 0, 0, 0 );
instance.originalPosition = vector3_new( 0, 0, 0 );
instance.originalSize = vector2_new( 0, 0 );
instance.originalBackgroundColor = vector3_new( 0, 0, 0 );
instance.opacity = 1;
instance.backgroundImagePath = "";
instance.useBackgroundImage = false;
instance.features = 0;
instance.featureNames = vector_char_pointer_newPointer();
element_constructor( &instance);
return instance;
}
element * element_newPointer() {
struct element * pointer = malloc( sizeof ( struct element ) );
pointer->position = vector3_new( 0, 0, 0 );
pointer->size = vector2_new( 0, 0 );
pointer->backgroundColor = vector3_new( 0, 0, 0 );
pointer->originalPosition = vector3_new( 0, 0, 0 );
pointer->originalSize = vector2_new( 0, 0 );
pointer->originalBackgroundColor = vector3_new( 0, 0, 0 );
pointer->opacity = 1;
pointer->backgroundImagePath = "";
pointer->useBackgroundImage = false;
pointer->features = 0;
pointer->featureNames = vector_char_pointer_newPointer();
element_constructor( pointer );
return pointer;
}

View File

@@ -0,0 +1,107 @@
#ifndef _element
#define _element
// Macros
#include "stdlib.h"
extern char * __ClassNames[];
// Includes
#include <math.h>
#include <stdbool.h>
#include <stdarg.h>
#include "classConfiguration.h"
#include "char.h"
#include "vector.h"
#include "vector4.h"
#include "vector3.h"
#include "vector2.h"
typedef struct element{
int index;
vector3 position;
vector2 size;
vector3 backgroundColor;
vector3 originalPosition;
vector2 originalSize;
vector3 originalBackgroundColor;
float opacity;
char * backgroundImagePath;
bool useBackgroundImage;
int features;
vector_char_pointer * featureNames;
int textureIndex;
void * background;
} element;
void element_constructor( element * this );
vector4 element_colorConverter( element * this, char * hexValue );
void element_setOriginal( element * this );
void element_setter_size( element * this, vector2 a );
void element_setter_position( element * this, vector3 a );
bool element_featureIsEnabled( element * this, int featureValue );
int element_getFeatureValueByFeatureName( element * this, char * featureName );
int element_updateFeature( element * this );
void element_setter_background( element * this, int count, int datatypes[], ... );
void element_click( element * this );
void element_mousedown( element * this );
void element_mouseup( element * this );
void element_mouseover( element * this );
void element_mouseleave( element * this );
element element_new( );
element * element_newPointer( );
#endif
typedef struct element element;

View File

@@ -0,0 +1,87 @@
/*
* This file is automaticaly generated, Please dont edit this file!
*/
#include <engine/event.h>
event event_new() {
event instance;
instance.mouse = mouse_newPointer();
instance.screen = screen_newPointer();
instance.keyboard = keyboard_newPointer();
return instance;
}
event * event_newPointer() {
struct event * pointer = malloc( sizeof ( struct event ) );
pointer->mouse = mouse_newPointer();
pointer->screen = screen_newPointer();
pointer->keyboard = keyboard_newPointer();
return pointer;
}
keyboard keyboard_new() {
keyboard instance;
return instance;
}
keyboard * keyboard_newPointer() {
struct keyboard * pointer = malloc( sizeof ( struct keyboard ) );
return pointer;
}
screen screen_new() {
screen instance;
return instance;
}
screen * screen_newPointer() {
struct screen * pointer = malloc( sizeof ( struct screen ) );
return pointer;
}
mouse mouse_new() {
mouse instance;
instance.eventTypes = vector_char_pointer_newPointer();
return instance;
}
mouse * mouse_newPointer() {
struct mouse * pointer = malloc( sizeof ( struct mouse ) );
pointer->eventTypes = vector_char_pointer_newPointer();
return pointer;
}

View File

@@ -0,0 +1,110 @@
#ifndef _event
#define _event
// Macros
#include "stdlib.h"
extern char * __ClassNames[];
// Includes
#include "stdbool.h"
#include "../vector2.h"
#include "vector.h"
typedef struct event{
struct mouse * mouse;
struct screen * screen;
struct keyboard * keyboard;
} event;
typedef struct keyboard{
int keyCode;
bool shiftKey;
bool ctrlKey;
bool altKey;
bool metaKey;
} keyboard;
typedef struct screen{
vector2 size;
vector2 position;
} screen;
typedef struct mouse{
vector2 position;
int button;
vector_char_pointer * eventTypes;
} mouse;
event event_new( );
event * event_newPointer( );
keyboard keyboard_new( );
keyboard * keyboard_newPointer( );
screen screen_new( );
screen * screen_newPointer( );
mouse mouse_new( );
mouse * mouse_newPointer( );
#endif
typedef struct event event;
typedef struct keyboard keyboard;
typedef struct screen screen;
typedef struct mouse mouse;

View File

@@ -0,0 +1,309 @@
/*
* This file is automaticaly generated, Please dont edit this file!
*/
#include <engine/eventManager.h>
void eventManger_constructor( eventManger * this ) {
this->lastEvent = event_newPointer();
this->lastEvent->mouse->button = -1;
}
event * eventManger_fetchEvent( eventManger * this ) {
event * currentEvent = event_newPointer();
currentEvent->mouse->button = -1;
Window qRoot;
Window qChild;
unsigned int qMask;
int childX;
int childY;
int mouseX;
int mouseY;
int child;
XWindowAttributes window;
if( XGetWindowAttributes( this->mainDisplay, this->mainWindow, &window ) ) {
}
if( XQueryPointer( this->mainDisplay, this->RootWindow, &qRoot, &qChild, &mouseX, &mouseY, &childX, &childY, &qMask ) )
{
mouseX -= window.x;
mouseY -= window.y;
for(int i = 0; i < sizeof(int) * 8; i++)
{
int mask = 1 << sizeof(int) * 8 - i - 1;
if(mask & qMask)
{
}
else
{
}
}
if( qMask == Button1MotionMask ) {
currentEvent->mouse->button = 0;
}
if( qMask == Button2MotionMask ) {
printf("Button2MotionMask\n");
}
if( qMask == Button3MotionMask ) {
printf("RightMouse\n");
}
if( qMask == Button4MotionMask ) {
printf("Button2MotionMask\n");
}
if( qMask == Button5MotionMask ) {
printf("Button2MotionMask\n");
}
if( qMask == ShiftMask ) {
printf("Pressed shift\n");
}
if( qMask == ControlMask ) {
printf("Pressed control\n");
}
if( qMask == EnterWindowMask ) {
}
XEvent event;
int keyboardEventCount = XPending( this->mainDisplay );
while( XPending( this->mainDisplay ) ) {
XNextEvent( this->mainDisplay, &event );
switch ( event.type ) {
case KeyPress:
printf("key has been pressed. %i\n\n", event.xkey.keycode);
break;
case KeyRelease:
printf("key has been released. %i\n\n", event.xkey.keycode);
break;
case Expose:
break;
default:
}
}
}
bool hasBorder = true;
int borderCorrection = 0;
if( hasBorder ) {
borderCorrection = 12;
}
currentEvent->mouse->position = vector2_new( mouseX, mouseY + borderCorrection );
currentEvent->screen->size = vector2_new( window.width, window.height + borderCorrection );
vector_char_pointer * mouseEvents = currentEvent->mouse->eventTypes;
mouseEvents = vector_char_pointer_newPointer();
if( this->lastEvent->mouse->position.x != currentEvent->mouse->position.x ||
this->lastEvent->mouse->position.y != currentEvent->mouse->position.y ) {
vector_char_pointer_add( mouseEvents, "mousemove" );
}
if( this->lastEvent->mouse->button != 0 && currentEvent->mouse->button == 0 ) {
this->lastMouseDownTime = clock();
printf("Mouse down\n\n");
vector_char_pointer_add( mouseEvents, "mousedown" );
}
if( this->lastEvent->mouse->button == 0 && currentEvent->mouse->button != 0 ) {
clock_t difference = clock() - this->lastMouseDownTime;
int milliseconds = difference * 1000 / CLOCKS_PER_SEC;
if( milliseconds < 150 ) {
printf("click event\n\n");
vector_char_pointer_add( mouseEvents, "click" );
}
printf("mouseup event\n\n");
vector_char_pointer_add( mouseEvents, "mouseup" );
}
currentEvent->mouse->eventTypes = mouseEvents;
this->lastEvent = currentEvent;
return currentEvent;
}
eventManger eventManger_new() {
eventManger instance;
eventManger_constructor( &instance);
return instance;
}
eventManger * eventManger_newPointer() {
struct eventManger * pointer = malloc( sizeof ( struct eventManger ) );
eventManger_constructor( pointer );
return pointer;
}

View File

@@ -0,0 +1,70 @@
#ifndef _eventManager
#define _eventManager
// Macros
#define GL_GLEXT_PROTOTYPES
#include "stdlib.h"
extern char * __ClassNames[];
// Includes
#include <vector2.h>
#include <vector.h>
#include <time.h>
#include <event.h>
#include <stdio.h>
#include <GL/glx.h>
#include <GL/gl.h>
#include <GL/glext.h>
#include <X11/keysym.h>
#include <X11/Xlib.h>
typedef struct eventManger{
Display * mainDisplay;
Window mainWindow;
Window RootWindow;
event * lastEvent;
clock_t lastMouseDownTime;
} eventManger;
void eventManger_constructor( eventManger * this );
event * eventManger_fetchEvent( eventManger * this );
eventManger eventManger_new( );
eventManger * eventManger_newPointer( );
#endif
typedef struct eventManger eventManger;

View File

@@ -0,0 +1,193 @@
/*
* This file is automaticaly generated, Please dont edit this file!
*/
#include <engine/floatArray.h>
int floatArray_length( floatArray * this ) {
return this->total;
}
float floatArray_get( floatArray * this, int index ) {
if ( index >= 0 && index < this->total ){
return this->items[index];
}
return NULL;
}
void floatArray_set( floatArray * this, int index, float item ) {
if ( index >= 0 && index < this->total ){
this->items[ index ] = item;
}
}
void floatArray_resize( floatArray * this, int capacity ) {
float * items = realloc( this->items, sizeof( float ) * capacity );
this->items = items;
this->capacity = capacity;
}
void floatArray_addVector2( floatArray * this, struct vector2 * item ) {
floatArray_add( this, item->x );
floatArray_add( this, item->y );
}
void floatArray_addVector3( floatArray * this, struct vector3 * item ) {
floatArray_add( this, item->x );
floatArray_add( this, item->y );
floatArray_add( this, item->z );
}
void floatArray_add( floatArray * this, float item ) {
if ( this->capacity == this->total ){
floatArray_resize( this, this->capacity * 2 );
}
this->items[ this->total++ ] = item;
}
void floatArray_delete( floatArray * this, int index ) {
if ( index < 0 || index >= this->total ){
return;
}
this->items[index] = NULL;
for ( int i = index; i < this->total - 1; i++ ) {
this->items[i] = this->items[i + 1];
this->items[i + 1] = NULL;
}
this->total--;
if ( this->total > 0 && this->total == this->capacity / 4 ){
floatArray_resize( this, this->capacity / 2 );
}
}
int floatArray_array_push( floatArray * this, float item ) {
floatArray_add( this, item );
return this->total;
}
void floatArray_unshift( floatArray * this, float item ) {
int length = this->total;
this->total++;
if ( this->capacity == this->total ){
floatArray_resize( this, this->capacity * 2 );
}
for ( int i = length - 1; i >= 0; --i ) {
this->items[ i + 1 ] = this->items[ i ];
}
this->items[ 0 ] = item;
}
float floatArray_pop( floatArray * this ) {
int length = this->total;
int lastIndex = length - 1;
float lastItem = floatArray_get( this, lastIndex );
floatArray_delete( this, lastIndex );
return lastItem;
}
floatArray floatArray_new() {
floatArray instance;
instance.capacity = 10;
instance.total = 0;
instance.items = malloc( 10000000 );
return instance;
}
floatArray * floatArray_newPointer() {
struct floatArray * pointer = malloc( sizeof ( struct floatArray ) );
pointer->capacity = 10;
pointer->total = 0;
pointer->items = malloc( 10000000 );
return pointer;
}

View File

@@ -0,0 +1,71 @@
#ifndef _floatArray
#define _floatArray
// Macros
#include "stdlib.h"
extern char * __ClassNames[];
// Includes
#include <vector2.h>
#include <vector3.h>
#include <text.h>
#include <char.h>
#include <stdlib.h>
typedef struct floatArray{
int capacity;
int total;
float * items;
} floatArray;
int floatArray_length( floatArray * this );
float floatArray_get( floatArray * this, int index );
void floatArray_set( floatArray * this, int index, float item );
void floatArray_resize( floatArray * this, int capacity );
void floatArray_addVector2( floatArray * this, struct vector2 * item );
void floatArray_addVector3( floatArray * this, struct vector3 * item );
void floatArray_add( floatArray * this, float item );
void floatArray_delete( floatArray * this, int index );
int floatArray_array_push( floatArray * this, float item );
void floatArray_unshift( floatArray * this, float item );
float floatArray_pop( floatArray * this );
floatArray floatArray_new( );
floatArray * floatArray_newPointer( );
#endif
typedef struct floatArray floatArray;

View File

@@ -0,0 +1,194 @@
/*
* This file is automaticaly generated, Please dont edit this file!
*/
#include <engine/fontRenderer.h>
texture2D * fontRenderer_loadFont( fontRenderer * this, char character ) {
FT_Library ft;
if ( FT_Init_FreeType( &ft ) )
{
printf("ERROR::FREETYPE: Could not init FreeType Library");
} else {
}
FT_Face face;
if ( FT_New_Face( ft, "assets/fonts/WorkSans/WorkSans-Regular.ttf", 0, &face ) )
{
printf("ERROR::FREETYPE: Failed to load font\n\n");
} else {
}
int fontSize = 118;
if ( FT_Set_Pixel_Sizes( face, 0, fontSize ) ) {
printf("ERROR::FREETYPE: Failed to set font size\n\n");
} else {
}
FT_Matrix matrix;
FT_UInt glyph_index;
FT_Vector pen;
int n;
FT_GlyphSlot slot = face->glyph;
pen.x = 0;
pen.y = 0;
if( FT_Load_Char( face, character, FT_LOAD_RENDER ) ) {
printf("ERROR error loading char.");
} else {
}
FT_Bitmap * bitmap = &slot->bitmap;
texture2D * texture = texture2D_newPointer();
texture->width = bitmap->width;
texture->height = bitmap->rows;
texture->hasAlpha = 1;
texture->offset = vector2_newPointer( ( float ) slot->bitmap_left, ( float ) slot->bitmap_top );
texture->data = bitmap->buffer;
for (int x = 0; x < texture->width; ++x)
{
}
return texture;
}
void fontRenderer_draw_bitmap( fontRenderer * this, FT_Bitmap * bitmap, FT_Int x, FT_Int y ) {
FT_Int i, j, p, q;
FT_Int x_max = x + bitmap->width;
FT_Int y_max = y + bitmap->rows;
int WIDTH = 512;
int HEIGHT = 512;
printf("x_max: %i\n", x_max);
printf("y_max: %i\n", y_max);
for ( i = x, p = 0; i < x_max; i++, p++ )
{
for ( j = y, q = 0; j < y_max; j++, q++ )
{
}
}
}
void fontRenderer_show_image( fontRenderer * this, void ) {
}
fontRenderer fontRenderer_new() {
fontRenderer instance;
instance.data = malloc( 512 * 512 * 4 );
return instance;
}
fontRenderer * fontRenderer_newPointer() {
struct fontRenderer * pointer = malloc( sizeof ( struct fontRenderer ) );
pointer->data = malloc( 512 * 512 * 4 );
return pointer;
}

View File

@@ -0,0 +1,60 @@
#ifndef _fontRenderer
#define _fontRenderer
// Macros
#define GL_GLEXT_PROTOTYPES
#include "stdlib.h"
extern char * __ClassNames[];
// Includes
#include <GL/glx.h>
#include <GL/gl.h>
#include <GL/glext.h>
#include <vector2.h>
#include <texture2D.h>
#include <text.h>
#include <freetype/freetype.h>
#include <ft2build.h>
typedef struct fontRenderer{
GLubyte * data;
} fontRenderer;
texture2D * fontRenderer_loadFont( fontRenderer * this, char character );
void fontRenderer_draw_bitmap( fontRenderer * this, FT_Bitmap * bitmap, FT_Int x, FT_Int y );
void fontRenderer_show_image( fontRenderer * this, void );
fontRenderer fontRenderer_new( );
fontRenderer * fontRenderer_newPointer( );
#endif
typedef struct fontRenderer fontRenderer;

View File

@@ -0,0 +1,23 @@
/*
* This file is automaticaly generated, Please dont edit this file!
*/
#include <engine/hints.h>
Hints Hints_new() {
Hints instance;
return instance;
}
Hints * Hints_newPointer() {
struct Hints * pointer = malloc( sizeof ( struct Hints ) );
return pointer;
}

View File

@@ -0,0 +1,43 @@
#ifndef _hints
#define _hints
// Macros
#include "stdlib.h"
extern char * __ClassNames[];
// Includes
typedef struct Hints{
unsigned long flags;
unsigned long functions;
unsigned long decorations;
long inputMode;
unsigned long status;
} Hints;
Hints Hints_new( );
Hints * Hints_newPointer( );
#endif
typedef struct Hints Hints;

View File

@@ -0,0 +1,23 @@
/*
* This file is automaticaly generated, Please dont edit this file!
*/
#include <engine/member.h>
member member_new() {
member instance;
return instance;
}
member * member_newPointer() {
struct member * pointer = malloc( sizeof ( struct member ) );
return pointer;
}

View File

@@ -0,0 +1,56 @@
#ifndef _member
#define _member
// Macros
#define GL_GLEXT_PROTOTYPES
#include "stdlib.h"
extern char * __ClassNames[];
// Includes
#include <GL/glx.h>
#include <GL/gl.h>
#include <GL/glext.h>
typedef struct member{
char * name;
GLint index;
GLint offset;
GLint size;
GLenum type;
GLuint arrayStride;
GLuint topLevelSize;
} member;
member member_new( );
member * member_newPointer( );
#endif
typedef struct member member;

View File

@@ -0,0 +1,724 @@
/*
* This file is automaticaly generated, Please dont edit this file!
*/
#include <engine/mesh.h>
struct block * mesh_getUniformBlock( mesh * this, char * blockName ) {
int blockCount = array_length( this->blocks );
for ( int i = 0; i < blockCount; ++i )
{
struct block * currentBlock = array_get( this->blocks, i );
char * currentBlockName = currentBlock->name;
if( char_operator_compare( currentBlockName , blockName) ) {
return currentBlock;
}
}
return NULL;
}
void mesh_bindBlock( mesh * this, struct block * blockInstance ) {
block_createBuffer( blockInstance );
array_add( this->blocks, blockInstance );
}
void mesh_setProgram( mesh * this, struct program * currentProgram ) {
this->program = currentProgram;
}
GLuint mesh_getGLTypeSize( mesh * this, GLuint type ) {
switch( type ) {
case GL_FLOAT:
return sizeof( GLfloat );
break;
case GL_INT:
return sizeof( GLint );
break;
case GL_UNSIGNED_INT:
return sizeof( GLuint );
break;
}
return 0;
}
GLuint mesh_getComponentType( mesh * this, GLuint type ) {
switch( type ) {
case GL_FLOAT:
return GL_FLOAT;
break;
case GL_FLOAT_VEC2:
return GL_FLOAT;
break;
case GL_FLOAT_VEC3:
return GL_FLOAT;
break;
case GL_FLOAT_VEC4:
return GL_FLOAT;
break;
case GL_INT:
return GL_INT;
break;
case GL_INT_VEC2:
return GL_INT;
break;
case GL_INT_VEC3:
return GL_INT;
break;
case GL_INT_VEC4:
return GL_INT;
break;
case GL_UNSIGNED_INT:
return GL_UNSIGNED_INT;
break;
case GL_UNSIGNED_INT_VEC2:
return GL_UNSIGNED_INT;
break;
case GL_UNSIGNED_INT_VEC3:
return GL_UNSIGNED_INT;
break;
case GL_UNSIGNED_INT_VEC4:
return GL_UNSIGNED_INT;
break;
}
return 0;
}
GLuint mesh_getItemSize( mesh * this, GLuint type ) {
switch( type ) {
case GL_FLOAT:
return 1;
break;
case GL_FLOAT_VEC2:
return 2;
break;
case GL_FLOAT_VEC3:
return 3;
break;
case GL_FLOAT_VEC4:
return 4;
break;
case GL_INT:
return 1;
break;
case GL_INT_VEC2:
return 2;
break;
case GL_INT_VEC3:
return 3;
break;
case GL_INT_VEC4:
return 4;
break;
case GL_UNSIGNED_INT:
return 1;
break;
case GL_UNSIGNED_INT_VEC2:
return 2;
break;
case GL_UNSIGNED_INT_VEC3:
return 3;
break;
case GL_UNSIGNED_INT_VEC4:
return 4;
break;
}
return 0;
}
GLuint mesh_createBuffer( mesh * this, char * attributeName, void * data, GLenum target, GLenum usage ) {
GLuint itemSize;
GLuint componentType;
GLuint componentSize;
GLuint attributeLocation;
GLuint isIndexBuffer = 0;
GLuint buffer;
glGenBuffers( 1, &buffer );
if( char_operator_compare( attributeName , "index") ) {
isIndexBuffer = 1;
componentType = GL_INT;
componentSize = mesh_getGLTypeSize( this, componentType );
target = GL_ELEMENT_ARRAY_BUFFER;
glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, buffer );
} else {
attribute * attribute = program_getAttributeByName( this->program, attributeName );
if( attribute == NULL ) {
return 0;
}
itemSize = mesh_getItemSize( this, attribute->type );
componentType = mesh_getComponentType( this, attribute->type );
componentSize = mesh_getGLTypeSize( this, componentType );
attributeLocation = attribute->location;
target = GL_ARRAY_BUFFER;
glEnableVertexAttribArray( attribute->location );
glBindBuffer( GL_ARRAY_BUFFER, buffer );
}
int itemCount;
GLuint bufferSize;
if( componentType == GL_UNSIGNED_INT || componentType == GL_INT ) {
unsignedIntegerArray * test = ( unsignedIntegerArray * ) data;
itemCount = unsignedIntegerArray_length( test );
bufferSize = itemCount * componentSize;
glBufferData( target, bufferSize, test->items, usage );
if( isIndexBuffer == NULL ) {
glVertexAttribIPointer( attributeLocation, itemSize, componentType, 0, ( void * ) 0 );
}
} else if( componentType == GL_FLOAT ) {
floatArray * test = ( floatArray * ) data;
itemCount = test->total;
bufferSize = itemCount * componentSize;
glBufferData( GL_ARRAY_BUFFER, bufferSize, test->items, usage );
if( isIndexBuffer == NULL ) {
glVertexAttribPointer( attributeLocation, itemSize, componentType, GL_FALSE, 0, ( void * ) 0 );
}
}
GLint compareSize = 0;
glGetBufferParameteriv( target, GL_BUFFER_SIZE, &compareSize );
if( bufferSize != compareSize )
{
glDeleteBuffers(1, &buffer);
printf("ERROR: size error");
return 0;
}
return buffer;
}
void mesh_createBuffers( mesh * this ) {
struct unsignedIntegerArray * indices = unsignedIntegerArray_newPointer();
struct floatArray * textureCoordinates = floatArray_newPointer();
struct floatArray * vertexCoordinates = floatArray_newPointer();
struct floatArray * normalCoordinates = floatArray_newPointer();
struct unsignedIntegerArray * meshIndices = unsignedIntegerArray_newPointer();
int subdivisionsDepth = 1;
int subdivisionsWidth = 1;
float width = 2;
float depth = 2;
int meshCount = 100 * 50;
int meshStartIndex = 0;
for (int meshIndex = 0; meshIndex < meshCount; ++meshIndex)
{
meshStartIndex = unsignedIntegerArray_length( meshIndices );
int numVertsAcross = subdivisionsWidth + 1;
for ( int z = 0; z < subdivisionsDepth; z++ ) {
for ( int x = 0; x < subdivisionsWidth; x++ ) {
unsignedIntegerArray_add( indices, ( z + 0 ) * numVertsAcross + x + meshStartIndex );
unsignedIntegerArray_add( indices, ( z + 1 ) * numVertsAcross + x + meshStartIndex );
unsignedIntegerArray_add( indices, ( z + 0 ) * numVertsAcross + x + 1 + meshStartIndex );
unsignedIntegerArray_add( indices, ( z + 1 ) * numVertsAcross + x + meshStartIndex );
unsignedIntegerArray_add( indices, ( z + 1 ) * numVertsAcross + x + 1 + meshStartIndex );
unsignedIntegerArray_add( indices, ( z + 0 ) * numVertsAcross + x + 1 + meshStartIndex );
}
}
for ( int z = 0; z <= subdivisionsDepth; z++ ) {
for ( int x = 0; x <= subdivisionsWidth; x++ ) {
float u = ( float ) x;
float v = ( float ) z;
floatArray_add( textureCoordinates, u );
floatArray_add( textureCoordinates, ( 1 - v ) );
floatArray_add( vertexCoordinates, width * u - width * 0.5 );
floatArray_add( vertexCoordinates, depth * v - depth * 0.5 );
floatArray_add( vertexCoordinates, 0 );
floatArray_add( normalCoordinates, 0 );
floatArray_add( normalCoordinates, 0 );
floatArray_add( normalCoordinates, 1 );
unsignedIntegerArray_add( meshIndices, meshIndex );
}
}
}
glGenVertexArrays( 1, &this->vertexArrayObject );
glBindVertexArray( this->vertexArrayObject );
this->vertexbuffer = mesh_createBuffer( this, "position", vertexCoordinates, GL_ARRAY_BUFFER, GL_STATIC_DRAW );
this->textureCoordinateBuffer = mesh_createBuffer( this, "textureCoordinates", textureCoordinates, GL_ARRAY_BUFFER, GL_STATIC_DRAW );
this->vertexbuffer = mesh_createBuffer( this, "meshIndex", meshIndices, GL_ARRAY_BUFFER, GL_STATIC_DRAW );
this->indexBuffer = mesh_createBuffer( this, "index", indices, GL_ARRAY_BUFFER, GL_STATIC_DRAW );
int blockCount = array_length( this->blocks );
for (int i = 0; i < blockCount; ++i)
{
block * currentBlock = array_get( this->blocks, i );
int size = currentBlock->bufferSize;
printf("Bind block %s bufferSize: %i bindingPoint: %i bufferType: %s \n\n", currentBlock->name, currentBlock->bufferSize, currentBlock->bindingPoint, block_getBufferTypeText( currentBlock ) );
glBindBuffer( currentBlock->bufferType, currentBlock->buffer );
glBindBufferBase( currentBlock->bufferType, currentBlock->bindingPoint, currentBlock->buffer );
glBufferData( currentBlock->bufferType, currentBlock->bufferSize, 0, GL_DYNAMIC_DRAW );
}
glBindVertexArray( 0 );
this->indices = indices;
this->textureCoordinates = textureCoordinates;
this->vertexCoordinates = vertexCoordinates;
this->normalCoordinates = normalCoordinates;
}
void mesh_createOrderedTriangleStripQuad( mesh * this ) {
}
mesh mesh_new() {
mesh instance;
instance.blocks = array_newPointer();
instance.uniformBuffers = unsignedIntegerArray_newPointer();
return instance;
}
mesh * mesh_newPointer() {
struct mesh * pointer = malloc( sizeof ( struct mesh ) );
pointer->blocks = array_newPointer();
pointer->uniformBuffers = unsignedIntegerArray_newPointer();
return pointer;
}

View File

@@ -0,0 +1,98 @@
#ifndef _mesh
#define _mesh
// Macros
#define GL_GLEXT_PROTOTYPES
#include "stdlib.h"
extern char * __ClassNames[];
// Includes
#include "unsignedIntegerArray.h"
#include "floatArray.h"
#include "program.h"
#include "shader.h"
#include "block.h"
#include <GL/glx.h>
#include <GL/gl.h>
#include <GL/glext.h>
typedef struct mesh{
struct program * program;
struct unsignedIntegerArray * indices;
struct floatArray * textureCoordinates;
struct floatArray * vertexCoordinates;
struct floatArray * normalCoordinates;
struct array * blocks;
GLuint vertexArrayObject;
GLuint uniformBuffer;
GLuint indexBuffer;
GLuint vertexbuffer;
GLuint textureCoordinateBuffer;
GLuint meshIndexBuffer;
GLuint uvBuffer;
struct unsignedIntegerArray * uniformBuffers;
} mesh;
struct block * mesh_getUniformBlock( mesh * this, char * blockName );
void mesh_bindBlock( mesh * this, struct block * blockInstance );
void mesh_setProgram( mesh * this, struct program * currentProgram );
GLuint mesh_getGLTypeSize( mesh * this, GLuint type );
GLuint mesh_getComponentType( mesh * this, GLuint type );
GLuint mesh_getItemSize( mesh * this, GLuint type );
GLuint mesh_createBuffer( mesh * this, char * attributeName, void * data, GLenum target, GLenum usage );
void mesh_createBuffers( mesh * this );
void mesh_createOrderedTriangleStripQuad( mesh * this );
mesh mesh_new( );
mesh * mesh_newPointer( );
#endif
typedef struct mesh mesh;

View File

@@ -0,0 +1,369 @@
/*
* This file is automaticaly generated, Please dont edit this file!
*/
#include <engine/opengl.h>
event * globalEvent;
resourceManager * resources;
void opengl_initialize( opengl * this ) {
printf("initialize opengl.\n");
resources = resourceManager_newPointer();
opengl_setupWindow( this );
opengl_setupManagers( this );
opengl_showVersion( this );
opengl_setupPipeline( this );
opengl_setupTime( this );
opengl_setupRenderLoop( this );
}
void opengl_showExtensions( opengl * this ) {
GLint max_layers;
glGetIntegerv ( GL_MAX_ARRAY_TEXTURE_LAYERS, &max_layers );
printf("GL_MAX_ARRAY_TEXTURE_LAYERS: %i\n", max_layers);
GLint max_texture_size;
glGetIntegerv (GL_MAX_TEXTURE_SIZE, &max_texture_size);
printf("GL_MAX_TEXTURE_SIZE: %i\n", max_texture_size);
}
void opengl_showVersion( opengl * this ) {
printf("opengl version : %s\n\n", glGetString(GL_VERSION) );
}
void opengl_setupTime( opengl * this ) {
clock_gettime( CLOCK_REALTIME, &this->startTime );
}
void opengl_setupManagers( opengl * this ) {
this->eventManger->mainDisplay = this->mainDisplay;
this->eventManger->mainWindow = this->mainWindow;
this->eventManger->RootWindow = this->RootWindow;
}
void opengl_setupWindow( opengl * this ) {
windowManager_setupDisplay( this->windowManager );
windowManager_setupWindow( this->windowManager );
this->mainDisplay = this->windowManager->mainDisplay;
this->mainWindow = this->windowManager->mainWindow;
this->RootWindow = this->windowManager->RootWindow;
}
void opengl_setupRenderLoop( opengl * this ) {
int IsProgramRunning = 1;
while( IsProgramRunning ) {
while( XPending( this->mainDisplay ) ) {
XEvent GeneralEvent = {};
XNextEvent( this->mainDisplay, &GeneralEvent );
switch( GeneralEvent.type ) {
case ClientMessage:
IsProgramRunning = 0;
break;
}
}
opengl_render( this );
}
}
void opengl_setupPipeline( opengl * this ) {
quads * quadsPass = quads_newPointer();
font * fontPass = font_newPointer();
compute * computePass = compute_newPointer();
compute2 * computePass2 = compute2_newPointer();
tesselation * tesselationPass = tesselation_newPointer();
pipeline_addRenderPass( this->pipeline, 1, (int[1]){ 44 }, quadsPass );
}
double opengl_clockToMilliseconds( opengl * this, clock_t ticks ) {
return ( ticks / ( double ) CLOCKS_PER_SEC );
}
void opengl_render( opengl * this ) {
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
opengl_clear( this, GL_DEPTH_BUFFER_BIT );
globalEvent = eventManger_fetchEvent( this->eventManger );
pipeline_render( this->pipeline );
opengl_swapBuffers( this );
}
void opengl_displayFPS( opengl * this ) {
struct timespec now;
clock_gettime( CLOCK_REALTIME, &now );
this->frameCount++;
int elapsedTime = now.tv_sec - this->startTime.tv_sec;
if( elapsedTime != this->lastTime ) {
printf("%i fps.\n\n", this->frameCount );
this->lastTime = elapsedTime;
this->frameCount = 0;
}
}
void opengl_clear( opengl * this, GLbitfield mask ) {
glClear( mask );
}
void opengl_clearColor( opengl * this, float r, float g, float b, float a ) {
glClearColor( r, g, b, a );
}
void opengl_swapBuffers( opengl * this ) {
PFNGLXSWAPINTERVALEXTPROC glXSwapIntervalEXT;
PFNGLXSWAPINTERVALMESAPROC glXSwapIntervalMESA;
PFNGLXSWAPINTERVALSGIPROC glXSwapIntervalSGI;
glXSwapIntervalEXT = ( PFNGLXSWAPINTERVALEXTPROC ) glXGetProcAddress( ( const GLubyte * ) "glXSwapIntervalEXT" );
if ( glXSwapIntervalEXT != NULL ) {
glXSwapIntervalEXT( this->mainDisplay, this->mainWindow, 0 );
} else {
glXSwapIntervalMESA = ( PFNGLXSWAPINTERVALMESAPROC ) glXGetProcAddress( ( const GLubyte * ) "glXSwapIntervalMESA" );
if ( glXSwapIntervalMESA != NULL ) {
glXSwapIntervalMESA( 0 );
} else {
glXSwapIntervalSGI = ( PFNGLXSWAPINTERVALSGIPROC ) glXGetProcAddress( ( const GLubyte * ) "glXSwapIntervalSGI" );
if ( glXSwapIntervalSGI != NULL ) {
glXSwapIntervalSGI( 0 );
}
}
}
glXSwapBuffers( this->mainDisplay, this->mainWindow );
}
opengl opengl_new() {
opengl instance;
instance.lastTime = clock();
instance.frameCount = 0;
instance.windowManager = windowManager_newPointer();
instance.eventManger = eventManger_newPointer();
instance.pipeline = pipeline_newPointer();
return instance;
}
opengl * opengl_newPointer() {
struct opengl * pointer = malloc( sizeof ( struct opengl ) );
pointer->lastTime = clock();
pointer->frameCount = 0;
pointer->windowManager = windowManager_newPointer();
pointer->eventManger = eventManger_newPointer();
pointer->pipeline = pipeline_newPointer();
return pointer;
}

View File

@@ -0,0 +1,142 @@
#ifndef _opengl
#define _opengl
// Macros
#define GL_GLEXT_PROTOTYPES
#include "stdlib.h"
extern char * __ClassNames[];
// Includes
#include <zlib.h>
#include <time.h>
#include <GL/glx.h>
#include <GL/gl.h>
#include <GL/glext.h>
#include <X11/keysym.h>
#include <X11/Xlib.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include "./event.h"
#include "./windowManager.h"
#include "./resourceManager.h"
#include "./renderPasses/renderPassTesselation.h"
#include "./renderPasses/renderPassCompute2.h"
#include "./renderPasses/renderPassCompute.h"
#include "./renderPasses/renderPassFont.h"
#include "./renderPasses/renderPassQuads.h"
#include "./pipeline.h"
#include "./eventManager.h"
#include "./unsignedIntegerArray.h"
#include "./floatArray.h"
#include "./texture2D.h"
#include "./sampler2D.h"
#include "./shader.h"
#include "./mesh.h"
typedef struct opengl{
Display * mainDisplay;
Window mainWindow;
int MainScreen;
Window RootWindow;
int lastTime;
struct timespec startTime;
int frameCount;
sampler2D * testSampler;
struct windowManager * windowManager;
struct eventManger * eventManger;
struct pipeline * pipeline;
} opengl;
void opengl_initialize( opengl * this );
void opengl_showExtensions( opengl * this );
void opengl_showVersion( opengl * this );
void opengl_setupTime( opengl * this );
void opengl_setupManagers( opengl * this );
void opengl_setupWindow( opengl * this );
void opengl_setupRenderLoop( opengl * this );
void opengl_setupPipeline( opengl * this );
double opengl_clockToMilliseconds( opengl * this, clock_t ticks );
void opengl_render( opengl * this );
void opengl_displayFPS( opengl * this );
void opengl_clear( opengl * this, GLbitfield mask );
void opengl_clearColor( opengl * this, float r, float g, float b, float a );
void opengl_swapBuffers( opengl * this );
resourceManager * resources;
event * globalEvent;
opengl opengl_new( );
opengl * opengl_newPointer( );
#endif
typedef struct opengl opengl;

View File

@@ -0,0 +1,113 @@
/*
* This file is automaticaly generated, Please dont edit this file!
*/
#include <engine/pipeline.h>
void pipeline_addRenderPass( pipeline * this, int count, int datatypes[], ... ) {
va_list args;
va_start( args, count );
int classIndex = datatypes[0];
vector_int_add( this->classIndices, classIndex );
void * voidPointer = va_arg( args, void * );
int methodIndex = getMethodIndexByPropertyName( classIndex, "prepare" );
int renderMethodIndex = getMethodIndexByPropertyName( classIndex, "render" );
vector_int_add( this->methodIndices, renderMethodIndex );
int classIndexTest = vector_int_get( this->classIndices, 0 );
callMethodOfClass( classIndex, methodIndex, voidPointer );
printf("\n");
va_end( args );
array_add( this->renderPasses, voidPointer );
}
void pipeline_render( pipeline * this ) {
array * renderPasses = this->renderPasses;
int renderPassCount = array_length( renderPasses );
for (int i = 0; i < renderPassCount; ++i)
{
int classIndex = vector_int_get( this->classIndices, i );
void * voidPointer = array_get( renderPasses, i );
int methodIndex = vector_int_get( this->methodIndices, i );
callMethodOfClass( classIndex, methodIndex, voidPointer );
}
}
pipeline pipeline_new() {
pipeline instance;
instance.__classIndex = 45;
instance.renderPasses = array_newPointer();
instance.classIndices = vector_int_newPointer();
instance.methodIndices = vector_int_newPointer();
return instance;
}
pipeline * pipeline_newPointer() {
struct pipeline * pointer = malloc( sizeof ( struct pipeline ) );
pointer->__classIndex = 45;
pointer->renderPasses = array_newPointer();
pointer->classIndices = vector_int_newPointer();
pointer->methodIndices = vector_int_newPointer();
return pointer;
}

View File

@@ -0,0 +1,55 @@
#ifndef _pipeline
#define _pipeline
// Macros
#include "stdlib.h"
extern char * __ClassNames[];
// Includes
#include "../classConfiguration.h"
#include "./vector.h"
#include "./renderPasses/renderPass.h"
#include "../array.h"
#include "../int.h"
typedef struct pipeline{
unsigned short __classIndex;
array * renderPasses;
vector_int * classIndices;
vector_int * methodIndices;
} pipeline;
void pipeline_addRenderPass( pipeline * this, int count, int datatypes[], ... );
void pipeline_render( pipeline * this );
pipeline pipeline_new( );
pipeline * pipeline_newPointer( );
#endif
typedef struct pipeline pipeline;

View File

@@ -0,0 +1,568 @@
/*
* This file is automaticaly generated, Please dont edit this file!
*/
#include <engine/program.h>
void program_addShader( program * this, struct shader * shaderInstance ) {
array_add( this->shaders, shaderInstance );
}
GLint program_glGetProgramResourceiv( program * this, GLint programProperty, GLint index, GLint Property ) {
GLint offsetValues;
glGetProgramResourceiv( this->glProgram, programProperty, index, 1, &Property , 1, 0, &offsetValues );
return offsetValues;
}
GLchar * program_glGetProgramResourceName( program * this, GLint programProperty, GLint index, GLint nameLength ) {
GLchar name[ GL_NAME_LENGTH + 1 ];
glGetProgramResourceName(
this->glProgram,
programProperty,
index,
GL_NAME_LENGTH + 1,
0,
name );
return name;
}
void program_extractBlocks( program * this ) {
GLint programInterfaces[2] = { GL_SHADER_STORAGE_BLOCK, GL_UNIFORM_BLOCK };
GLint programProperties[2] = { GL_BUFFER_VARIABLE, GL_UNIFORM };
GLenum programBufferTypes[2] = { GL_SHADER_STORAGE_BUFFER, GL_UNIFORM_BUFFER };
for (int blockTypeIndex = 0; blockTypeIndex < 2; ++blockTypeIndex)
{
GLint program = this->glProgram;
GLint numActiveResources;
GLint programInterface = programInterfaces[blockTypeIndex];
GLint programProperty = programProperties[blockTypeIndex];
GLenum programBufferType = programBufferTypes[blockTypeIndex];
glGetProgramInterfaceiv( program, programInterface, GL_ACTIVE_RESOURCES, &numActiveResources );
for ( GLuint blockIndex = 0; blockIndex < numActiveResources; blockIndex++ ) {
struct block * blockInstance = block_newPointer();
GLint blockNameLength = program_glGetProgramResourceiv( this, programInterface, blockIndex, GL_NAME_LENGTH );
blockInstance->bufferSize = program_glGetProgramResourceiv( this, programInterface, blockIndex, GL_BUFFER_DATA_SIZE );
GLint numberActiveVariables = program_glGetProgramResourceiv( this, programInterface, blockIndex, GL_NUM_ACTIVE_VARIABLES );
blockInstance->bindingPoint = program_glGetProgramResourceiv( this, programInterface, blockIndex, GL_BUFFER_BINDING );
GLchar name[ GL_NAME_LENGTH + 1 ];
glGetProgramResourceName( this->glProgram, programInterface, blockIndex, GL_NAME_LENGTH + 1, NULL, name );
blockInstance->name = malloc( GL_NAME_LENGTH );
strcpy( blockInstance->name, name );
blockInstance->bufferType = programBufferType;
printf("block:%s \n\n", blockInstance->name );
printf(" block name %s\n", blockInstance->name);
printf(" block buffer size: %i\n", blockInstance->bufferSize);
printf(" block binding point: %i\n\n", blockInstance->bindingPoint);
GLint indices[ numberActiveVariables ];
GLenum member = GL_ACTIVE_VARIABLES;
glGetProgramResourceiv( program, programInterface, blockIndex, 1, &member, numberActiveVariables, 0, indices );
printf(" number of variables: %i\n\n\n", numberActiveVariables);
for ( GLuint index = 0; index < numberActiveVariables; index++ )
{
struct member * memberInstance = member_newPointer();
GLint itemIndex = indices[ index ];
memberInstance->index = itemIndex;
GLint nameLength = program_glGetProgramResourceiv( this, programProperty, itemIndex, GL_NAME_LENGTH );
memberInstance->offset = program_glGetProgramResourceiv( this, programProperty, itemIndex, GL_OFFSET );
memberInstance->type = program_glGetProgramResourceiv( this, programProperty, itemIndex, GL_TYPE );
memberInstance->arrayStride = program_glGetProgramResourceiv( this, programProperty, itemIndex, GL_ARRAY_STRIDE );
memberInstance->size = program_glGetProgramResourceiv( this, programProperty, itemIndex, GL_ARRAY_SIZE );
int topLevelSize = program_glGetProgramResourceiv( this, programProperty, itemIndex, GL_TOP_LEVEL_ARRAY_SIZE );
int topLevelStride = program_glGetProgramResourceiv( this, programProperty, itemIndex, GL_TOP_LEVEL_ARRAY_STRIDE );
if( memberInstance->arrayStride == 0 ) {
memberInstance->arrayStride = topLevelStride;
}
memberInstance->topLevelSize = topLevelSize;
GLchar memberName[ GL_NAME_LENGTH + 1 ];
glGetProgramResourceName( this->glProgram, programProperty, itemIndex, GL_NAME_LENGTH + 1, NULL, memberName );
memberInstance->name = malloc( GL_NAME_LENGTH );
strcpy( memberInstance->name, memberName );
printf(" offset: #%i name: %s vec2: %i offset: %i itemSize / arrayStride: %i Array size: %i toplevel size: %i top level size: %i \n\n",
memberInstance->index,
memberInstance->name,
memberInstance->type == GL_FLOAT_VEC2,
memberInstance->offset,
memberInstance->arrayStride,
memberInstance->size, topLevelSize,
topLevelStride );
block_add( blockInstance, memberInstance );
}
block_createBuffer( blockInstance );
array_add( this->blocks, blockInstance );
}
}
}
struct block * program_createNewBlock( program * this, char * blockName ) {
printf("Copy buffer: %s\n\n", blockName);
block * originalBlock = program_getBlock( this, blockName );
block * blockCopy = block_newPointer();
blockCopy->members = originalBlock->members;
blockCopy->bindingPoint = originalBlock->bindingPoint;
blockCopy->index = originalBlock->index;
blockCopy->bufferSize = originalBlock->bufferSize;
block_createBuffer( blockCopy );
return blockCopy;
}
struct block * program_getBlock( program * this, char * blockName ) {
int blockCount = array_length( this->blocks );
for ( int i = 0; i < blockCount; ++i )
{
block * currentBlock = array_get( this->blocks, i );
char * currentBlockName = currentBlock->name;
if( char_operator_compare( currentBlockName , blockName) ) {
return currentBlock;
}
}
return NULL;
}
void program_create( program * this ) {
this->glProgram = glCreateProgram();
array * shaders = this->shaders;
int shaderCount = array_length( shaders );
for (int i = 0; i < shaderCount; ++i)
{
shader * currentShader = array_get( shaders, i );
glAttachShader( this->glProgram, currentShader->glShader );
}
glLinkProgram( this->glProgram );
glUseProgram( this->glProgram );
program_extractBlocks( this );
program_extractAttributes( this );
program_extractUniforms( this );
}
void program_bindBlock( program * this, char * blockName ) {
block * currentBlock = program_getBlock( this, blockName );
glBindBufferBase( currentBlock->bufferType, currentBlock->bindingPoint, currentBlock->buffer );
}
void program_use( program * this ) {
glUseProgram( this->glProgram );
}
void program_extractUniforms( program * this ) {
int attributeCount = 0;
GLsizei bufSize = 64;
GLsizei length;
GLint size;
GLenum type;
int uniformCount = 0;
glGetProgramiv( this->glProgram, GL_ACTIVE_UNIFORMS, &uniformCount );
for (int i = 0; i < uniformCount; i++)
{
struct uniform * uniformInstance = uniform_newPointer();
GLenum type;
GLchar name[bufSize];
glGetActiveUniform( this->glProgram, ( GLuint ) i, bufSize, &length, &size, &type, uniformInstance->name );
GLint uniformLocation = glGetUniformLocation( this->glProgram, uniformInstance->name );
uniformInstance->location = uniformLocation;
uniformInstance->type = type;
array_add( this->uniforms, uniformInstance );
}
}
void program_extractAttributes( program * this ) {
int attributeCount = 0;
GLsizei bufSize = 64;
GLsizei length;
GLint size;
GLenum type;
glGetProgramiv( this->glProgram, GL_ACTIVE_ATTRIBUTES, &attributeCount );
for (int i = 0; i < attributeCount; i++)
{
GLenum type;
attribute * attributeInstance = attribute_newPointer();
glGetActiveAttrib( this->glProgram, ( GLuint ) i, bufSize, &length, &size, &type, attributeInstance->name);
GLint attributeLocation = glGetAttribLocation( this->glProgram, attributeInstance->name );
glEnableVertexAttribArray( attributeLocation );
attributeInstance->location = attributeLocation;
attributeInstance->type = type;
array_add( this->attributes, attributeInstance );
}
}
struct attribute * program_getAttributeByName( program * this, char * attributeName ) {
int attributeCount = array_length( this->attributes );
for ( int i = 0; i < attributeCount; ++i )
{
struct attribute * currentAttribute = array_get( this->attributes, i );
char * currentAttributeName = currentAttribute->name;
if( char_operator_compare( currentAttributeName , attributeName) ) {
return currentAttribute;
}
}
return NULL;
}
void program_setUniform( program * this, char * name, void * value ) {
int uniformCount = array_length( this->uniforms );
for (int i = 0; i < uniformCount; ++i)
{
uniform * currentUniform = array_get( this->uniforms, i );
char * uniformName = (char *)currentUniform->name;
if( char_operator_compare( uniformName , name) ) {
switch( currentUniform->type ) {
case GL_FLOAT_VEC2:
vector2 * vector2Value = ( vector2 * ) value;
glUniform2f( currentUniform->location, vector2Value->x, vector2Value->y );
break;
case GL_FLOAT_VEC3:
vector3 * vector3Value = ( vector3 * ) value;
glUniform3f( currentUniform->location, vector3Value->x, vector3Value->y, vector3Value->z );
break;
case GL_SAMPLER_2D:
program_updateSampler2D( this, currentUniform, value );
break;
case GL_SAMPLER_2D_ARRAY:
program_updateSampler2D( this, currentUniform, value );
break;
}
}
}
}
void program_updateSampler2D( program * this, uniform * currentUniform, void * value ) {
glEnable( GL_BLEND );
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
sampler2D * sampler = ( sampler2D * ) value;
if( !sampler->binded ) {
sampler->index = this->samplerIndex++;
sampler2D_bind( sampler );
}
glActiveTexture( GL_TEXTURE0 + sampler->index );
glBindTexture( sampler->target, sampler->glTexture );
glUniform1i( currentUniform->location, sampler->index );
}
program program_new() {
program instance;
instance.samplerIndex = 0;
instance.uniforms = array_newPointer();
instance.attributes = array_newPointer();
instance.blocks = array_newPointer();
instance.shaders = array_newPointer();
return instance;
}
program * program_newPointer() {
struct program * pointer = malloc( sizeof ( struct program ) );
pointer->samplerIndex = 0;
pointer->uniforms = array_newPointer();
pointer->attributes = array_newPointer();
pointer->blocks = array_newPointer();
pointer->shaders = array_newPointer();
return pointer;
}

View File

@@ -0,0 +1,100 @@
#ifndef _program
#define _program
// Macros
#define GL_GLEXT_PROTOTYPES
#include "stdlib.h"
extern char * __ClassNames[];
// Includes
#include "shader.h"
#include "sampler2D.h"
#include "../char.h"
#include "../array.h"
#include "fileSystem.h"
#include <stdio.h>
#include <GL/glx.h>
#include <GL/gl.h>
#include <GL/glext.h>
#include "uniform.h"
#include "member.h"
#include "block.h"
typedef struct program{
GLuint samplerIndex;
array * uniforms;
array * attributes;
array * blocks;
array * shaders;
GLuint glProgram;
} program;
void program_addShader( program * this, struct shader * shaderInstance );
GLint program_glGetProgramResourceiv( program * this, GLint programProperty, GLint index, GLint Property );
GLchar * program_glGetProgramResourceName( program * this, GLint programProperty, GLint index, GLint nameLength );
void program_extractBlocks( program * this );
struct block * program_createNewBlock( program * this, char * blockName );
struct block * program_getBlock( program * this, char * blockName );
void program_create( program * this );
void program_bindBlock( program * this, char * blockName );
void program_use( program * this );
void program_extractUniforms( program * this );
void program_extractAttributes( program * this );
struct attribute * program_getAttributeByName( program * this, char * attributeName );
void program_setUniform( program * this, char * name, void * value );
void program_updateSampler2D( program * this, uniform * currentUniform, void * value );
program program_new( );
program * program_newPointer( );
#endif
typedef struct program program;

View File

@@ -0,0 +1,23 @@
/*
* This file is automaticaly generated, Please dont edit this file!
*/
#include <engine/quadMesh.h>
quadMesh quadMesh_new() {
quadMesh instance;
return instance;
}
quadMesh * quadMesh_newPointer() {
struct quadMesh * pointer = malloc( sizeof ( struct quadMesh ) );
return pointer;
}

View File

@@ -0,0 +1,55 @@
#ifndef _quadMesh
#define _quadMesh
// Macros
#include "stdlib.h"
extern char * __ClassNames[];
// Includes
#include "vector.h"
#include "vector3.h"
#include "vector2.h"
typedef struct quadMesh{
vector2 position;
vector2 size;
vector3 color;
float zIndex;
float opacity;
int textureIndex;
int features;
int elementIndex;
} quadMesh;
quadMesh quadMesh_new( );
quadMesh * quadMesh_newPointer( );
#endif
typedef struct quadMesh quadMesh;

View File

@@ -0,0 +1,46 @@
/*
* This file is automaticaly generated, Please dont edit this file!
*/
#include <engine/renderPasses/renderPass.h>
void renderPass_prepare( renderPass * this ) {
}
void renderPass_render( renderPass * this ) {
}
renderPass renderPass_new() {
renderPass instance;
instance.enabled = true;
return instance;
}
renderPass * renderPass_newPointer() {
struct renderPass * pointer = malloc( sizeof ( struct renderPass ) );
pointer->enabled = true;
return pointer;
}

View File

@@ -0,0 +1,47 @@
#ifndef _renderPass
#define _renderPass
// Macros
#include "stdlib.h"
extern char * __ClassNames[];
// Includes
#include "mesh.h"
#include "shader.h"
typedef struct renderPass{
bool enabled;
struct shader * shader;
struct mesh * mesh;
} renderPass;
void renderPass_prepare( renderPass * this );
void renderPass_render( renderPass * this );
renderPass renderPass_new( );
renderPass * renderPass_newPointer( );
#endif
typedef struct renderPass renderPass;

View File

@@ -0,0 +1,115 @@
/*
* This file is automaticaly generated, Please dont edit this file!
*/
#include <engine/renderPasses/renderPassCompute.h>
void compute_prepare( compute * this ) {
printf("\n\n\n Prepare renderPass Compute\n\n\n\n\n");
shader * computeShader = shader_newPointer( GL_COMPUTE_SHADER );
shader_loadFromFile( computeShader, "assets/shaders/addition.comp" );
this->program = program_newPointer();
program_addShader( this->program, computeShader );
program_create( this->program );
vector_vector2 * inputA = vector_vector2_newPointer();
for (int i = 0; i < 100; ++i)
{
vector2 a = vector2_new( i, i );
vector_vector2_add( inputA, a );
}
vector_vector2 * inputB = vector_vector2_newPointer();
for (int i = 0; i < 100; ++i)
{
vector2 a = vector2_new( 0, 10 );
vector_vector2_add( inputB, a );
}
block * inputBlock = program_getBlock( this->program, "inputBlock" );
block_setMemberArray( inputBlock, "array_a[0]", ( float * ) inputA->items );
block_setMemberArray( inputBlock, "array_b[0]", ( float * ) inputB->items );
block_upload( inputBlock );
}
void compute_render( compute * this ) {
program_use( this->program );
program_bindBlock( this->program, "inputBlock");
program_bindBlock( this->program, "outputBlock");
glDispatchCompute( 1, 1, 1 );
glMemoryBarrier( GL_SHADER_STORAGE_BARRIER_BIT );
}
compute compute_new() {
compute instance;
instance.active = true;
return instance;
}
compute * compute_newPointer() {
struct compute * pointer = malloc( sizeof ( struct compute ) );
pointer->active = true;
return pointer;
}

View File

@@ -0,0 +1,63 @@
#ifndef _renderPassCompute
#define _renderPassCompute
// Macros
#include "stdlib.h"
extern char * __ClassNames[];
// Includes
#include "../mesh.h"
#include "../vector.h"
#include "../block.h"
#include "stdbool.h"
#include "../sampler2D.h"
#include "../int.h"
#include "../program.h"
#include "../shader.h"
#include "../vector2.h"
#include "../event.h"
#include "./renderPass.h"
typedef struct compute{
struct program * program;
int active;
} compute;
void compute_prepare( compute * this );
void compute_render( compute * this );
compute compute_new( );
compute * compute_newPointer( );
#endif
typedef struct compute compute;

View File

@@ -0,0 +1,99 @@
/*
* This file is automaticaly generated, Please dont edit this file!
*/
#include <engine/renderPasses/renderPassCompute2.h>
void compute2_prepare( compute2 * this ) {
printf("\n\n\n Prepare renderPass Compute 2\n\n\n\n\n");
shader * computeShader = shader_newPointer( GL_COMPUTE_SHADER );
shader_loadFromFile( computeShader, "assets/shaders/addition2.comp" );
this->program = program_newPointer();
program_addShader( this->program, computeShader );
program_create( this->program );
}
void compute2_render( compute2 * this ) {
if( this->active ) {
program_use( this->program );
program_bindBlock( this->program, "outputBlock2" );
glDispatchCompute( 1, 1, 1 );
block * outputBlock = program_getBlock( this->program, "outputBlock2" );
vector_vector2 * output = block_getMemberArray( outputBlock, "array_d[0]" );
int count = vector_vector2_length( output );
for (int i = 0; i < count; ++i)
{
vector2 currentVector = vector_vector2_get( output, i );
printf("%i = %f %f \n", i, i, currentVector.x, currentVector.y );
}
printf("length: %i\n\n", count);
this->active = false;
}
}
compute2 compute2_new() {
compute2 instance;
instance.active = true;
return instance;
}
compute2 * compute2_newPointer() {
struct compute2 * pointer = malloc( sizeof ( struct compute2 ) );
pointer->active = true;
return pointer;
}

View File

@@ -0,0 +1,59 @@
#ifndef _renderPassCompute2
#define _renderPassCompute2
// Macros
#include "stdlib.h"
extern char * __ClassNames[];
// Includes
#include "../block.h"
#include "stdbool.h"
#include "../sampler2D.h"
#include "../../int.h"
#include "../program.h"
#include "../shader.h"
#include "../../vector2.h"
#include "../event.h"
#include "renderPass.h"
typedef struct compute2{
struct program * program;
int active;
} compute2;
void compute2_prepare( compute2 * this );
void compute2_render( compute2 * this );
compute2 compute2_new( );
compute2 * compute2_newPointer( );
#endif
typedef struct compute2 compute2;

View File

@@ -0,0 +1,193 @@
/*
* This file is automaticaly generated, Please dont edit this file!
*/
#include <engine/renderPasses/renderPassFont.h>
char * font_textFromNumber( font * this, int i ) {
char * fileName = malloc( sizeof( char ) * 100 );
sprintf( fileName, "%d", i );
return fileName;
}
void font_prepare( font * this ) {
printf("\n\n\n Prepare renderPass Font\n\n\n\n\n");
shader * vertexShader = shader_newPointer( GL_VERTEX_SHADER );
shader_loadFromFile( vertexShader, "assets/shaders/quad.vertex" );
shader * fragmentShader = shader_newPointer( GL_FRAGMENT_SHADER );
shader_loadFromFile( fragmentShader, "assets/shaders/quad.fragment" );
this->program = program_newPointer();
program_addShader( this->program, vertexShader );
program_addShader( this->program, fragmentShader );
program_create( this->program );
sampler2D * samplerArray = sampler2D_newPointer();
samplerArray->target = GL_TEXTURE_2D_ARRAY;
samplerArray->format = GL_RED;
samplerArray->internalFormat = GL_RED;
samplerArray->WRAP_S = GL_CLAMP_TO_EDGE;
samplerArray->WRAP_S = GL_CLAMP_TO_EDGE;
samplerArray->cubeSize = vector3_newPointer( 128, 128, 170 );
samplerArray->UNPACK_ALIGNMENT = true;
this->samplerArray = samplerArray;
block * fontBlock = program_getBlock( this->program, "fontData" );
this->mesh = mesh_newPointer();
mesh_setProgram( this->mesh, this->program );
mesh_createBuffers( this->mesh );
glUseProgram( this->program->glProgram );
for ( int i = 1; i < 170; ++i )
{
texture2D * characterTexture = fontRenderer_loadFont( this->font, 34 + i );
vector2 * offset = characterTexture->offset;
printf("%c offset left: %f, offset top: %f bitmap->rows: %i\n", (char) 34 + i, offset->x, offset->y, characterTexture->height );
vector2 * size = vector2_newPointer( characterTexture->width, characterTexture->height );
block_setMemberItem( fontBlock, "fontOffsets[0]", i - 35, offset );
block_setMemberItem( fontBlock, "fontSizes[0]", i - 35, size );
sampler2D_addTexture( samplerArray, characterTexture );
}
block_upload( fontBlock );
program_setUniform( this->program, "samplerArray", samplerArray );
vector_int * textArray = vector_int_newPointer();
char * someText = "Wauw this is myp first text.";
for (int i = 0; i < strlen(someText); ++i)
{
int charNumber = ( char ) someText[i] - 35;
printf(" %i\n", charNumber );
vector_int_add( textArray, charNumber );
}
block * inputBlock = program_getBlock( this->program, "inputBlock" );
block_setMemberArray( inputBlock, "characters[0]", ( float * ) textArray->items );
block_upload( inputBlock );
}
void font_render( font * this ) {
int numItems = 12;
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
program_use( this->program );
program_bindBlock( this->program, "inputBlock");
program_bindBlock( this->program, "fontData");
program_setUniform( this->program, "samplerArray", this->samplerArray );
glBindVertexArray( this->mesh->vertexArrayObject );
glDrawElements( GL_TRIANGLES, numItems, GL_UNSIGNED_INT, ( void * ) 0 );
}
font font_new() {
font instance;
instance.font = fontRenderer_newPointer();
return instance;
}
font * font_newPointer() {
struct font * pointer = malloc( sizeof ( struct font ) );
pointer->font = fontRenderer_newPointer();
return pointer;
}

View File

@@ -0,0 +1,63 @@
#ifndef _renderPassFont
#define _renderPassFont
// Macros
#include "stdlib.h"
extern char * __ClassNames[];
// Includes
#include "../mesh.h"
#include "../program.h"
#include "../fontRenderer.h"
#include "int.h"
#include "../shader.h"
#include "../vector2.h"
#include "../event.h"
#include "renderPass.h"
typedef struct font{
struct program * program;
struct mesh * mesh;
fontRenderer * font;
sampler2D * samplerArray;
} font;
char * font_textFromNumber( font * this, int i );
void font_prepare( font * this );
void font_render( font * this );
font font_new( );
font * font_newPointer( );
#endif
typedef struct font font;

View File

@@ -0,0 +1,731 @@
/*
* This file is automaticaly generated, Please dont edit this file!
*/
#include <engine/renderPasses/renderPassQuads.h>
event * globalEvent;
resourceManager * resources;
char * quads_textFromNumber( quads * this, int i ) {
char * fileName = malloc( sizeof( char ) * 100 );
sprintf( fileName, "%d", i );
return fileName;
}
void quads_prepare( quads * this ) {
printf("\n\n\n Prepare renderPass Quad\n\n\n\n\n");
this->samplerArray = sampler2D_newPointer();
for (int i = 1; i < 10; ++i )
{
char * fileName = quads_textFromNumber( this, i );
char_operator_add( fileName , ".png");
printf("load png: %s\n", fileName);
}
printf("\n\n");
this->samplerArray->target = GL_TEXTURE_2D_ARRAY;
shader * vertexShader = shader_newPointer( GL_VERTEX_SHADER );
shader_loadFromFile( vertexShader, "assets/shaders/multiQuad.vertex" );
shader * fragmentShader = shader_newPointer( GL_FRAGMENT_SHADER );
shader_loadFromFile( fragmentShader, "assets/shaders/multiQuad.fragment" );
this->program = program_newPointer();
program_addShader( this->program, vertexShader );
program_addShader( this->program, fragmentShader );
program_create( this->program );
block * orientationBlock = program_getBlock( this->program, "orientation" );
block * meshesBlock = program_getBlock( this->program, "meshes" );
this->mesh = mesh_newPointer();
mesh_setProgram( this->mesh, this->program );
mesh_createBuffers( this->mesh );
quads_createMeshes( this );
sampler2D_addTexture( this->samplerArray, resourceManager_loadPngImage( resources, "1.png" ) );
block_upload( meshesBlock );
}
void quads_sortOpacity( quads * this, vector_quadMesh * meshes ) {
int count = vector_quadMesh_length( meshes );
int i, j;
struct quadMesh temp;
for (i = 0; i < (count - 1); ++i)
{
for (j = 0; j < count - 1 - i; ++j )
{
struct quadMesh quadA = vector_quadMesh_get( meshes, j );
struct quadMesh quadB = vector_quadMesh_get( meshes, j + 1 );
float a = ( intptr_t ) quadA.zIndex;
float b = ( intptr_t ) quadB.zIndex;
if ( a > b )
{
temp = meshes->items[j+1];
meshes->items[ j + 1 ] = meshes->items[j];
meshes->items[ j ] = temp;
}
}
}
}
void quads_createMeshes( quads * this ) {
vector_quadMesh * meshes = this->meshes;
vector_quadMesh_resize( meshes, 100 );
vector_element * elements = this->elements;
{
element instance = element_new();
element_setter_position( &instance, vector3_new( 200, 200, 1100 ) );
element_setter_size( &instance, vector2_new( 200., 200. ) );
instance.opacity = 1;
element_setter_background( &instance, 1, (int[1]){ -2 }, "9.png" );
vector_element_add( elements, instance );
}
{
element instance = element_new();
element_setter_position( &instance, vector3_new( 100, 100, 500 ) );
element_setter_size( &instance, vector2_new( 400., 400. ) );
element_setter_background( &instance, 1, (int[1]){ -2 }, "3.png" );
instance.opacity = .9;
vector_element_add( elements, instance );
{
element instance = element_new();
element_setter_position( &instance, vector3_new( 20, 0, 1300 ) );
element_setter_size( &instance, vector2_new( 40., 40. ) );
element_setter_background( &instance, 1, (int[1]){ -2 }, "7.png" );
instance.opacity = 1;
vector_element_add( elements, instance );
}
int count = vector_element_length( elements );
for (int i = 0; i < count; ++i)
{
element currentElement = vector_element_get( elements, i );
quadMesh meshInstance = quadMesh_new();
meshInstance.elementIndex = i;
meshInstance.position = vector2_new( currentElement.position.x, currentElement.position.y );
meshInstance.zIndex = currentElement.position.z;
meshInstance.size = currentElement.size;
printf("zIndex: %f\n", currentElement.position.z);
int features = 0;
if( currentElement.useBackgroundImage ) {
meshInstance.textureIndex = sampler2D_getTextureIndex( this->samplerArray );
printf("use background image. %s \n", currentElement.backgroundImagePath );
sampler2D_addTexture( this->samplerArray, resourceManager_loadPngImage( resources, currentElement.backgroundImagePath ) );
} else {
printf("dont use background color. %f %f %f \n", currentElement.backgroundColor.x, currentElement.backgroundColor.y, currentElement.backgroundColor.z);
meshInstance.color = currentElement.backgroundColor;
}
meshInstance.features = element_updateFeature( &currentElement );
meshInstance.opacity = currentElement.opacity;
element_setOriginal( &currentElement );
vector_element_set( elements, i, currentElement );
vector_quadMesh_add( meshes, meshInstance );
}
quads_sortOpacity( this, meshes );
}
block * meshesBlock = program_getBlock( this->program, "meshes" );
block_setData( meshesBlock, ( float * ) meshes->items );
}
quadMesh quads_updateMesh( quads * this, quadMesh currentMesh, element currentElement ) {
vector2 position = vector2_new( currentElement.position.x, currentElement.position.y );
currentMesh.position = position;
currentMesh.zIndex = currentElement.position.z;
currentMesh.size = currentElement.size;
currentMesh.color = currentElement.backgroundColor;
return currentMesh;
}
void quads_callElementEvents( quads * this, event * currentEvent, element * currentElement, int elementIndex ) {
vector_char_pointer * mouseEvents = currentEvent->mouse->eventTypes;
int mouseEventCount = vector_char_pointer_length( mouseEvents );
for (int k = 0; k < mouseEventCount; ++k)
{
char * mouseEventCode = vector_char_pointer_get( mouseEvents, k );
printf(" mouse event: %s\n", mouseEventCode);
if( char_operator_compare( mouseEventCode , "click") ) {
element_click( currentElement );
}
if( char_operator_compare( mouseEventCode , "mousedown") ) {
element_mousedown( currentElement );
}
if( char_operator_compare( mouseEventCode , "mouseup") ) {
element_mouseup( currentElement );
}
if( char_operator_compare( mouseEventCode , "mousemove") ) {
if( !quads_integerContains( this, this->mouseOverElements, elementIndex ) ) {
element_mouseover( currentElement );
vector_int_add( this->mouseOverElements, elementIndex );
}
}
}
}
bool quads_integerContains( quads * this, vector_int * numbers, int a ) {
int count = vector_int_length( numbers );
for (int j = 0; j < count; ++j)
{
int b = vector_int_get( numbers, j );
if( a == b ) {
return true;
}
}
return false;
}
void quads_render( quads * this ) {
program * currentProgram = this->program;
event * currentEvent = globalEvent;
block * eventsBlock = program_getBlock( currentProgram, "events" );
block * meshesBlock = program_getBlock( currentProgram, "meshes" );
eventsBlock->autoUpload = true;
block_setMember( eventsBlock, "window", &currentEvent->screen->size );
meshesBlock->autoUpload = true;
vector2 mousePosition = globalEvent->mouse->position;
int mouseX = ( int ) mousePosition.x;
int mouseY = ( int ) mousePosition.y;
vector_element * elements = this->elements;
vector_quadMesh * meshes = this->meshes;
vector_int * mouseOverElements = this->mouseOverElements;
int count = vector_quadMesh_length( meshes );
for (int i = 0; i < count; ++i)
{
quadMesh currentMesh = vector_quadMesh_get( meshes, i );
int left = currentMesh.position.x;
int top = currentMesh.position.y;
int right = currentMesh.position.x + currentMesh.size.x;
int bottom = currentMesh.position.y + currentMesh.size.y;
int elementIndex = currentMesh.elementIndex;
if( mouseX > left && mouseX < right && mouseY > top && mouseY < bottom ) {
element currentElement = vector_element_get( elements, elementIndex );
quads_callElementEvents( this, currentEvent, &currentElement, elementIndex );
currentMesh = quads_updateMesh( this, currentMesh, currentElement );
vector_element_set( elements, elementIndex, currentElement );
block_setMemberArrayRow( meshesBlock, "meshArray[0].color", i, ( float * ) & currentMesh );
} else {
if( quads_integerContains( this, this->mouseOverElements, elementIndex ) ) {
printf("mouseout\n\n");
vector_int_delete( this->mouseOverElements, elementIndex );
element currentElement = vector_element_get( elements, elementIndex );
element_mouseleave( &currentElement );
currentMesh = quads_updateMesh( this, currentMesh, currentElement );
vector_element_set( elements, elementIndex, currentElement );
block_setMemberArrayRow( meshesBlock, "meshArray[0].color", i, ( float * ) & currentMesh );
}
}
}
vector2 * position2 = vector2_newPointer( 0.4, 0 );
program_setUniform( this->program, "samplerArray", this->samplerArray );
glUseProgram( currentProgram->glProgram );
int numItems = 200;
glDisable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDepthRange(0.0, 1.0);
glDepthFunc(GL_ALWAYS);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_CULL_FACE);
glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST );
glBindVertexArray( this->mesh->vertexArrayObject );
glDrawElements( GL_TRIANGLES, numItems, GL_UNSIGNED_INT, ( void * ) 0 );
}
quads quads_new() {
quads instance;
instance.font = fontRenderer_newPointer();
instance.meshes = vector_quadMesh_newPointer();
instance.elements = vector_element_newPointer();
instance.mouseOverElements = vector_int_newPointer();
return instance;
}
quads * quads_newPointer() {
struct quads * pointer = malloc( sizeof ( struct quads ) );
pointer->font = fontRenderer_newPointer();
pointer->meshes = vector_quadMesh_newPointer();
pointer->elements = vector_element_newPointer();
pointer->mouseOverElements = vector_int_newPointer();
return pointer;
}

View File

@@ -0,0 +1,95 @@
#ifndef _renderPassQuads
#define _renderPassQuads
// Macros
#include "stdlib.h"
extern char * __ClassNames[];
// Includes
#include "../element.h"
#include "../quadMesh.h"
#include "../mesh.h"
#include "../resourceManager.h"
#include "../fontRenderer.h"
#include "../../int.h"
#include "../program.h"
#include "../shader.h"
#include "../program.h"
#include "../vector4.h"
#include "../vector3.h"
#include "../vector2.h"
#include "../event.h"
#include "renderPass.h"
typedef struct quads{
mesh * mesh;
fontRenderer * font;
sampler2D * samplerArray;
program * program;
vector_quadMesh * meshes;
vector_element * elements;
vector_int * mouseOverElements;
} quads;
char * quads_textFromNumber( quads * this, int i );
void quads_prepare( quads * this );
void quads_sortOpacity( quads * this, vector_quadMesh * meshes );
void quads_createMeshes( quads * this );
quadMesh quads_updateMesh( quads * this, quadMesh currentMesh, element currentElement );
void quads_callElementEvents( quads * this, event * currentEvent, element * currentElement, int elementIndex );
bool quads_integerContains( quads * this, vector_int * numbers, int a );
void quads_render( quads * this );
extern resourceManager * resources;
extern event * globalEvent;
quads quads_new( );
quads * quads_newPointer( );
#endif
typedef struct quads quads;

View File

@@ -0,0 +1,137 @@
/*
* This file is automaticaly generated, Please dont edit this file!
*/
#include <engine/renderPasses/renderPassTesselation.h>
char * tesselation_textFromNumber( tesselation * this, int i ) {
char * fileName = malloc( sizeof( char ) * 100 );
sprintf( fileName, "%d", i );
return fileName;
}
void tesselation_prepare( tesselation * this ) {
shader * vertexShader = shader_newPointer( GL_VERTEX_SHADER );
shader_loadFromFile( vertexShader, "assets/shaders/quadScale.vertex" );
shader * fragmentShader = shader_newPointer( GL_FRAGMENT_SHADER );
shader_loadFromFile( fragmentShader, "assets/shaders/color.fragment" );
shader * geometryShader = shader_newPointer( GL_GEOMETRY_SHADER );
shader_loadFromFile( geometryShader, "assets/shaders/tesselation.geometry.shader" );
shader * tesselationControlShader = shader_newPointer( GL_TESS_CONTROL_SHADER );
shader_loadFromFile( tesselationControlShader, "assets/shaders/tesselation.triangle.tsc.shader" );
shader * tesselationEvaluationShader = shader_newPointer( GL_TESS_EVALUATION_SHADER );
shader_loadFromFile( tesselationEvaluationShader, "assets/shaders/tesselation.triangle.shader" );
this->program = program_newPointer();
program_addShader( this->program, vertexShader );
program_addShader( this->program, fragmentShader );
program_create( this->program );
this->mesh = mesh_newPointer();
mesh_setProgram( this->mesh, this->program );
mesh_createBuffers( this->mesh );
glUseProgram( this->program->glProgram );
}
void tesselation_render( tesselation * this ) {
glUseProgram( this->program->glProgram );
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
int numItems = 12;
glBindVertexArray( this->mesh->vertexArrayObject );
glDrawElements( GL_LINE_STRIP, numItems, GL_UNSIGNED_INT, ( void * ) 0 );
}
tesselation tesselation_new() {
tesselation instance;
instance.font = fontRenderer_newPointer();
return instance;
}
tesselation * tesselation_newPointer() {
struct tesselation * pointer = malloc( sizeof ( struct tesselation ) );
pointer->font = fontRenderer_newPointer();
return pointer;
}

View File

@@ -0,0 +1,63 @@
#ifndef _renderPassTesselation
#define _renderPassTesselation
// Macros
#include "stdlib.h"
extern char * __ClassNames[];
// Includes
#include "../mesh.h"
#include "../program.h"
#include "../fontRenderer.h"
#include "int.h"
#include "../shader.h"
#include "../vector2.h"
#include "../event.h"
#include "renderPass.h"
typedef struct tesselation{
struct program * program;
struct mesh * mesh;
fontRenderer * font;
sampler2D * samplerArray;
} tesselation;
char * tesselation_textFromNumber( tesselation * this, int i );
void tesselation_prepare( tesselation * this );
void tesselation_render( tesselation * this );
tesselation tesselation_new( );
tesselation * tesselation_newPointer( );
#endif
typedef struct tesselation tesselation;

View File

@@ -0,0 +1,127 @@
/*
* This file is automaticaly generated, Please dont edit this file!
*/
#include <engine/resourceManager.h>
texture2D * resourceManager_loadPngImage( resourceManager * this, char * name ) {
texture2D * texture = texture2D_newPointer();
png_structp png_ptr;
png_infop info_ptr;
unsigned int sig_read = 0;
int color_type;
int interlace_type;
FILE * fp;
if ( ( fp = fopen( name, "rb" ) ) == NULL ) {
return NULL;
}
png_ptr = png_create_read_struct( PNG_LIBPNG_VER_STRING, NULL, NULL, NULL );
if ( png_ptr == NULL ) {
fclose( fp );
return false;
}
info_ptr = png_create_info_struct( png_ptr );
if ( info_ptr == NULL ) {
fclose(fp);
png_destroy_read_struct( &png_ptr, NULL, NULL );
return false;
}
if ( setjmp( png_jmpbuf( png_ptr ) ) ) {
png_destroy_read_struct( &png_ptr, &info_ptr, NULL );
fclose( fp );
return false;
}
png_init_io( png_ptr, fp );
png_set_sig_bytes( png_ptr, sig_read );
png_read_png( png_ptr, info_ptr, PNG_TRANSFORM_STRIP_16 | PNG_TRANSFORM_PACKING | PNG_TRANSFORM_EXPAND, NULL );
png_uint_32 width, height;
int bit_depth;
png_get_IHDR( png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, &interlace_type, NULL, NULL );
unsigned int row_bytes = png_get_rowbytes( png_ptr, info_ptr );
texture->width = width;
texture->height = height;
texture->hasAlpha = ( color_type == PNG_COLOR_TYPE_RGBA );
texture->data = ( unsigned char * ) malloc( row_bytes * texture->height );
png_bytepp row_pointers = png_get_rows( png_ptr, info_ptr );
for (int i = 0; i < texture->height; i++) {
memcpy( texture->data + ( row_bytes * ( texture->height - 1 - i ) ), row_pointers[ i ], row_bytes );
}
png_destroy_read_struct( &png_ptr, &info_ptr, NULL );
fclose( fp );
return texture;
}
resourceManager resourceManager_new() {
resourceManager instance;
return instance;
}
resourceManager * resourceManager_newPointer() {
struct resourceManager * pointer = malloc( sizeof ( struct resourceManager ) );
return pointer;
}

View File

@@ -0,0 +1,43 @@
#ifndef _resourceManager
#define _resourceManager
// Macros
#include "stdlib.h"
extern char * __ClassNames[];
// Includes
#include "string.h"
#include "stdbool.h"
#include <png.h>
#include "texture2D.h"
typedef struct resourceManager{
} resourceManager;
texture2D * resourceManager_loadPngImage( resourceManager * this, char * name );
resourceManager resourceManager_new( );
resourceManager * resourceManager_newPointer( );
#endif
typedef struct resourceManager resourceManager;

View File

@@ -0,0 +1,293 @@
/*
* This file is automaticaly generated, Please dont edit this file!
*/
#include <engine/sampler2D.h>
void sampler2D_constructor( sampler2D * this ) {
glGenTextures( 1, &this->glTexture );
}
void sampler2D_addTexture( sampler2D * this, texture2D * texture ) {
array_add( this->textures, texture );
}
int sampler2D_getTextureIndex( sampler2D * this ) {
int numberOfTextures = array_length( this->textures );
return numberOfTextures;
}
void sampler2D_bind( sampler2D * this ) {
this->binded = true;
glActiveTexture( GL_TEXTURE0 + this->index );
glBindTexture( this->target, this->glTexture );
glTexParameteri( this->target, GL_TEXTURE_WRAP_S, this->WRAP_S );
glTexParameteri( this->target, GL_TEXTURE_WRAP_T, this->WRAP_T );
glTexParameteri( this->target, GL_TEXTURE_MIN_FILTER, this->MIN_FILTER );
glTexParameteri( this->target, GL_TEXTURE_MAG_FILTER, this->MAG_FILTER );
if( this->target == GL_TEXTURE_2D_ARRAY ) {
int offsetX = 0;
int offsetY = 0;
int offsetZ = 0;
int depth = 1;
int levelOfDetail = 0;
int layerCount = 2;
int mipLevelCount = 1;
int currentLayer = 0;
texture2D * texture1 = array_get( this->textures, 0 );
int numberOfTextures = array_length( this->textures );
if( this->cubeSize == NULL ) {
this->cubeSize = vector3_newPointer( texture1->width, texture1->height, numberOfTextures );
}
if( this->UNPACK_ALIGNMENT ) {
glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
} else {
glPixelStorei( GL_UNPACK_ALIGNMENT, 0 );
}
glTexStorage3D( this->target, mipLevelCount, this->format, this->cubeSize->x, this->cubeSize->y, numberOfTextures );
GLint data[ texture1->width * texture1->height * numberOfTextures ];
glTexImage3D( GL_TEXTURE_2D_ARRAY, levelOfDetail, this->internalFormat, this->cubeSize->x, this->cubeSize->y, numberOfTextures, this->border, this->format, this->type, data);
for (int i = 0; i < numberOfTextures; ++i)
{
texture2D * currentTexture = array_get( this->textures, i );
float test = 0;
glTexSubImage3D( this->target,
0,
offsetX, test , i,
currentTexture->width, currentTexture->height, 1,
this->format,
this->type,
currentTexture->data );
}
} else {
texture2D * texture = array_get( this->textures, 0 );
glTexImage2D( this->target, 0, this->internalFormat, texture->width, texture->height, this->border, this->format, this->type, texture->data );
}
if( this->generateMipmap ) {
glGenerateMipmap( this->target );
}
}
sampler2D sampler2D_new() {
sampler2D instance;
instance.textures = array_newPointer();
instance.binded = false;
instance.filter = GL_LINEAR;
instance.MIN_FILTER = GL_LINEAR;
instance.MAG_FILTER = GL_LINEAR;
instance.WRAP_S = GL_REPEAT;
instance.WRAP_T = GL_REPEAT;
instance.datatype = GL_RGBA;
instance.format = GL_RGBA;
instance.internalFormat = GL_RGBA;
instance.target = GL_TEXTURE_2D;
instance.type = GL_UNSIGNED_BYTE;
instance.cubeSize = NULL;
instance.border = false;
instance.generateMipmap = true;
instance.UNPACK_ALIGNMENT = false;
instance.index = 0;
sampler2D_constructor( &instance);
return instance;
}
sampler2D * sampler2D_newPointer() {
struct sampler2D * pointer = malloc( sizeof ( struct sampler2D ) );
pointer->textures = array_newPointer();
pointer->binded = false;
pointer->filter = GL_LINEAR;
pointer->MIN_FILTER = GL_LINEAR;
pointer->MAG_FILTER = GL_LINEAR;
pointer->WRAP_S = GL_REPEAT;
pointer->WRAP_T = GL_REPEAT;
pointer->datatype = GL_RGBA;
pointer->format = GL_RGBA;
pointer->internalFormat = GL_RGBA;
pointer->target = GL_TEXTURE_2D;
pointer->type = GL_UNSIGNED_BYTE;
pointer->cubeSize = NULL;
pointer->border = false;
pointer->generateMipmap = true;
pointer->UNPACK_ALIGNMENT = false;
pointer->index = 0;
sampler2D_constructor( pointer );
return pointer;
}

View File

@@ -0,0 +1,96 @@
#ifndef _sampler2D
#define _sampler2D
// Macros
#define GL_GLEXT_PROTOTYPES
#include "stdlib.h"
extern char * __ClassNames[];
// Includes
#include "../vector3.h"
#include "../array.h"
#include "stdbool.h"
#include "./texture2D.h"
#include <GL/glx.h>
#include <GL/gl.h>
#include <GL/glext.h>
typedef struct sampler2D{
texture2D * texture;
array * textures;
GLuint glTexture;
GLint binded;
GLint filter;
GLint MIN_FILTER;
GLint MAG_FILTER;
GLint WRAP_S;
GLint WRAP_T;
GLint datatype;
GLint format;
GLint internalFormat;
GLint target;
GLint type;
vector3 * cubeSize;
GLint border;
GLint generateMipmap;
bool UNPACK_ALIGNMENT;
GLuint index;
} sampler2D;
void sampler2D_constructor( sampler2D * this );
void sampler2D_addTexture( sampler2D * this, texture2D * texture );
int sampler2D_getTextureIndex( sampler2D * this );
void sampler2D_bind( sampler2D * this );
sampler2D sampler2D_new( );
sampler2D * sampler2D_newPointer( );
#endif
typedef struct sampler2D sampler2D;

View File

@@ -0,0 +1,125 @@
/*
* This file is automaticaly generated, Please dont edit this file!
*/
#include <engine/shader.h>
void shader_constructor( shader * this, GLuint shaderType ) {
this->glShader = glCreateShader( shaderType );
}
void shader_loadFromFile( shader * this, char * shaderPath ) {
text * shaderSource = fileSystem_readFile( filesystem, shaderPath, "utf8" );
glShaderSource( this->glShader, 1, &shaderSource->value, NULL );
glCompileShader( this->glShader );
shader_checkShaderForErrors( this, this->glShader );
}
void shader_checkShaderForErrors( shader * this, GLuint shader ) {
GLint isCompiled = 0;
glGetShaderiv( shader, GL_COMPILE_STATUS, &isCompiled );
if( isCompiled == GL_FALSE )
{
GLint maxLength = 0;
glGetShaderiv( shader, GL_INFO_LOG_LENGTH, &maxLength );
GLchar errorMessage[ maxLength ];
glGetShaderInfoLog( shader, maxLength, &maxLength, errorMessage );
printf("\n\n\n\n Error: %s\n\n\n\n\n\n", errorMessage);
glDeleteShader( shader );
exit( 0 );
return;
}
}
shader shader_new(GLuint shaderType) {
shader instance;
shader_constructor( &instance, shaderType);
return instance;
}
shader * shader_newPointer(GLuint shaderType) {
struct shader * pointer = malloc( sizeof ( struct shader ) );
shader_constructor( pointer , shaderType);
return pointer;
}
attribute attribute_new() {
attribute instance;
return instance;
}
attribute * attribute_newPointer() {
struct attribute * pointer = malloc( sizeof ( struct attribute ) );
return pointer;
}

View File

@@ -0,0 +1,87 @@
#ifndef _shader
#define _shader
// Macros
#define GL_GLEXT_PROTOTYPES
#include "stdlib.h"
extern char * __ClassNames[];
// Includes
#include "sampler2D.h"
#include "../char.h"
#include "../array.h"
#include "../fileSystem.h"
#include <stdio.h>
#include <GL/glx.h>
#include <GL/gl.h>
#include <GL/glext.h>
#include "uniform.h"
#include "member.h"
#include "block.h"
typedef struct shader{
GLuint glShader;
} shader;
void shader_constructor( shader * this, GLuint shaderType );
void shader_loadFromFile( shader * this, char * shaderPath );
void shader_checkShaderForErrors( shader * this, GLuint shader );
typedef struct attribute{
GLchar name[64];
GLint location;
GLenum type;
} attribute;
shader shader_new( GLuint shaderType );
shader * shader_newPointer( GLuint shaderType );
attribute attribute_new( );
attribute * attribute_newPointer( );
#endif
typedef struct shader shader;
typedef struct attribute attribute;

View File

@@ -0,0 +1,23 @@
/*
* This file is automaticaly generated, Please dont edit this file!
*/
#include <engine/texture2D.h>
texture2D texture2D_new() {
texture2D instance;
return instance;
}
texture2D * texture2D_newPointer() {
struct texture2D * pointer = malloc( sizeof ( struct texture2D ) );
return pointer;
}

View File

@@ -0,0 +1,54 @@
#ifndef _texture2D
#define _texture2D
// Macros
#define GL_GLEXT_PROTOTYPES
#include "stdlib.h"
extern char * __ClassNames[];
// Includes
#include "vector2.h"
#include <GL/glx.h>
#include <GL/gl.h>
#include <GL/glext.h>
typedef struct texture2D{
GLubyte * data;
int width;
int height;
int hasAlpha;
vector2 * offset;
} texture2D;
texture2D texture2D_new( );
texture2D * texture2D_newPointer( );
#endif
typedef struct texture2D texture2D;

View File

@@ -0,0 +1,23 @@
/*
* This file is automaticaly generated, Please dont edit this file!
*/
#include <engine/uniform.h>
uniform uniform_new() {
uniform instance;
return instance;
}
uniform * uniform_newPointer() {
struct uniform * pointer = malloc( sizeof ( struct uniform ) );
return pointer;
}

View File

@@ -0,0 +1,54 @@
#ifndef _uniform
#define _uniform
// Macros
#define GL_GLEXT_PROTOTYPES
#include "stdlib.h"
extern char * __ClassNames[];
// Includes
#include <GL/glx.h>
#include <GL/gl.h>
#include <GL/glext.h>
typedef struct uniform{
char name[64];
GLint index;
GLint location;
GLint offset;
GLint size;
GLenum type;
} uniform;
uniform uniform_new( );
uniform * uniform_newPointer( );
#endif
typedef struct uniform uniform;

View File

@@ -0,0 +1,182 @@
/*
* This file is automaticaly generated, Please dont edit this file!
*/
#include <engine/unsignedIntegerArray.h>
int unsignedIntegerArray_length( unsignedIntegerArray * this ) {
return this->total;
}
unsigned int unsignedIntegerArray_get( unsignedIntegerArray * this, int index ) {
return this->items[index];
}
void unsignedIntegerArray_set( unsignedIntegerArray * this, int index, unsigned int item ) {
if ( index >= 0 && index < this->total ){
this->items[ index ] = item;
}
}
void unsignedIntegerArray_resize( unsignedIntegerArray * this, int capacity ) {
int * items = realloc( this->items, sizeof( int ) * capacity );
this->items = items;
this->capacity = capacity;
}
void unsignedIntegerArray_addVector2( unsignedIntegerArray * this, struct vector2 * item ) {
unsignedIntegerArray_add( this, item->x );
unsignedIntegerArray_add( this, item->y );
}
void unsignedIntegerArray_addVector3( unsignedIntegerArray * this, struct vector3 * item ) {
unsignedIntegerArray_add( this, item->x );
unsignedIntegerArray_add( this, item->y );
unsignedIntegerArray_add( this, item->z );
}
void unsignedIntegerArray_add( unsignedIntegerArray * this, unsigned int item ) {
if ( this->capacity == this->total ){
unsignedIntegerArray_resize( this, this->capacity * 2 );
}
this->items[ this->total++ ] = item;
}
void unsignedIntegerArray_delete( unsignedIntegerArray * this, int index ) {
if ( index < 0 || index >= this->total ){
return;
}
this->items[index] = 0.0;
for ( int i = index; i < this->total - 1; i++ ) {
this->items[i] = this->items[i + 1];
this->items[i + 1] = 0.0;
}
this->total--;
if ( this->total > 0 && this->total == this->capacity / 4 ){
unsignedIntegerArray_resize( this, this->capacity / 2 );
}
}
unsigned int unsignedIntegerArray_array_push( unsignedIntegerArray * this, unsigned int item ) {
unsignedIntegerArray_add( this, item );
return this->total;
}
void unsignedIntegerArray_unshift( unsignedIntegerArray * this, int item ) {
int length = this->total;
this->total++;
if ( this->capacity == this->total ){
unsignedIntegerArray_resize( this, this->capacity * 2 );
}
for ( int i = length - 1; i >= 0; --i ) {
this->items[ i + 1 ] = this->items[ i ];
}
this->items[ 0 ] = item;
}
unsigned int unsignedIntegerArray_pop( unsignedIntegerArray * this ) {
int length = this->total;
int lastIndex = length - 1;
int lastItem = unsignedIntegerArray_get( this, lastIndex );
unsignedIntegerArray_delete( this, lastIndex );
return lastItem;
}
unsignedIntegerArray unsignedIntegerArray_new() {
unsignedIntegerArray instance;
instance.capacity = 10;
instance.total = 0;
instance.items = malloc( 10000000 );
return instance;
}
unsignedIntegerArray * unsignedIntegerArray_newPointer() {
struct unsignedIntegerArray * pointer = malloc( sizeof ( struct unsignedIntegerArray ) );
pointer->capacity = 10;
pointer->total = 0;
pointer->items = malloc( 10000000 );
return pointer;
}

View File

@@ -0,0 +1,65 @@
#ifndef _unsignedIntegerArray
#define _unsignedIntegerArray
// Macros
#include "stdlib.h"
extern char * __ClassNames[];
// Includes
#include <vector2.h>
#include <vector3.h>
typedef struct unsignedIntegerArray{
int capacity;
int total;
unsigned int * items;
} unsignedIntegerArray;
int unsignedIntegerArray_length( unsignedIntegerArray * this );
unsigned int unsignedIntegerArray_get( unsignedIntegerArray * this, int index );
void unsignedIntegerArray_set( unsignedIntegerArray * this, int index, unsigned int item );
void unsignedIntegerArray_resize( unsignedIntegerArray * this, int capacity );
void unsignedIntegerArray_addVector2( unsignedIntegerArray * this, struct vector2 * item );
void unsignedIntegerArray_addVector3( unsignedIntegerArray * this, struct vector3 * item );
void unsignedIntegerArray_add( unsignedIntegerArray * this, unsigned int item );
void unsignedIntegerArray_delete( unsignedIntegerArray * this, int index );
unsigned int unsignedIntegerArray_array_push( unsignedIntegerArray * this, unsigned int item );
void unsignedIntegerArray_unshift( unsignedIntegerArray * this, int item );
unsigned int unsignedIntegerArray_pop( unsignedIntegerArray * this );
unsignedIntegerArray unsignedIntegerArray_new( );
unsignedIntegerArray * unsignedIntegerArray_newPointer( );
#endif
typedef struct unsignedIntegerArray unsignedIntegerArray;

View File

@@ -0,0 +1,997 @@
/*
* This file is automaticaly generated, Please dont edit this file!
*/
#include <engine/vector.h>
int vector_char_pointer_length( vector_char_pointer * this ) {
return this->total;
}
char * vector_char_pointer_get( vector_char_pointer * this, int index ) {
return this->items[index];
}
void vector_char_pointer_set( vector_char_pointer * this, int index, char * item ) {
if ( index >= 0 && index < this->total ){
this->items[ index ] = item;
}
}
void vector_char_pointer_resize( vector_char_pointer * this, int capacity ) {
char * * items = realloc( this->items, sizeof( char * ) * capacity );
this->items = items;
this->capacity = capacity;
}
void vector_char_pointer_add( vector_char_pointer * this, char * item ) {
if ( this->capacity == this->total ){
vector_char_pointer_resize( this, this->capacity * 2 );
}
this->items[ this->total++ ] = item;
}
void vector_char_pointer_delete( vector_char_pointer * this, int index ) {
for ( int i = index; i < this->total - 1; i++ ) {
this->items[i] = this->items[i + 1];
}
this->total--;
}int vector_char_pointer_array_push( vector_char_pointer * this, char * item ) {
vector_char_pointer_add( this, item );
return this->total;
}
void vector_char_pointer_unshift( vector_char_pointer * this, char * item ) {
int length = this->total;
this->total++;
if ( this->capacity == this->total ){
vector_char_pointer_resize( this, this->capacity * 2 );
}
for ( int i = length - 1; i >= 0; --i ) {
this->items[ i + 1 ] = this->items[ i ];
}
this->items[ 0 ] = item;
}int vector_quadMesh_length( vector_quadMesh * this ) {
return this->total;
}
quadMesh vector_quadMesh_get( vector_quadMesh * this, int index ) {
return this->items[index];
}
void vector_quadMesh_set( vector_quadMesh * this, int index, quadMesh item ) {
if ( index >= 0 && index < this->total ){
this->items[ index ] = item;
}
}
void vector_quadMesh_resize( vector_quadMesh * this, int capacity ) {
quadMesh * items = realloc( this->items, sizeof( quadMesh ) * capacity );
this->items = items;
this->capacity = capacity;
}
void vector_quadMesh_add( vector_quadMesh * this, quadMesh item ) {
if ( this->capacity == this->total ){
vector_quadMesh_resize( this, this->capacity * 2 );
}
this->items[ this->total++ ] = item;
}
void vector_quadMesh_delete( vector_quadMesh * this, int index ) {
for ( int i = index; i < this->total - 1; i++ ) {
this->items[i] = this->items[i + 1];
}
this->total--;
}int vector_quadMesh_array_push( vector_quadMesh * this, quadMesh item ) {
vector_quadMesh_add( this, item );
return this->total;
}
void vector_quadMesh_unshift( vector_quadMesh * this, quadMesh item ) {
int length = this->total;
this->total++;
if ( this->capacity == this->total ){
vector_quadMesh_resize( this, this->capacity * 2 );
}
for ( int i = length - 1; i >= 0; --i ) {
this->items[ i + 1 ] = this->items[ i ];
}
this->items[ 0 ] = item;
}int vector_element_length( vector_element * this ) {
return this->total;
}
element vector_element_get( vector_element * this, int index ) {
return this->items[index];
}
void vector_element_set( vector_element * this, int index, element item ) {
if ( index >= 0 && index < this->total ){
this->items[ index ] = item;
}
}
void vector_element_resize( vector_element * this, int capacity ) {
element * items = realloc( this->items, sizeof( element ) * capacity );
this->items = items;
this->capacity = capacity;
}
void vector_element_add( vector_element * this, element item ) {
if ( this->capacity == this->total ){
vector_element_resize( this, this->capacity * 2 );
}
this->items[ this->total++ ] = item;
}
void vector_element_delete( vector_element * this, int index ) {
for ( int i = index; i < this->total - 1; i++ ) {
this->items[i] = this->items[i + 1];
}
this->total--;
}int vector_element_array_push( vector_element * this, element item ) {
vector_element_add( this, item );
return this->total;
}
void vector_element_unshift( vector_element * this, element item ) {
int length = this->total;
this->total++;
if ( this->capacity == this->total ){
vector_element_resize( this, this->capacity * 2 );
}
for ( int i = length - 1; i >= 0; --i ) {
this->items[ i + 1 ] = this->items[ i ];
}
this->items[ 0 ] = item;
}int vector_int_length( vector_int * this ) {
return this->total;
}
int vector_int_get( vector_int * this, int index ) {
return this->items[index];
}
void vector_int_set( vector_int * this, int index, int item ) {
if ( index >= 0 && index < this->total ){
this->items[ index ] = item;
}
}
void vector_int_resize( vector_int * this, int capacity ) {
int * items = realloc( this->items, sizeof( int ) * capacity );
this->items = items;
this->capacity = capacity;
}
void vector_int_add( vector_int * this, int item ) {
if ( this->capacity == this->total ){
vector_int_resize( this, this->capacity * 2 );
}
this->items[ this->total++ ] = item;
}
void vector_int_delete( vector_int * this, int index ) {
for ( int i = index; i < this->total - 1; i++ ) {
this->items[i] = this->items[i + 1];
}
this->total--;
}int vector_int_array_push( vector_int * this, int item ) {
vector_int_add( this, item );
return this->total;
}
void vector_int_unshift( vector_int * this, int item ) {
int length = this->total;
this->total++;
if ( this->capacity == this->total ){
vector_int_resize( this, this->capacity * 2 );
}
for ( int i = length - 1; i >= 0; --i ) {
this->items[ i + 1 ] = this->items[ i ];
}
this->items[ 0 ] = item;
}int vector_vector2_length( vector_vector2 * this ) {
return this->total;
}
vector2 vector_vector2_get( vector_vector2 * this, int index ) {
return this->items[index];
}
void vector_vector2_set( vector_vector2 * this, int index, vector2 item ) {
if ( index >= 0 && index < this->total ){
this->items[ index ] = item;
}
}
void vector_vector2_resize( vector_vector2 * this, int capacity ) {
vector2 * items = realloc( this->items, sizeof( vector2 ) * capacity );
this->items = items;
this->capacity = capacity;
}
void vector_vector2_add( vector_vector2 * this, vector2 item ) {
if ( this->capacity == this->total ){
vector_vector2_resize( this, this->capacity * 2 );
}
this->items[ this->total++ ] = item;
}
void vector_vector2_delete( vector_vector2 * this, int index ) {
for ( int i = index; i < this->total - 1; i++ ) {
this->items[i] = this->items[i + 1];
}
this->total--;
}int vector_vector2_array_push( vector_vector2 * this, vector2 item ) {
vector_vector2_add( this, item );
return this->total;
}
void vector_vector2_unshift( vector_vector2 * this, vector2 item ) {
int length = this->total;
this->total++;
if ( this->capacity == this->total ){
vector_vector2_resize( this, this->capacity * 2 );
}
for ( int i = length - 1; i >= 0; --i ) {
this->items[ i + 1 ] = this->items[ i ];
}
this->items[ 0 ] = item;
}
vector_char_pointer vector_char_pointer_new() {
vector_char_pointer instance;
instance.capacity = 10;
instance.total = 0;
instance.items = malloc( 10000000 );
return instance;
}
vector_char_pointer * vector_char_pointer_newPointer() {
struct vector_char_pointer * pointer = malloc( sizeof ( struct vector_char_pointer ) );
pointer->capacity = 10;
pointer->total = 0;
pointer->items = malloc( 10000000 );
return pointer;
}
vector_quadMesh vector_quadMesh_new() {
vector_quadMesh instance;
instance.capacity = 10;
instance.total = 0;
instance.items = malloc( 10000000 );
return instance;
}
vector_quadMesh * vector_quadMesh_newPointer() {
struct vector_quadMesh * pointer = malloc( sizeof ( struct vector_quadMesh ) );
pointer->capacity = 10;
pointer->total = 0;
pointer->items = malloc( 10000000 );
return pointer;
}
vector_element vector_element_new() {
vector_element instance;
instance.capacity = 10;
instance.total = 0;
instance.items = malloc( 10000000 );
return instance;
}
vector_element * vector_element_newPointer() {
struct vector_element * pointer = malloc( sizeof ( struct vector_element ) );
pointer->capacity = 10;
pointer->total = 0;
pointer->items = malloc( 10000000 );
return pointer;
}
vector_int vector_int_new() {
vector_int instance;
instance.capacity = 10;
instance.total = 0;
instance.items = malloc( 10000000 );
return instance;
}
vector_int * vector_int_newPointer() {
struct vector_int * pointer = malloc( sizeof ( struct vector_int ) );
pointer->capacity = 10;
pointer->total = 0;
pointer->items = malloc( 10000000 );
return pointer;
}
vector_vector2 vector_vector2_new() {
vector_vector2 instance;
instance.capacity = 10;
instance.total = 0;
instance.items = malloc( 10000000 );
return instance;
}
vector_vector2 * vector_vector2_newPointer() {
struct vector_vector2 * pointer = malloc( sizeof ( struct vector_vector2 ) );
pointer->capacity = 10;
pointer->total = 0;
pointer->items = malloc( 10000000 );
return pointer;
}

View File

@@ -0,0 +1,217 @@
#ifndef _vector
#define _vector
// Macros
#include "stdlib.h"
extern char * __ClassNames[];
// Includes
#include "../int.h"
#include "../vector2.h"
#include "quadMesh.h"
#include "element.h"
typedef struct vector_char_pointer{
int capacity;
int total;
char * * items;
} vector_char_pointer;
int vector_char_pointer_length( vector_char_pointer * this );
char * vector_char_pointer_get( vector_char_pointer * this, int index );
void vector_char_pointer_set( vector_char_pointer * this, int index, char * item );
void vector_char_pointer_resize( vector_char_pointer * this, int capacity );
void vector_char_pointer_add( vector_char_pointer * this, char * item );
void vector_char_pointer_delete( vector_char_pointer * this, int index );
int vector_char_pointer_array_push( vector_char_pointer * this, char * item );
void vector_char_pointer_unshift( vector_char_pointer * this, char * item );
typedef struct vector_quadMesh{
int capacity;
int total;
quadMesh * items;
} vector_quadMesh;
int vector_quadMesh_length( vector_quadMesh * this );
quadMesh vector_quadMesh_get( vector_quadMesh * this, int index );
void vector_quadMesh_set( vector_quadMesh * this, int index, quadMesh item );
void vector_quadMesh_resize( vector_quadMesh * this, int capacity );
void vector_quadMesh_add( vector_quadMesh * this, quadMesh item );
void vector_quadMesh_delete( vector_quadMesh * this, int index );
int vector_quadMesh_array_push( vector_quadMesh * this, quadMesh item );
void vector_quadMesh_unshift( vector_quadMesh * this, quadMesh item );
typedef struct vector_element{
int capacity;
int total;
element * items;
} vector_element;
int vector_element_length( vector_element * this );
element vector_element_get( vector_element * this, int index );
void vector_element_set( vector_element * this, int index, element item );
void vector_element_resize( vector_element * this, int capacity );
void vector_element_add( vector_element * this, element item );
void vector_element_delete( vector_element * this, int index );
int vector_element_array_push( vector_element * this, element item );
void vector_element_unshift( vector_element * this, element item );
typedef struct vector_int{
int capacity;
int total;
int * items;
} vector_int;
int vector_int_length( vector_int * this );
int vector_int_get( vector_int * this, int index );
void vector_int_set( vector_int * this, int index, int item );
void vector_int_resize( vector_int * this, int capacity );
void vector_int_add( vector_int * this, int item );
void vector_int_delete( vector_int * this, int index );
int vector_int_array_push( vector_int * this, int item );
void vector_int_unshift( vector_int * this, int item );
typedef struct vector_vector2{
int capacity;
int total;
vector2 * items;
} vector_vector2;
int vector_vector2_length( vector_vector2 * this );
vector2 vector_vector2_get( vector_vector2 * this, int index );
void vector_vector2_set( vector_vector2 * this, int index, vector2 item );
void vector_vector2_resize( vector_vector2 * this, int capacity );
void vector_vector2_add( vector_vector2 * this, vector2 item );
void vector_vector2_delete( vector_vector2 * this, int index );
int vector_vector2_array_push( vector_vector2 * this, vector2 item );
void vector_vector2_unshift( vector_vector2 * this, vector2 item );
vector_char_pointer vector_char_pointer_new( );
vector_char_pointer * vector_char_pointer_newPointer( );
vector_quadMesh vector_quadMesh_new( );
vector_quadMesh * vector_quadMesh_newPointer( );
vector_element vector_element_new( );
vector_element * vector_element_newPointer( );
vector_int vector_int_new( );
vector_int * vector_int_newPointer( );
vector_vector2 vector_vector2_new( );
vector_vector2 * vector_vector2_newPointer( );
#endif
typedef struct vector vector;
typedef struct vector_char_pointer vector_char_pointer;
typedef struct vector_quadMesh vector_quadMesh;
typedef struct vector_element vector_element;
typedef struct vector_int vector_int;
typedef struct vector_vector2 vector_vector2;

View File

@@ -0,0 +1,75 @@
/*
* This file is automaticaly generated, Please dont edit this file!
*/
#include <engine/vector4.h>
void vector4_constructor( vector4 * this, float x, float y, float z, float w ) {
this->x = x;
this->y = y;
this->z = z;
this->w = w;
}
vector4 * vector4_operator_plus( vector4 * this, vector4 * b ) {
vector4_add( this, b );
return this;
}
vector4 * vector4_operator_add( vector4 * this, vector4 * b ) {
vector4_add( this, b );
return this;
}
void vector4_add( vector4 * this, vector4 * b ) {
this->x += b->x;
this->y += b->y;
this->z += b->z;
this->w += b->w;
}
vector4 vector4_new(float x, float y, float z, float w) {
vector4 instance;
vector4_constructor( &instance, x, y, z, w);
return instance;
}
vector4 * vector4_newPointer(float x, float y, float z, float w) {
struct vector4 * pointer = malloc( sizeof ( struct vector4 ) );
vector4_constructor( pointer , x, y, z, w);
return pointer;
}

View File

@@ -0,0 +1,49 @@
#ifndef _vector4
#define _vector4
// Macros
#include "stdlib.h"
extern char * __ClassNames[];
// Includes
typedef struct vector4{
float x;
float y;
float z;
float w;
} vector4;
void vector4_constructor( vector4 * this, float x, float y, float z, float w );
vector4 * vector4_operator_plus( vector4 * this, vector4 * b );
vector4 * vector4_operator_add( vector4 * this, vector4 * b );
void vector4_add( vector4 * this, vector4 * b );
vector4 vector4_new( float x, float y, float z, float w );
vector4 * vector4_newPointer( float x, float y, float z, float w );
#endif
typedef struct vector4 vector4;

View File

@@ -0,0 +1,179 @@
/*
* This file is automaticaly generated, Please dont edit this file!
*/
#include <engine/windowManager.h>
static int DoubleBufferAttributes[] = {
GLX_RGBA,
GLX_RED_SIZE, 1,
GLX_GREEN_SIZE, 1,
GLX_BLUE_SIZE, 1,
GLX_DEPTH_SIZE, 12,
GLX_DOUBLEBUFFER,
None,
};
void windowManager_setupDisplay( windowManager * this ) {
this->mainDisplay = XOpenDisplay( 0 );
this->MainScreen = XDefaultScreen( this->mainDisplay );
}
void windowManager_setupWindow( windowManager * this ) {
this->RootWindow = XDefaultRootWindow( this->mainDisplay );
int empty;
int ResultStatus = glXQueryExtension( this->mainDisplay, &empty, &empty );
XVisualInfo* VisualInfo = glXChooseVisual( this->mainDisplay, this->MainScreen, DoubleBufferAttributes );
GLXContext ShareList = None;
int IsDirectRendering = True;
GLXContext OpenGLContext = glXCreateContext( this->mainDisplay, VisualInfo, ShareList, IsDirectRendering );
int WindowX = 0;
int WindowY = 0;
int WindowWidth = 1000;
int WindowHeight = 1024;
int BorderWidth = 0;
int WindowClass = InputOutput;
int WindowDepth = VisualInfo->depth;
Visual* WindowVisual = VisualInfo->visual;
int AttributeValueMask = CWBackPixel | CWEventMask | CWColormap;
XSetWindowAttributes WindowAttributes = {};
WindowAttributes.colormap = XCreateColormap( this->mainDisplay, this->RootWindow, VisualInfo->visual, AllocNone );
WindowAttributes.background_pixel = 0;
WindowAttributes.event_mask = StructureNotifyMask | KeyPressMask | KeyReleaseMask | PointerMotionMask;
this->mainWindow = XCreateWindow( this->mainDisplay, this->RootWindow,
WindowX, WindowY, WindowWidth, WindowHeight,
BorderWidth, WindowDepth, WindowClass, WindowVisual,
AttributeValueMask, &WindowAttributes);
XMoveWindow( this->mainDisplay, this->mainWindow, -400, 0 );
XStoreName( this->mainDisplay, this->mainWindow, "Opengl: Fixed function pipeline" );
glXMakeCurrent( this->mainDisplay, this->mainWindow, OpenGLContext );
XMapWindow( this->mainDisplay, this->mainWindow );
Atom WM_DELETE_WINDOW = XInternAtom( this->mainDisplay, "WM_DELETE_WINDOW", False );
if( !XSetWMProtocols( this->mainDisplay, this->mainWindow, &WM_DELETE_WINDOW, 1) ) {
printf( "Couldn't register WM_DELETE_WINDOW\n" );
}
}
windowManager windowManager_new() {
windowManager instance;
return instance;
}
windowManager * windowManager_newPointer() {
struct windowManager * pointer = malloc( sizeof ( struct windowManager ) );
return pointer;
}

View File

@@ -0,0 +1,64 @@
#ifndef _windowManager
#define _windowManager
// Macros
#define GL_GLEXT_PROTOTYPES
#include "stdlib.h"
extern char * __ClassNames[];
// Includes
#include <hints.h>
#include <stdio.h>
#include <GL/glx.h>
#include <GL/gl.h>
#include <GL/glext.h>
#include <X11/keysym.h>
#include <X11/Xlib.h>
typedef struct windowManager{
Display * mainDisplay;
Window mainWindow;
int MainScreen;
Window RootWindow;
} windowManager;
void windowManager_setupDisplay( windowManager * this );
void windowManager_setupWindow( windowManager * this );
static int DoubleBufferAttributes[] ;
windowManager windowManager_new( );
windowManager * windowManager_newPointer( );
#endif
typedef struct windowManager windowManager;

View File

@@ -0,0 +1,13 @@
/*
* This file is automaticaly generated, Please dont edit this file!
*/
#include <examples/example.opengl.h>
void main( ) {
opengl * instance = opengl_newPointer();
opengl_initialize( instance );
}

View File

@@ -0,0 +1,22 @@
#ifndef _example_opengl
#define _example_opengl
// Macros
#include "stdlib.h"
extern char * __ClassNames[];
// Includes
#include "../engine/opengl.h"
void main( );
#endif

View File

@@ -0,0 +1,23 @@
/*
* This file is automaticaly generated, Please dont edit this file!
*/
#include <file.h>
file file_new() {
file instance;
return instance;
}
file * file_newPointer() {
struct file * pointer = malloc( sizeof ( struct file ) );
return pointer;
}

View File

@@ -0,0 +1,39 @@
#ifndef _file
#define _file
// Macros
#include "stdlib.h"
extern char * __ClassNames[];
// Includes
#include "text.h"
typedef struct file{
char * filePath;
text * content;
} file;
file file_new( );
file * file_newPointer( );
#endif
typedef struct file file;

View File

@@ -0,0 +1,279 @@
/*
* This file is automaticaly generated, Please dont edit this file!
*/
#include <fileSystem.h>
struct fileSystem * filesystem;
void fileSystem_writeFile( fileSystem * this, char * filepath, char * data ) {
FILE *fp = fopen( filepath, "wb" );
if (fp != NULL)
{
fputs( data, fp );
fclose( fp );
}
}
struct array * fileSystem_readDir( fileSystem * this, char * filePath ) {
DIR * dir;
struct dirent * entry;
struct array * files = array_newPointer();
if ( ( dir = opendir( filePath ) ) == NULL ){
perror("opendir() error");
} else {
while( ( entry = readdir( dir ) ) != NULL ) {
char * filename = (char *)entry->d_name;
if ( strcmp( filename, ".." ) != 0 && strcmp( filename, "." ) != 0 ) {
array_add( files, filename );
}
}
}
return files;
}
struct text * fileSystem_readFile( fileSystem * this, char * name, char * mode ) {
char * readMode;
if( char_operator_compare( mode , "utf8") ) {
readMode = "r";
} else {
readMode = "rb";
}
FILE * file = fopen( name, readMode );
if ( file == NULL ) {
fprintf( stderr, "Error: Can't open file '%s'.", name );
exit( EXIT_FAILURE );
}
fseek( file, 0, SEEK_END );
long length = ftell( file );
fseek( file, 0, SEEK_SET );
char * buffer = malloc( sizeof( char ) * ( length + 1 ) );
fread( buffer, sizeof( char ), length, file );
fclose( file );
if( char_operator_compare( mode , "utf8") ) {
buffer[ length ] = 0;
}
text * output = text_newPointer( "" );
output->length = 0;
text_appendBinary( output, buffer, length );
return output;
}
char * fileSystem_readBinaryFile( fileSystem * this, char * name, char * mode, int * size ) {
char * readMode;
if( char_operator_compare( mode , "utf8") ) {
readMode = "r";
} else {
readMode = "rb";
printf("readmode = rb binary\n\n");
}
FILE * file = fopen( name, readMode );
if ( file == NULL ) {
fprintf( stderr, "Error: Can't open file '%s'.", name );
exit( EXIT_FAILURE );
}
fseek( file, 0, SEEK_END );
long length = ftell( file );
printf("buffer length is '%i' \n\n", length);
fseek( file, 0, SEEK_SET );
char * buffer = malloc( sizeof( char ) * ( length + 1 ) );
buffer[ length ] = '\0';
fread( buffer, sizeof( char ), length, file );
fclose( file );
*size = length;
printf("strlen: %i \n\n", length);
return buffer;
}
int fileSystem_ensureDirectory( fileSystem * this, char * path ) {
char * pathCopy = char_copy( path );
struct array * parts = char_split( pathCopy, "/" );
int count = array_length( parts );
for ( int i = 1; i < count; ++i )
{
struct array * tempParts = char_split( pathCopy, "/" );
for ( int j = 0; j < count-i-1; ++j )
{
array_pop( tempParts );
}
char * tempPath = array_join( tempParts, "/" );
if( fileSystem_exists( this, tempPath ) ) {
} else {
fileSystem_makeDirectory( this, tempPath );
}
}
return 1;
}
int fileSystem_makeDirectory( fileSystem * this, char * path ) {
if ( fileSystem_exists( this, path ) == NULL ) {
mkdir( path, 0700 );
}
return 1;
}
int fileSystem_exists( fileSystem * this, char * path ) {
if ( access( path, F_OK ) == 0 ) {
return 1;
} else {
return 0;
}
}
int fileSystem_isDirectory( fileSystem * this, char * path ) {
struct stat path_stat;
stat( path, & path_stat );
if( S_ISREG( path_stat.st_mode ) ) {
return 0;
} else {
return 1;
}
}
fileSystem fileSystem_new() {
fileSystem instance;
return instance;
}
fileSystem * fileSystem_newPointer() {
struct fileSystem * pointer = malloc( sizeof ( struct fileSystem ) );
return pointer;
}

View File

@@ -0,0 +1,73 @@
#ifndef _fileSystem
#define _fileSystem
// Macros
#include "stdlib.h"
extern char * __ClassNames[];
// Includes
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <dirent.h>
#include <char.h>
#include <console.h>
#include <array.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <http.h>
typedef struct fileSystem{
} fileSystem;
void fileSystem_writeFile( fileSystem * this, char * filepath, char * data );
struct array * fileSystem_readDir( fileSystem * this, char * filePath );
struct text * fileSystem_readFile( fileSystem * this, char * name, char * mode );
char * fileSystem_readBinaryFile( fileSystem * this, char * name, char * mode, int * size );
int fileSystem_ensureDirectory( fileSystem * this, char * path );
int fileSystem_makeDirectory( fileSystem * this, char * path );
int fileSystem_exists( fileSystem * this, char * path );
int fileSystem_isDirectory( fileSystem * this, char * path );
extern struct fileSystem * filesystem;
fileSystem fileSystem_new( );
fileSystem * fileSystem_newPointer( );
#endif
typedef struct fileSystem fileSystem;

View File

@@ -0,0 +1,23 @@
/*
* This file is automaticaly generated, Please dont edit this file!
*/
#include <header.h>
header header_new() {
header instance;
return instance;
}
header * header_newPointer() {
struct header * pointer = malloc( sizeof ( struct header ) );
return pointer;
}

View File

@@ -0,0 +1,37 @@
#ifndef _header
#define _header
// Macros
#include "stdlib.h"
extern char * __ClassNames[];
// Includes
typedef struct header{
char * name;
char * value;
} header;
header header_new( );
header * header_newPointer( );
#endif
typedef struct header header;

View File

@@ -0,0 +1,186 @@
/*
* This file is automaticaly generated, Please dont edit this file!
*/
#include <headers.h>
void headerManager_parse( headerManager * this, char * headerContent ) {
array * headerRows = char_split( headerContent, "\n");
int headerCount = array_length( headerRows );
for (int i = 1; i < headerCount; ++i)
{
char * headerRow = array_get( headerRows, i );
array * headerRowParts = char_split( headerRow, ":");
int headerRowPartsCount = array_length( headerRowParts );
if( headerRowPartsCount == 2 ) {
char * headerName = array_get( headerRowParts, 0 );
char * headerValue = array_get( headerRowParts, 1 );
headerManager_add( this, headerName, char_removeWhitespace( headerValue ) );
}
}
printf("\n\n");
}
void headerManager_display( headerManager * this ) {
struct array * headerRows = this->headers;
int headerCount = array_length( headerRows );
for (int i = 0; i < headerCount; ++i)
{
struct header * headerInstance = array_get( headerRows, i );
printf("%-20s %-30s \n", headerInstance->name, headerInstance->value);
}
}
void headerManager_add( headerManager * this, char * name, char * value ) {
header * headerInstance = header_newPointer();
headerInstance->name = name;
headerInstance->value = value;
array_add( this->headers, headerInstance );
}
void headerManager_set( headerManager * this, char * name, char * value ) {
struct header * headerInstance = headerManager_get( this, name );
if( headerInstance == NULL ) {
headerManager_add( this, name, value );
} else {
int headerIndex = headerManager_getHeaderIndex( this, name );
array * headers = this->headers;
header * headerInstance = array_get( headers, headerIndex );
headerInstance->value = value;
}
}
int headerManager_getHeaderIndex( headerManager * this, char * name ) {
array * headers = this->headers;
int count = array_length( headers );
for (int i = 0; i < count; ++i)
{
header * headerInstance = array_get( headers, i );
if( char_operator_compare( headerInstance->name , name) ) {
return i;
}
}
return -1;
}
char * headerManager_getValue( headerManager * this, char * name ) {
array * headers = this->headers;
int count = array_length( headers );
for (int i = 0; i < count; ++i)
{
header * headerInstance = array_get( headers, i );
if( char_operator_compare( headerInstance->name , name) ) {
return headerInstance->value;
}
}
return NULL;
}
header * headerManager_get( headerManager * this, char * name ) {
array * headers = this->headers;
int count = array_length( headers );
for (int i = 0; i < count; ++i)
{
header * headerInstance = array_get( headers, i );
if( char_operator_compare( headerInstance->name , name) ) {
return headerInstance;
}
}
return NULL;
}
headerManager headerManager_new() {
headerManager instance;
instance.headers = array_newPointer();
return instance;
}
headerManager * headerManager_newPointer() {
struct headerManager * pointer = malloc( sizeof ( struct headerManager ) );
pointer->headers = array_newPointer();
return pointer;
}

View File

@@ -0,0 +1,53 @@
#ifndef _headers
#define _headers
// Macros
#include "stdlib.h"
extern char * __ClassNames[];
// Includes
#include "header.h"
#include "array.h"
typedef struct headerManager{
struct array * headers;
} headerManager;
void headerManager_parse( headerManager * this, char * headerContent );
void headerManager_display( headerManager * this );
void headerManager_add( headerManager * this, char * name, char * value );
void headerManager_set( headerManager * this, char * name, char * value );
int headerManager_getHeaderIndex( headerManager * this, char * name );
char * headerManager_getValue( headerManager * this, char * name );
header * headerManager_get( headerManager * this, char * name );
headerManager headerManager_new( );
headerManager * headerManager_newPointer( );
#endif
typedef struct headerManager headerManager;

View File

@@ -0,0 +1,546 @@
/*
* This file is automaticaly generated, Please dont edit this file!
*/
#include <http.h>
void http_createServer( http * this, void ( * requestCallback )( request * req, text * response ) ) {
this->requestCallback = requestCallback;
if( this->useSSL == 1 ) {
http_initializeOpenSSL( this );
}
printf("after initializeOpenSSL\n\n");
}
void http_initializeOpenSSL( http * this ) {
SSL_load_error_strings();
OpenSSL_add_ssl_algorithms();
SSLeay_add_ssl_algorithms();
return;
}
int http_listen( http * this, int port ) {
this->socket = socket( AF_INET, SOCK_STREAM, 0 );
int iSetOption = 1;
setsockopt( this->socket, SOL_SOCKET, SO_REUSEADDR, ( char * ) & iSetOption, sizeof( iSetOption ) );
if ( this->socket == -1 ) {
perror("webserver (socket)");
exit( 0 );
} else {
printf("socket created successfully\n");
}
this->hostAddress->sin_family = AF_INET;
this->hostAddress->sin_port = htons( port );
this->hostAddress->sin_addr.s_addr = htonl( INADDR_ANY );
if ( bind( this->socket, ( struct sockaddr * ) this->hostAddress, this->hostAddresslength ) != 0 ) {
perror("webserver (bind)");
exit( 0 );
} else {
printf("socket successfully bound to address\n");
}
if ( listen( this->socket, SOMAXCONN ) != 0 ) {
perror("webserver (listen)");
exit( 0 );
} else {
printf("server listening for connections\n");
}
for (;;) {
http_acceptConnection( this );
}
printf("exit");
return 0;
}
char * http_getExtension( http * this, char * path ) {
array * parts = char_split( path, ".");
int count = array_length( parts );
return array_get( parts, count - 1 );
}
void http_logRequest( http * this, request * requestInstance ) {
printf("server address: [%s:%u]\n", requestInstance->address, requestInstance->port );
printf("mimeType: %-30s \n", requestInstance->mimeType);
printf("header: %-30s \n", requestInstance->extension );
printf("method: %-30s \n", requestInstance->method );
printf("version: %-30s \n\n", requestInstance->version );
}
void http_acceptConnection( http * this ) {
fileSystem * filesystem = this->filesystem;
mimeTypes * mimetypes = this->mimetypes;
text * response = text_newPointer("");
char buffer[ 4096 ];
struct sockaddr_in client_addr;
int client_addrlen = sizeof(client_addr);
int socketConnection = accept( this->socket,
(struct sockaddr *)this->hostAddress,
( socklen_t * ) & this->hostAddresslength );
SSL * ssl = NULL;
if( this->useSSL == 1 ) {
const SSL_METHOD * method = SSLv23_server_method();
this->sslContext = SSL_CTX_new( method );
if ( this->sslContext == NULL ) {
printf("Error loading SSL_CTX_NEW '%s'\n\n", stderr);
}
SSL_CTX_set_options( this->sslContext, SSL_OP_SINGLE_DH_USE );
int use_cert = SSL_CTX_use_certificate_file( this->sslContext, "/etc/letsencrypt/live/unifyjs.org/fullchain.pem" , SSL_FILETYPE_PEM );
int use_prv = SSL_CTX_use_PrivateKey_file( this->sslContext, "/etc/letsencrypt/live/unifyjs.org/privkey.pem", SSL_FILETYPE_PEM );
if( use_cert != 1 ) {
printf( "error: SSL_CTX_use_certificate_file\n\n" );
}
if( use_prv != 1 ) {
printf( "error: SSL_CTX_use_PrivateKey_file\n\n" );
}
if ( !SSL_CTX_check_private_key(this->sslContext) ) {
printf("Private key does not match the certificate public key\n");
}
ssl = SSL_new( this->sslContext );
SSL_set_fd( ssl, socketConnection );
int ssl_err = SSL_accept( ssl );
if( ssl_err == 0 ){
printf("SSL_accept returned zero\n");
}
int n;
if( ssl_err < 0 ) {
int err;
if( ( err = SSL_get_error(ssl,n ) ) == SSL_ERROR_WANT_READ) {
printf("SSL_accept wants more data\n");
return ;
}
exit(7);
}
} else {
printf("connection accepted\n\n");
int sockn = getsockname( socketConnection,
( struct sockaddr * ) &client_addr,
( socklen_t * ) &client_addrlen);
if ( sockn == -1 ) {
perror("webserver (getsockname)");
}
}
int valread;
if( this->useSSL == 1 ) {
valread = SSL_read( ssl, buffer, 4096 - 1 );
} else {
printf("read without ssl\n\n");
int valread = read( socketConnection, buffer, 4096 -1 );
if ( valread == -1 ) {
perror("webserver (read)");
}
}
if ( valread == -1 ) {
perror("webserver (read)");
}
request * requestInstance = request_newPointer();
sscanf( buffer, "%s %s %s", requestInstance->method, requestInstance->url, requestInstance->version );
requestInstance->address = inet_ntoa( client_addr.sin_addr );
requestInstance->port = ntohs( client_addr.sin_port );
requestInstance->extension = http_getExtension( this, requestInstance->url );
requestInstance->mimeType = mimeTypes_getByExtension( mimetypes, requestInstance->extension );
this->requestCallback( requestInstance, response );
int writeResponse;
if( this->useSSL == 1 ) {
writeResponse = SSL_write( ssl, response->value, response->length );
} else {
int writeResponse = write( socketConnection, response->value, response->length );
printf("close connection");
if ( writeResponse == -1 ) {
perror("webserver (write)");
return;
}
}
if ( writeResponse == -1 ) {
perror("webserver (write)");
return;
} else {
}
close( socketConnection );
}
void http_dump_buffer( http * this, void *buffer, int buffer_size ) {
int i;
for(i = 0;i < buffer_size;++i){
printf( "%c", ( (char *) buffer )[i]);
}
}
void abort( ) {
}
http http_new() {
http instance;
instance.hostAddress = malloc( sizeof( struct sockaddr_in ) );
instance.hostAddresslength = sizeof( struct sockaddr_in );
instance.filesystem = fileSystem_newPointer();
instance.mimetypes = mimeTypes_newPointer();
instance.headers = headerManager_newPointer();
instance.useSSL = -1;
return instance;
}
http * http_newPointer() {
struct http * pointer = malloc( sizeof ( struct http ) );
pointer->hostAddress = malloc( sizeof( struct sockaddr_in ) );
pointer->hostAddresslength = sizeof( struct sockaddr_in );
pointer->filesystem = fileSystem_newPointer();
pointer->mimetypes = mimeTypes_newPointer();
pointer->headers = headerManager_newPointer();
pointer->useSSL = -1;
return pointer;
}

View File

@@ -0,0 +1,97 @@
#ifndef _http
#define _http
// Macros
#include "stdlib.h"
extern char * __ClassNames[];
// Includes
#include <sys/resource.h>
#include <openssl/ssl.h>
#include <openssl/err.h>
#include <headers.h>
#include <request.h>
#include <unistd.h>
#include <sys/socket.h>
#include <string.h>
#include <stdio.h>
#include <cache.h>
#include <errno.h>
#include <arpa/inet.h>
#include "./mimeTypes.h"
#include "./text.h"
#include "./fileSystem.h"
typedef struct http{
int socket;
struct sockaddr_in * hostAddress;
int hostAddresslength;
struct fileSystem * filesystem;
struct mimeTypes * mimetypes;
struct headerManager * headers;
int useSSL;
SSL_CTX * sslContext;
void ( * requestCallback )( struct request * requestInstance, struct text * response );
} http;
void http_createServer( http * this, void ( * requestCallback )( request * req, text * response ) );
void http_initializeOpenSSL( http * this );
int http_listen( http * this, int port );
char * http_getExtension( http * this, char * path );
void http_logRequest( http * this, request * requestInstance );
void http_acceptConnection( http * this );
void http_dump_buffer( http * this, void *buffer, int buffer_size );
void abort( );
http http_new( );
http * http_newPointer( );
#endif
typedef struct http http;

View File

@@ -0,0 +1,21 @@
/*
* This file is automaticaly generated, Please dont edit this file!
*/
#include <int.h>
char * int_toText( int * this ) {
char * textNumber = malloc( sizeof( char ) * 20 );
sprintf( textNumber, "%d", this );
return textNumber;
}
int int_negative( int * this ) {
return 12;
}

View File

@@ -0,0 +1,24 @@
#ifndef _int
#define _int
// Macros
#include "stdlib.h"
extern char * __ClassNames[];
// Includes
#include <stdio.h>
char * int_toText( int * this );
int int_negative( int * this );
#endif

View File

@@ -0,0 +1,93 @@
/*
* This file is automaticaly generated, Please dont edit this file!
*/
#include <mimeTypes.h>
void mimeTypes_constructor( mimeTypes * this ) {
mimeTypes_add( this, "html", "text/html");
mimeTypes_add( this, "css", "text/css");
mimeTypes_add( this, "ttf", "application/x-font-ttf");
mimeTypes_add( this, "png", "image/png");
mimeTypes_add( this, "svg", "image/svg+xml");
}
void mimeTypes_add( mimeTypes * this, char * extension, char * mimeType ) {
struct array * extensions = this->extensions;
array_add( extensions, extension );
struct array * mimeTypes = this->mimeTypes;
array_add( mimeTypes, mimeType );
}
char * mimeTypes_getByExtension( mimeTypes * this, char * extension ) {
struct array * extensions = this->extensions;
struct array * mimeTypes = this->mimeTypes;
int count = array_length( extensions );
for (int i = 0; i < count; ++i)
{
char * currentExtension = array_get( extensions, i );
if( char_operator_compare( currentExtension , extension) ) {
char * mimeType = array_get( mimeTypes, i );
return mimeType;
}
}
return "no-mimetype";
}
mimeTypes mimeTypes_new() {
mimeTypes instance;
instance.extensions = array_newPointer();
instance.mimeTypes = array_newPointer();
mimeTypes_constructor( &instance);
return instance;
}
mimeTypes * mimeTypes_newPointer() {
struct mimeTypes * pointer = malloc( sizeof ( struct mimeTypes ) );
pointer->extensions = array_newPointer();
pointer->mimeTypes = array_newPointer();
mimeTypes_constructor( pointer );
return pointer;
}

View File

@@ -0,0 +1,45 @@
#ifndef _mimeTypes
#define _mimeTypes
// Macros
#include "stdlib.h"
extern char * __ClassNames[];
// Includes
#include "array.h"
typedef struct mimeTypes{
array * extensions;
array * mimeTypes;
} mimeTypes;
void mimeTypes_constructor( mimeTypes * this );
void mimeTypes_add( mimeTypes * this, char * extension, char * mimeType );
char * mimeTypes_getByExtension( mimeTypes * this, char * extension );
mimeTypes mimeTypes_new( );
mimeTypes * mimeTypes_newPointer( );
#endif
typedef struct mimeTypes mimeTypes;

View File

@@ -0,0 +1,112 @@
/*
* This file is automaticaly generated, Please dont edit this file!
*/
#include <request.h>
void request_constructor( request * this ) {
}
void request_free( request * this ) {
free( this );
}
request request_new() {
request instance;
instance.connection = malloc( BUFFER_SIZE );
instance.address = malloc( BUFFER_SIZE );
instance.url = malloc( BUFFER_SIZE );
instance.method = malloc( BUFFER_SIZE );
instance.version = malloc( BUFFER_SIZE );
instance.mimeType = malloc( BUFFER_SIZE );
instance.extension = malloc( BUFFER_SIZE );
instance.headers = headerManager_newPointer();
request_constructor( &instance);
return instance;
}
request * request_newPointer() {
struct request * pointer = malloc( sizeof ( struct request ) );
pointer->connection = malloc( BUFFER_SIZE );
pointer->address = malloc( BUFFER_SIZE );
pointer->url = malloc( BUFFER_SIZE );
pointer->method = malloc( BUFFER_SIZE );
pointer->version = malloc( BUFFER_SIZE );
pointer->mimeType = malloc( BUFFER_SIZE );
pointer->extension = malloc( BUFFER_SIZE );
pointer->headers = headerManager_newPointer();
request_constructor( pointer );
return pointer;
}

View File

@@ -0,0 +1,62 @@
#ifndef _request
#define _request
// Macros
#define BUFFER_SIZE 1024
#include "stdlib.h"
extern char * __ClassNames[];
// Includes
#include "headers.h"
#include "stdlib.h"
typedef struct request{
char * connection;
char * address;
int port;
char * url;
char * method;
char * version;
char * mimeType;
char * extension;
struct headerManager * headers;
} request;
void request_constructor( request * this );
void request_free( request * this );
request request_new( );
request * request_newPointer( );
#endif
typedef struct request request;

View File

@@ -0,0 +1,205 @@
/*
* This file is automaticaly generated, Please dont edit this file!
*/
#include <text.h>
int text_operator_compare( text * this, text * b ) {
if( strcmp( this->value, b->value ) == 0 ) {
return 1;
} else {
return 0;
}
}
text * text_operator_add( text * this, char * b ) {
text_append( this, b );
return this;
}
void text_constructor( text * this, char * value ) {
this->length = strlen( value );
if( this->length > this->capacity ) {
this->capacity = this->length * 2;
}
this->value = malloc( sizeof( char ) * this->capacity );
strcpy( this->value, value );
}
char text_get( text * this, int index ) {
return this->value[ index ];
}
void text_resize( text * this, int size ) {
this->value = realloc( this->value, size );
this->capacity = size;
}
text * text_append( text * this, char * value ) {
int originalLength = this->length;
int newValueLength = strlen( value );
this->length += newValueLength;
if( this->length > this->capacity ) {
text_resize( this, this->length * 2 );
}
memcpy( this->value + originalLength, value, newValueLength + 1 );
return this;
}
text * text_appendBinary( text * this, char * value, int size ) {
int originalLength = this->length;
int newValueLength = size;
this->length += newValueLength;
if( this->length > this->capacity ) {
text_resize( this, this->length * 2 );
}
memcpy( this->value + originalLength, value, newValueLength + 1 );
return this;
}
text * text_appendObject( text * this, text * object ) {
int originalLength = this->length;
int newValueLength = object->length;
this->length += newValueLength;
if( this->length > this->capacity ) {
text_resize( this, this->length * 2 );
}
memcpy(this->value + originalLength, object->value, newValueLength + 1);
return this;
}
text * text_concatenate( text * this, char * value ) {
text * copy = text_newPointer( this->value );
strcat( copy->value, value );
return copy;
}
char * text_toNative( text * this ) {
return this->value;
}
char * text_whiteSpace( text * this, int whiteSpaceCount ) {
char * output = malloc( 400 );
for (int i = 0; i < whiteSpaceCount; ++i)
{
strcat( output, " " );
}
return output;
}
void text_free( text * this ) {
free( this->value );
free( this );
}
text text_new(char * value) {
text instance;
instance.usevalue = -1;
instance.capacity = 500;
text_constructor( &instance, value);
return instance;
}
text * text_newPointer(char * value) {
struct text * pointer = malloc( sizeof ( struct text ) );
pointer->usevalue = -1;
pointer->capacity = 500;
text_constructor( pointer , value);
return pointer;
}

View File

@@ -0,0 +1,75 @@
#ifndef _text
#define _text
// Macros
#include "stdlib.h"
extern char * __ClassNames[];
// Includes
#include <dirent.h>
#include <array.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
typedef struct text{
char * value;
int usevalue;
int length;
int capacity;
} text;
int text_operator_compare( text * this, text * b );
text * text_operator_add( text * this, char * b );
void text_constructor( text * this, char * value );
char text_get( text * this, int index );
void text_resize( text * this, int size );
text * text_append( text * this, char * value );
text * text_appendBinary( text * this, char * value, int size );
text * text_appendObject( text * this, text * object );
text * text_concatenate( text * this, char * value );
char * text_toNative( text * this );
char * text_whiteSpace( text * this, int whiteSpaceCount );
void text_free( text * this );
text text_new( char * value );
text * text_newPointer( char * value );
#endif
typedef struct text text;

View File

@@ -0,0 +1,88 @@
/*
* This file is automaticaly generated, Please dont edit this file!
*/
#include <vector2.h>
void vector2_constructor( vector2 * this, float x, float y ) {
this->x = x;
this->y = y;
}
vector2 * vector2_operator_plus( vector2 * this, vector2 * b ) {
vector2_add( this, b );
return this;
}
vector2 * vector2_operator_add( vector2 * this, struct vector2 * b ) {
return b;
}
void vector2_add( vector2 * this, vector2 * a ) {
this->x += a->x;
this->y += a->y;
}
void vector2_subtract( vector2 * this, vector2 * a ) {
this->x -= a->x;
this->y -= a->y;
}
int vector2_length( vector2 * this ) {
return this->x + this->y;
}
vector2 vector2_new(float x, float y) {
vector2 instance;
vector2_constructor( &instance, x, y);
return instance;
}
vector2 * vector2_newPointer(float x, float y) {
struct vector2 * pointer = malloc( sizeof ( struct vector2 ) );
vector2_constructor( pointer , x, y);
return pointer;
}

View File

@@ -0,0 +1,49 @@
#ifndef _vector2
#define _vector2
// Macros
#include "stdlib.h"
extern char * __ClassNames[];
// Includes
typedef struct vector2{
float x;
float y;
} vector2;
void vector2_constructor( vector2 * this, float x, float y );
vector2 * vector2_operator_plus( vector2 * this, vector2 * b );
vector2 * vector2_operator_add( vector2 * this, struct vector2 * b );
void vector2_add( vector2 * this, vector2 * a );
void vector2_subtract( vector2 * this, vector2 * a );
int vector2_length( vector2 * this );
vector2 vector2_new( float x, float y );
vector2 * vector2_newPointer( float x, float y );
#endif
typedef struct vector2 vector2;

View File

@@ -0,0 +1,72 @@
/*
* This file is automaticaly generated, Please dont edit this file!
*/
#include <vector3.h>
void vector3_constructor( vector3 * this, float x, float y, float z ) {
this->x = x;
this->y = y;
this->z = z;
}
vector3 * vector3_operator_plus( vector3 * this, vector3 * b ) {
vector3_add( this, b );
return this;
}
vector3 * vector3_operator_add( vector3 * this, vector3 * b ) {
vector3_add( this, b );
return this;
}
void vector3_add( vector3 * this, vector3 * b ) {
this->x += b->x;
this->y += b->y;
this->z += b->z;
}
vector3 vector3_new(float x, float y, float z) {
vector3 instance;
vector3_constructor( &instance, x, y, z);
return instance;
}
vector3 * vector3_newPointer(float x, float y, float z) {
struct vector3 * pointer = malloc( sizeof ( struct vector3 ) );
vector3_constructor( pointer , x, y, z);
return pointer;
}

View File

@@ -0,0 +1,47 @@
#ifndef _vector3
#define _vector3
// Macros
#include "stdlib.h"
extern char * __ClassNames[];
// Includes
typedef struct vector3{
float x;
float y;
float z;
} vector3;
void vector3_constructor( vector3 * this, float x, float y, float z );
vector3 * vector3_operator_plus( vector3 * this, vector3 * b );
vector3 * vector3_operator_add( vector3 * this, vector3 * b );
void vector3_add( vector3 * this, vector3 * b );
vector3 vector3_new( float x, float y, float z );
vector3 * vector3_newPointer( float x, float y, float z );
#endif
typedef struct vector3 vector3;