Initial commit
This commit is contained in:
583
application/demos/example.opengl/engine/block.c
Normal file
583
application/demos/example.opengl/engine/block.c
Normal 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;
|
||||
|
||||
}
|
||||
|
||||
96
application/demos/example.opengl/engine/block.h
Normal file
96
application/demos/example.opengl/engine/block.h
Normal 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;
|
||||
|
||||
|
||||
|
||||
366
application/demos/example.opengl/engine/element.c
Normal file
366
application/demos/example.opengl/engine/element.c
Normal 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;
|
||||
|
||||
}
|
||||
|
||||
107
application/demos/example.opengl/engine/element.h
Normal file
107
application/demos/example.opengl/engine/element.h
Normal 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;
|
||||
|
||||
|
||||
|
||||
87
application/demos/example.opengl/engine/event.c
Normal file
87
application/demos/example.opengl/engine/event.c
Normal 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;
|
||||
|
||||
}
|
||||
|
||||
110
application/demos/example.opengl/engine/event.h
Normal file
110
application/demos/example.opengl/engine/event.h
Normal 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;
|
||||
|
||||
|
||||
|
||||
309
application/demos/example.opengl/engine/eventManager.c
Normal file
309
application/demos/example.opengl/engine/eventManager.c
Normal 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;
|
||||
|
||||
}
|
||||
|
||||
70
application/demos/example.opengl/engine/eventManager.h
Normal file
70
application/demos/example.opengl/engine/eventManager.h
Normal 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;
|
||||
|
||||
|
||||
|
||||
193
application/demos/example.opengl/engine/floatArray.c
Normal file
193
application/demos/example.opengl/engine/floatArray.c
Normal 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;
|
||||
|
||||
}
|
||||
|
||||
71
application/demos/example.opengl/engine/floatArray.h
Normal file
71
application/demos/example.opengl/engine/floatArray.h
Normal 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;
|
||||
|
||||
|
||||
|
||||
194
application/demos/example.opengl/engine/fontRenderer.c
Normal file
194
application/demos/example.opengl/engine/fontRenderer.c
Normal 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;
|
||||
|
||||
}
|
||||
|
||||
60
application/demos/example.opengl/engine/fontRenderer.h
Normal file
60
application/demos/example.opengl/engine/fontRenderer.h
Normal 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;
|
||||
|
||||
|
||||
|
||||
23
application/demos/example.opengl/engine/hints.c
Normal file
23
application/demos/example.opengl/engine/hints.c
Normal 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;
|
||||
|
||||
}
|
||||
|
||||
43
application/demos/example.opengl/engine/hints.h
Normal file
43
application/demos/example.opengl/engine/hints.h
Normal 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;
|
||||
|
||||
|
||||
|
||||
23
application/demos/example.opengl/engine/member.c
Normal file
23
application/demos/example.opengl/engine/member.c
Normal 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;
|
||||
|
||||
}
|
||||
|
||||
56
application/demos/example.opengl/engine/member.h
Normal file
56
application/demos/example.opengl/engine/member.h
Normal 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;
|
||||
|
||||
|
||||
|
||||
724
application/demos/example.opengl/engine/mesh.c
Normal file
724
application/demos/example.opengl/engine/mesh.c
Normal 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;
|
||||
|
||||
}
|
||||
|
||||
98
application/demos/example.opengl/engine/mesh.h
Normal file
98
application/demos/example.opengl/engine/mesh.h
Normal 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;
|
||||
|
||||
|
||||
|
||||
369
application/demos/example.opengl/engine/opengl.c
Normal file
369
application/demos/example.opengl/engine/opengl.c
Normal 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;
|
||||
|
||||
}
|
||||
|
||||
142
application/demos/example.opengl/engine/opengl.h
Normal file
142
application/demos/example.opengl/engine/opengl.h
Normal 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;
|
||||
|
||||
|
||||
|
||||
113
application/demos/example.opengl/engine/pipeline.c
Normal file
113
application/demos/example.opengl/engine/pipeline.c
Normal 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;
|
||||
|
||||
}
|
||||
|
||||
55
application/demos/example.opengl/engine/pipeline.h
Normal file
55
application/demos/example.opengl/engine/pipeline.h
Normal 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;
|
||||
|
||||
|
||||
|
||||
568
application/demos/example.opengl/engine/program.c
Normal file
568
application/demos/example.opengl/engine/program.c
Normal 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;
|
||||
|
||||
}
|
||||
|
||||
100
application/demos/example.opengl/engine/program.h
Normal file
100
application/demos/example.opengl/engine/program.h
Normal 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;
|
||||
|
||||
|
||||
|
||||
23
application/demos/example.opengl/engine/quadMesh.c
Normal file
23
application/demos/example.opengl/engine/quadMesh.c
Normal 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;
|
||||
|
||||
}
|
||||
|
||||
55
application/demos/example.opengl/engine/quadMesh.h
Normal file
55
application/demos/example.opengl/engine/quadMesh.h
Normal 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;
|
||||
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
|
||||
@@ -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( ¤tElement );
|
||||
|
||||
meshInstance.opacity = currentElement.opacity;
|
||||
|
||||
|
||||
|
||||
|
||||
element_setOriginal( ¤tElement );
|
||||
|
||||
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", ¤tEvent->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, ¤tElement, 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( ¤tElement );
|
||||
|
||||
|
||||
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
|
||||
127
application/demos/example.opengl/engine/resourceManager.c
Normal file
127
application/demos/example.opengl/engine/resourceManager.c
Normal 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;
|
||||
|
||||
}
|
||||
|
||||
43
application/demos/example.opengl/engine/resourceManager.h
Normal file
43
application/demos/example.opengl/engine/resourceManager.h
Normal 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;
|
||||
|
||||
|
||||
|
||||
293
application/demos/example.opengl/engine/sampler2D.c
Normal file
293
application/demos/example.opengl/engine/sampler2D.c
Normal 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;
|
||||
|
||||
}
|
||||
|
||||
96
application/demos/example.opengl/engine/sampler2D.h
Normal file
96
application/demos/example.opengl/engine/sampler2D.h
Normal 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;
|
||||
|
||||
|
||||
|
||||
125
application/demos/example.opengl/engine/shader.c
Normal file
125
application/demos/example.opengl/engine/shader.c
Normal 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;
|
||||
|
||||
}
|
||||
|
||||
87
application/demos/example.opengl/engine/shader.h
Normal file
87
application/demos/example.opengl/engine/shader.h
Normal 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;
|
||||
|
||||
|
||||
|
||||
23
application/demos/example.opengl/engine/texture2D.c
Normal file
23
application/demos/example.opengl/engine/texture2D.c
Normal 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;
|
||||
|
||||
}
|
||||
|
||||
54
application/demos/example.opengl/engine/texture2D.h
Normal file
54
application/demos/example.opengl/engine/texture2D.h
Normal 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;
|
||||
|
||||
|
||||
|
||||
23
application/demos/example.opengl/engine/uniform.c
Normal file
23
application/demos/example.opengl/engine/uniform.c
Normal 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;
|
||||
|
||||
}
|
||||
|
||||
54
application/demos/example.opengl/engine/uniform.h
Normal file
54
application/demos/example.opengl/engine/uniform.h
Normal 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;
|
||||
|
||||
|
||||
|
||||
182
application/demos/example.opengl/engine/unsignedIntegerArray.c
Normal file
182
application/demos/example.opengl/engine/unsignedIntegerArray.c
Normal 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;
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
|
||||
997
application/demos/example.opengl/engine/vector.c
Normal file
997
application/demos/example.opengl/engine/vector.c
Normal 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;
|
||||
|
||||
}
|
||||
|
||||
217
application/demos/example.opengl/engine/vector.h
Normal file
217
application/demos/example.opengl/engine/vector.h
Normal 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;
|
||||
|
||||
|
||||
|
||||
75
application/demos/example.opengl/engine/vector4.c
Normal file
75
application/demos/example.opengl/engine/vector4.c
Normal 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;
|
||||
|
||||
}
|
||||
|
||||
49
application/demos/example.opengl/engine/vector4.h
Normal file
49
application/demos/example.opengl/engine/vector4.h
Normal 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;
|
||||
|
||||
|
||||
|
||||
179
application/demos/example.opengl/engine/windowManager.c
Normal file
179
application/demos/example.opengl/engine/windowManager.c
Normal 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;
|
||||
|
||||
}
|
||||
|
||||
64
application/demos/example.opengl/engine/windowManager.h
Normal file
64
application/demos/example.opengl/engine/windowManager.h
Normal 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;
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user