Initial commit
This commit is contained in:
138
application/source/engine/arrayUnsignedInteger.c
Normal file
138
application/source/engine/arrayUnsignedInteger.c
Normal file
@@ -0,0 +1,138 @@
|
||||
|
||||
|
||||
class arrayUnsignedInteger{
|
||||
|
||||
int capacity = 10;
|
||||
|
||||
int total = 0;
|
||||
|
||||
unsigned int * items = malloc( 10000000 );
|
||||
|
||||
int length()
|
||||
{
|
||||
|
||||
return this->total;
|
||||
|
||||
}
|
||||
|
||||
unsigned int get( int index )
|
||||
{
|
||||
|
||||
|
||||
return this->items[index];
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
void set( int index, unsigned int item )
|
||||
{
|
||||
|
||||
if ( index >= 0 && index < this->total ){
|
||||
|
||||
this->items[ index ] = item;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void resize( int capacity )
|
||||
{
|
||||
|
||||
int * items = realloc( this->items, sizeof( unsigned int ) * capacity );
|
||||
|
||||
|
||||
this->items = items;
|
||||
|
||||
this->capacity = capacity;
|
||||
|
||||
}
|
||||
|
||||
|
||||
void add( unsigned int item )
|
||||
{
|
||||
|
||||
if ( this->capacity == this->total ){
|
||||
|
||||
this->resize( this->capacity * 2 );
|
||||
|
||||
}
|
||||
|
||||
this->items[ this->total++ ] = item;
|
||||
|
||||
}
|
||||
|
||||
void delete( 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 ){
|
||||
|
||||
this->resize( this->capacity / 2 );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
unsigned int array_push( unsigned int item ) {
|
||||
|
||||
this->add( item );
|
||||
|
||||
return this->total;
|
||||
|
||||
}
|
||||
|
||||
void unshift( int item ) {
|
||||
|
||||
int length = this->total;
|
||||
|
||||
this->total++;
|
||||
|
||||
if ( this->capacity == this->total ){
|
||||
|
||||
this->resize( this->capacity * 2 );
|
||||
|
||||
}
|
||||
|
||||
for ( int i = length - 1; i >= 0; --i ) {
|
||||
|
||||
this->items[ i + 1 ] = this->items[ i ];
|
||||
|
||||
}
|
||||
|
||||
this->items[ 0 ] = item;
|
||||
|
||||
}
|
||||
|
||||
unsigned int pop() {
|
||||
|
||||
int length = this->total;
|
||||
|
||||
int lastIndex = length - 1;
|
||||
|
||||
int lastItem = this->get( lastIndex );
|
||||
|
||||
this->delete( lastIndex );
|
||||
|
||||
return lastItem;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
560
application/source/engine/block.c
Normal file
560
application/source/engine/block.c
Normal file
@@ -0,0 +1,560 @@
|
||||
|
||||
#define GL_GLEXT_PROTOTYPES
|
||||
|
||||
#include <GL/glext.h>
|
||||
|
||||
#include <GL/gl.h> // GL 1.1 functions
|
||||
|
||||
#include <GL/glx.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "fileSystem.h"
|
||||
|
||||
#include "array.h"
|
||||
|
||||
#include "char.h"
|
||||
|
||||
#include "sampler2D.h"
|
||||
|
||||
#include "member.h"
|
||||
|
||||
class block{
|
||||
|
||||
array * members = new array();
|
||||
|
||||
GLint buffer;
|
||||
|
||||
GLuint index;
|
||||
|
||||
GLenum bufferType;
|
||||
|
||||
GLint bufferSize;
|
||||
|
||||
GLint bindingPoint;
|
||||
|
||||
GLchar * name;
|
||||
|
||||
float * data;
|
||||
|
||||
GLint autoUpload = 0;
|
||||
|
||||
|
||||
|
||||
add( struct member * memberInstance ) {
|
||||
|
||||
this->members->add( memberInstance );
|
||||
|
||||
}
|
||||
|
||||
enableAutoUpload() {
|
||||
|
||||
this->autoUpload = 1;
|
||||
|
||||
}
|
||||
|
||||
|
||||
char * getBufferTypeText( ) {
|
||||
|
||||
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";
|
||||
|
||||
}
|
||||
|
||||
createBuffer() {
|
||||
|
||||
unsigned int blockBufferSize = this->bufferSize; // allocate 152 bytes of memory
|
||||
|
||||
//printf(" create array for block %s os size %i \n", this->name, 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 upload() {
|
||||
|
||||
//printf("upload uniform buffer: %f %f %f %f\n", this->data[0], this->data[1], this->data[2], this->data[3]);
|
||||
|
||||
//printf("upload uniform buffer: %i\n", this->index);
|
||||
|
||||
//glBindBuffer( this->bufferType, this->buffer );
|
||||
|
||||
//glBindBufferBase( this->bufferType, this->bindingPoint, this->buffer );
|
||||
|
||||
//glBufferData( this->bufferType, this->bufferSize, this->data, GL_DYNAMIC_DRAW );
|
||||
|
||||
|
||||
glBindBuffer( this->bufferType, this->buffer );
|
||||
|
||||
glBindBufferBase( this->bufferType, this->bindingPoint, this->buffer );
|
||||
|
||||
glBufferSubData( this->bufferType, 0, this->bufferSize, this->data );
|
||||
|
||||
}
|
||||
|
||||
mapBufferError( 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 * getMemberArray( char * name ) {
|
||||
|
||||
glMemoryBarrier( GL_SHADER_STORAGE_BARRIER_BIT );
|
||||
|
||||
vector<vector2> * output = new vector();
|
||||
|
||||
|
||||
int uniformCount = this->members->length();
|
||||
|
||||
for (int i = 0; i < uniformCount; ++i)
|
||||
{
|
||||
member * currentMember = this->members->get( i );
|
||||
|
||||
char * memberName = ( char * ) currentMember->name;
|
||||
|
||||
if( 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;
|
||||
|
||||
this->mapBufferError( output->items );
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
glUnmapBuffer( GL_SHADER_STORAGE_BUFFER );
|
||||
|
||||
|
||||
return output;
|
||||
|
||||
}
|
||||
|
||||
void setMemberArrayRow( char * name, int arrayIndex, float * data ) {
|
||||
|
||||
int memberCount = this->members->length();
|
||||
|
||||
for (int i = 0; i < memberCount; ++i)
|
||||
{
|
||||
member * currentMember = this->members->get( i );
|
||||
|
||||
char * memberName = ( char * ) currentMember->name;
|
||||
|
||||
if( memberName == name ) {
|
||||
|
||||
int size = currentMember->size * 8;
|
||||
|
||||
int arrayStride = currentMember->arrayStride;
|
||||
|
||||
int offset = arrayStride * arrayIndex;
|
||||
|
||||
//printf("set array stride: %i %i\n", arrayIndex, arrayStride);
|
||||
|
||||
//int offset = currentMember->offset / 4;
|
||||
|
||||
|
||||
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 setMemberArray( char * name, float * data ) {
|
||||
|
||||
int memberCount = this->members->length();
|
||||
|
||||
for (int i = 0; i < memberCount; ++i)
|
||||
{
|
||||
member * currentMember = this->members->get( i );
|
||||
|
||||
char * memberName = ( char * ) currentMember->name;
|
||||
|
||||
if( memberName == name ) {
|
||||
|
||||
int size = currentMember->size * 8;
|
||||
|
||||
int offset = currentMember->offset / 4;
|
||||
|
||||
memcpy( this->data + offset, data, size );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void setMemberItem( char * name, int index, void * value ) {
|
||||
|
||||
|
||||
int uniformCount = this->members->length();
|
||||
|
||||
//printf("uniformCount: %i\n\n", uniformCount);
|
||||
|
||||
for (int i = 0; i < uniformCount; ++i)
|
||||
{
|
||||
member * currentMember = this->members->get( i );
|
||||
|
||||
char * memberName = ( char * ) currentMember->name;
|
||||
|
||||
if( memberName == name ) {
|
||||
|
||||
//printf("\n\n Update this uniform from uniform block %s\n\n", name);
|
||||
int stride;
|
||||
|
||||
int strideNormalized;
|
||||
|
||||
int size;
|
||||
|
||||
int offset;
|
||||
|
||||
|
||||
switch( currentMember->type ) {
|
||||
|
||||
case GL_FLOAT_VEC2:
|
||||
|
||||
stride = currentMember->arrayStride;
|
||||
|
||||
strideNormalized = stride / sizeof( float ) ;
|
||||
|
||||
//printf("get size of item: %i\n",strideNormalized );
|
||||
|
||||
|
||||
|
||||
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 );
|
||||
|
||||
// need to fix this
|
||||
if( currentMember->topLevelSize == 1 ) {
|
||||
|
||||
//arrayIndex = 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
//printf(" %i: %f \n", dataOffset + 1 + arrayIndex , vector2Value->y );
|
||||
|
||||
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 };
|
||||
|
||||
// printf("%f %f\n", data[0], data[1]);
|
||||
|
||||
|
||||
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 setData( float * data ) {
|
||||
|
||||
this->data = data;
|
||||
|
||||
}
|
||||
|
||||
void setMember( char * name, void * value ) {
|
||||
|
||||
int uniformCount = this->members->length();
|
||||
|
||||
//printf("uniformCount: %i\n\n", uniformCount);
|
||||
|
||||
for (int i = 0; i < uniformCount; ++i)
|
||||
{
|
||||
member * currentMember = this->members->get( i );
|
||||
|
||||
char * memberName = ( char * ) currentMember->name;
|
||||
|
||||
if( memberName == name ) {
|
||||
|
||||
//printf("\n\n Update this uniform from uniform block %s\n\n", 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 };
|
||||
|
||||
// printf("%f %f\n", data[0], data[1]);
|
||||
|
||||
|
||||
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;
|
||||
|
||||
//this->data[ dataOffset + 1 ] = vector2Value->y;
|
||||
|
||||
}
|
||||
|
||||
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 };
|
||||
|
||||
// printf("%f %f\n", data[0], data[1]);
|
||||
|
||||
|
||||
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;
|
||||
|
||||
//this->data[ dataOffset + 1 ] = vector2Value->y;
|
||||
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
302
application/source/engine/element.c
Normal file
302
application/source/engine/element.c
Normal file
@@ -0,0 +1,302 @@
|
||||
|
||||
#include "vector2.h"
|
||||
|
||||
#include "vector3.h"
|
||||
|
||||
#include "vector4.h"
|
||||
|
||||
#include "vector.h"
|
||||
|
||||
#include "char.h"
|
||||
|
||||
#include "classConfiguration.h"
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <math.h>
|
||||
|
||||
|
||||
class element{
|
||||
|
||||
int index;
|
||||
|
||||
vector3 position = new vector3( 0, 0, 0 );
|
||||
|
||||
vector2 size = new vector2( 0, 0 );
|
||||
|
||||
vector3 backgroundColor = new vector3( 0, 0, 0 );
|
||||
|
||||
|
||||
|
||||
vector3 originalPosition = new vector3( 0, 0, 0 );
|
||||
|
||||
vector2 originalSize = new vector2( 0, 0 );
|
||||
|
||||
vector3 originalBackgroundColor = new vector3( 0, 0, 0 );
|
||||
|
||||
|
||||
|
||||
float opacity = 1;
|
||||
|
||||
char * backgroundImagePath = "";
|
||||
|
||||
bool useBackgroundImage = false;
|
||||
|
||||
int features = 0;
|
||||
|
||||
vector<char *> * featureNames = new vector();
|
||||
|
||||
|
||||
constructor() {
|
||||
|
||||
this->featureNames->add( "useBackgroundImage" );
|
||||
|
||||
this->featureNames->add( "useBorder" );
|
||||
|
||||
}
|
||||
|
||||
|
||||
vector4 colorConverter( 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 = new vector4( r, g, b, (float)a );
|
||||
|
||||
return rgbColor;
|
||||
}
|
||||
|
||||
|
||||
int textureIndex;
|
||||
|
||||
void * background;
|
||||
|
||||
setOriginal() {
|
||||
|
||||
this->originalSize = this->size;
|
||||
|
||||
this->originalPosition = this->position;
|
||||
|
||||
this->originalBackgroundColor = this->backgroundColor;
|
||||
|
||||
}
|
||||
|
||||
set size( vector2 a ) {
|
||||
|
||||
this->size.x = a.x;
|
||||
|
||||
this->size.y = a.y;
|
||||
|
||||
printf("set size: %f %f\n", this->size.x, this->size.y);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
set position( 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 featureIsEnabled( int featureValue ) {
|
||||
|
||||
return ( this->features & featureValue ) > 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
int getFeatureValueByFeatureName( char * featureName ) {
|
||||
|
||||
int count = this->featureNames->length();
|
||||
|
||||
for (int i = 0; i < count; ++i)
|
||||
{
|
||||
char * currentFeatureName = this->featureNames->get( i );
|
||||
|
||||
if( featureName == currentFeatureName ) {
|
||||
|
||||
return powf( 2, i );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
int updateFeature() {
|
||||
|
||||
int currentFeatureValue;
|
||||
|
||||
currentFeatureValue = this->getFeatureValueByFeatureName( "useBackgroundImage" );
|
||||
|
||||
if( this->featureIsEnabled( currentFeatureValue ) ) {
|
||||
|
||||
if( !this->useBackgroundImage ) {
|
||||
|
||||
this->features -= currentFeatureValue;
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
if( this->useBackgroundImage ) {
|
||||
|
||||
this->features += currentFeatureValue;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
return this->features;
|
||||
|
||||
//featureIsEnabled( int featureValue )
|
||||
|
||||
|
||||
}
|
||||
|
||||
set background( ... ) {
|
||||
|
||||
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 = this->colorConverter( message );
|
||||
|
||||
this->backgroundColor = new vector3( 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( className == "vector3" ) {
|
||||
|
||||
vector3 message = va_arg( args, vector3 );
|
||||
|
||||
this->backgroundColor = message;
|
||||
|
||||
this->useBackgroundImage = false;
|
||||
|
||||
}
|
||||
|
||||
if( className == "vector4" ) {
|
||||
|
||||
vector4 message = va_arg( args, vector4 );
|
||||
|
||||
this->backgroundColor = new vector3( message.x, message.y, message.z );
|
||||
|
||||
this->opacity = message.w;
|
||||
|
||||
this->useBackgroundImage = false;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
//printf(" %f %f %f %f \n\n\n ", this->backgroundColor.x, this->backgroundColor.y, this->backgroundColor.z, this->opacity);
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
click() {
|
||||
|
||||
|
||||
this->backgroundColor = new vector3( 0, 256, 256 );
|
||||
|
||||
}
|
||||
|
||||
mousedown() {
|
||||
|
||||
//printf("executed click event\n\n");
|
||||
|
||||
this->backgroundColor = new vector3( 0, 256, 256 );
|
||||
|
||||
this->position = new vector3( 256, 256, 100 );
|
||||
|
||||
}
|
||||
|
||||
mouseup() {
|
||||
|
||||
//printf("executed click event\n\n");
|
||||
|
||||
this->backgroundColor = this->originalBackgroundColor;
|
||||
|
||||
this->position = this->originalPosition;
|
||||
|
||||
}
|
||||
|
||||
mouseover() {
|
||||
|
||||
this->backgroundColor = new vector3( 256, 256, 256 );
|
||||
|
||||
}
|
||||
|
||||
mouseleave() {
|
||||
|
||||
printf("mouse leave\n");
|
||||
|
||||
this->backgroundColor = this->originalBackgroundColor;
|
||||
|
||||
}
|
||||
}
|
||||
100
application/source/engine/event.c
Normal file
100
application/source/engine/event.c
Normal file
@@ -0,0 +1,100 @@
|
||||
|
||||
#include "vector.h"
|
||||
|
||||
#include "../vector2.h"
|
||||
|
||||
#include "stdbool.h"
|
||||
|
||||
|
||||
/*
|
||||
|
||||
DOM Level 3 defines nine mouse events.
|
||||
|
||||
event
|
||||
|
||||
keyboard
|
||||
|
||||
key : ArrowUp
|
||||
|
||||
keyCode : 123
|
||||
|
||||
shiftKey : false
|
||||
|
||||
ctrlKey : true
|
||||
|
||||
altKey : false
|
||||
|
||||
metaKey : false
|
||||
|
||||
|
||||
screen
|
||||
|
||||
position
|
||||
|
||||
vector2
|
||||
|
||||
size
|
||||
|
||||
vector2
|
||||
|
||||
|
||||
mouse
|
||||
|
||||
position
|
||||
|
||||
vector2
|
||||
|
||||
button:
|
||||
0 Left
|
||||
|
||||
1 middle
|
||||
|
||||
2 right
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
|
||||
|
||||
class mouse{
|
||||
|
||||
vector2 position;
|
||||
|
||||
int button;
|
||||
|
||||
vector<char *> * eventTypes = new vector();
|
||||
|
||||
}
|
||||
|
||||
class screen{
|
||||
|
||||
vector2 size;
|
||||
|
||||
vector2 position;
|
||||
|
||||
}
|
||||
|
||||
class keyboard{
|
||||
|
||||
int keyCode;
|
||||
|
||||
bool shiftKey;
|
||||
|
||||
bool ctrlKey;
|
||||
|
||||
bool altKey;
|
||||
|
||||
bool metaKey;
|
||||
|
||||
}
|
||||
|
||||
class event{
|
||||
|
||||
struct mouse * mouse = new mouse();
|
||||
|
||||
struct screen * screen = new screen();
|
||||
|
||||
struct keyboard * keyboard = new keyboard();
|
||||
|
||||
}
|
||||
290
application/source/engine/eventManager.c
Normal file
290
application/source/engine/eventManager.c
Normal file
@@ -0,0 +1,290 @@
|
||||
|
||||
#include <X11/Xlib.h>
|
||||
|
||||
#include <X11/keysym.h>
|
||||
|
||||
#define GL_GLEXT_PROTOTYPES
|
||||
|
||||
#include <GL/glext.h>
|
||||
|
||||
#include <GL/gl.h> // GL 1.1 functions
|
||||
|
||||
#include <GL/glx.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <event.h>
|
||||
|
||||
#include <time.h>
|
||||
|
||||
#include <vector.h>
|
||||
|
||||
|
||||
#include <vector2.h>
|
||||
|
||||
|
||||
|
||||
class eventManger{
|
||||
|
||||
Display * mainDisplay;
|
||||
|
||||
Window mainWindow;
|
||||
|
||||
Window RootWindow;
|
||||
|
||||
event * lastEvent;
|
||||
|
||||
clock_t lastMouseDownTime;
|
||||
|
||||
constructor() {
|
||||
|
||||
this->lastEvent = new event();
|
||||
|
||||
this->lastEvent->mouse->button = -1;
|
||||
|
||||
|
||||
}
|
||||
|
||||
event * fetchEvent() {
|
||||
|
||||
event * currentEvent = new event();
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
//printf("1");
|
||||
}
|
||||
else
|
||||
{
|
||||
//printf("0");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//printf("(%d)\n", qMask);
|
||||
|
||||
if( qMask == Button1MotionMask ) {
|
||||
|
||||
//printf("LeftMouse\n");
|
||||
|
||||
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 ) {
|
||||
|
||||
//printf("EnterWindowMask\n");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
XEvent event;
|
||||
|
||||
int keyboardEventCount = XPending( this->mainDisplay );
|
||||
|
||||
//printf("eventCount: %i\n\n", keyboardEventCount);
|
||||
|
||||
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:
|
||||
|
||||
//printf("event not defined: %i\n\n", event.type);
|
||||
|
||||
//break;
|
||||
|
||||
}
|
||||
|
||||
//printf("event: %i\n\n", event.type);
|
||||
|
||||
}
|
||||
|
||||
//printf(" Mouse is at (%d,%d)\n", windowX, windowY );
|
||||
|
||||
//printf(" Mouse X: %d mouse Y: %d \n", mouseX, mouseY );
|
||||
|
||||
//XGrabKeyboard( this->mainDisplay, this->RootWindow, 0, GrabModeAsync, GrabModeAsync, CurrentTime);
|
||||
|
||||
|
||||
//printf("qchild is at (%d,%d)\n", mouseX, mouseY);
|
||||
|
||||
}
|
||||
|
||||
bool hasBorder = true;
|
||||
|
||||
int borderCorrection = 0;
|
||||
|
||||
|
||||
|
||||
if( hasBorder ) {
|
||||
|
||||
borderCorrection = 12;
|
||||
|
||||
}
|
||||
|
||||
|
||||
currentEvent->mouse->position = new vector2( mouseX, mouseY + borderCorrection );
|
||||
|
||||
currentEvent->screen->size = new vector2( window.width, window.height + borderCorrection );
|
||||
|
||||
//currentEvent->mouse->eventTypes = new vector();
|
||||
|
||||
vector<char *> * mouseEvents = currentEvent->mouse->eventTypes;
|
||||
|
||||
mouseEvents = new vector();
|
||||
|
||||
if( this->lastEvent->mouse->position.x != currentEvent->mouse->position.x ||
|
||||
this->lastEvent->mouse->position.y != currentEvent->mouse->position.y ) {
|
||||
|
||||
mouseEvents->add( "mousemove" );
|
||||
|
||||
}
|
||||
|
||||
if( this->lastEvent->mouse->button != 0 && currentEvent->mouse->button == 0 ) {
|
||||
|
||||
this->lastMouseDownTime = clock();
|
||||
|
||||
printf("Mouse down\n\n");
|
||||
|
||||
mouseEvents->add( "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");
|
||||
|
||||
|
||||
mouseEvents->add( "click" );
|
||||
|
||||
}
|
||||
|
||||
printf("mouseup event\n\n");
|
||||
|
||||
mouseEvents->add( "mouseup" );
|
||||
//printf("%i\n\n", milliseconds);
|
||||
|
||||
|
||||
}
|
||||
|
||||
currentEvent->mouse->eventTypes = mouseEvents;
|
||||
|
||||
|
||||
this->lastEvent = currentEvent;
|
||||
|
||||
return currentEvent;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
167
application/source/engine/floatArray.c
Normal file
167
application/source/engine/floatArray.c
Normal file
@@ -0,0 +1,167 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <char.h>
|
||||
|
||||
#include <text.h>
|
||||
|
||||
#include <vector3.h>
|
||||
|
||||
#include <vector2.h>
|
||||
|
||||
class floatArray{
|
||||
|
||||
int capacity = 10;
|
||||
|
||||
int total = 0;
|
||||
|
||||
float * items = malloc( 10000000 );
|
||||
|
||||
int length()
|
||||
{
|
||||
|
||||
return this->total;
|
||||
|
||||
}
|
||||
|
||||
float get( int index )
|
||||
{
|
||||
|
||||
if ( index >= 0 && index < this->total ){
|
||||
|
||||
return this->items[index];
|
||||
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
||||
}
|
||||
|
||||
void set( int index, float item )
|
||||
{
|
||||
|
||||
if ( index >= 0 && index < this->total ){
|
||||
|
||||
this->items[ index ] = item;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void resize( int capacity )
|
||||
{
|
||||
|
||||
float * items = realloc( this->items, sizeof( float ) * capacity );
|
||||
|
||||
|
||||
this->items = items;
|
||||
|
||||
this->capacity = capacity;
|
||||
|
||||
}
|
||||
|
||||
void addVector2( struct vector2 * item ) {
|
||||
|
||||
this->add( item->x );
|
||||
|
||||
this->add( item->y );
|
||||
|
||||
}
|
||||
|
||||
void addVector3( struct vector3 * item ) {
|
||||
|
||||
this->add( item->x );
|
||||
|
||||
this->add( item->y );
|
||||
|
||||
this->add( item->z );
|
||||
|
||||
}
|
||||
|
||||
void add( float item )
|
||||
{
|
||||
|
||||
if ( this->capacity == this->total ){
|
||||
|
||||
this->resize( this->capacity * 2 );
|
||||
|
||||
}
|
||||
|
||||
this->items[ this->total++ ] = item;
|
||||
|
||||
}
|
||||
|
||||
void delete( 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 ){
|
||||
|
||||
this->resize( this->capacity / 2 );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int array_push( float item ) {
|
||||
|
||||
this->add( item );
|
||||
|
||||
return this->total;
|
||||
|
||||
}
|
||||
|
||||
void unshift( float item ) {
|
||||
|
||||
int length = this->total;
|
||||
|
||||
this->total++;
|
||||
|
||||
if ( this->capacity == this->total ){
|
||||
|
||||
this->resize( this->capacity * 2 );
|
||||
|
||||
}
|
||||
|
||||
for ( int i = length - 1; i >= 0; --i ) {
|
||||
|
||||
this->items[ i + 1 ] = this->items[ i ];
|
||||
|
||||
}
|
||||
|
||||
this->items[ 0 ] = item;
|
||||
|
||||
}
|
||||
|
||||
float pop() {
|
||||
|
||||
int length = this->total;
|
||||
|
||||
int lastIndex = length - 1;
|
||||
|
||||
float lastItem = this->get( lastIndex );
|
||||
|
||||
this->delete( lastIndex );
|
||||
|
||||
return lastItem;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
176
application/source/engine/fontRenderer.c
Normal file
176
application/source/engine/fontRenderer.c
Normal file
@@ -0,0 +1,176 @@
|
||||
|
||||
#include <ft2build.h>
|
||||
|
||||
#include <freetype/freetype.h>
|
||||
|
||||
#include <text.h>
|
||||
|
||||
#include <texture2D.h>
|
||||
|
||||
#include <vector2.h>
|
||||
|
||||
#define GL_GLEXT_PROTOTYPES
|
||||
|
||||
#include <GL/glext.h>
|
||||
|
||||
#include <GL/gl.h> // GL 1.1 functions
|
||||
|
||||
#include <GL/glx.h>
|
||||
|
||||
|
||||
class fontRenderer{
|
||||
|
||||
GLubyte * data = malloc( 512 * 512 * 4 );
|
||||
|
||||
texture2D * loadFont( char character ) {
|
||||
|
||||
FT_Library ft;
|
||||
|
||||
if ( FT_Init_FreeType( &ft ) )
|
||||
{
|
||||
|
||||
printf("ERROR::FREETYPE: Could not init FreeType Library");
|
||||
|
||||
//return -1;
|
||||
|
||||
} else {
|
||||
|
||||
// printf("FreeType Library loaded\n\n");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
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");
|
||||
|
||||
//return -1;
|
||||
|
||||
} else {
|
||||
|
||||
// printf("FREETYPE: font loaded\n\n");
|
||||
|
||||
}
|
||||
|
||||
int fontSize = 118;
|
||||
|
||||
if ( FT_Set_Pixel_Sizes( face, 0, fontSize ) ) {
|
||||
|
||||
printf("ERROR::FREETYPE: Failed to set font size\n\n");
|
||||
|
||||
} else {
|
||||
|
||||
//printf("FREETYPE: font size set\n\n");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
FT_Matrix matrix;
|
||||
|
||||
FT_UInt glyph_index;
|
||||
|
||||
FT_Vector pen;
|
||||
|
||||
int n;
|
||||
|
||||
FT_GlyphSlot slot = face->glyph; /* a small shortcut */
|
||||
|
||||
|
||||
pen.x = 0;
|
||||
|
||||
pen.y = 0;
|
||||
|
||||
if( FT_Load_Char( face, character, FT_LOAD_RENDER ) ) {
|
||||
|
||||
printf("ERROR error loading char.");
|
||||
|
||||
} else {
|
||||
|
||||
//printf("FREETYPE: Char loaded %c \n", character );
|
||||
|
||||
}
|
||||
|
||||
|
||||
//printf( "%c: bitmap_left: %i, bitmap_top: %i\n", ( char ) character, slot->bitmap_left, slot->bitmap_top );
|
||||
|
||||
|
||||
FT_Bitmap * bitmap = &slot->bitmap;
|
||||
|
||||
texture2D * texture = new texture2D();
|
||||
|
||||
texture->width = bitmap->width;
|
||||
|
||||
texture->height = bitmap->rows;
|
||||
|
||||
texture->hasAlpha = 1;
|
||||
|
||||
texture->offset = new vector2( ( float ) slot->bitmap_left, ( float ) slot->bitmap_top );
|
||||
|
||||
|
||||
//printf("x_max: %i\n", texture->width);
|
||||
|
||||
//printf("y_max: %i\n", texture->height);
|
||||
|
||||
|
||||
|
||||
|
||||
texture->data = bitmap->buffer;//bitmap->buffer;
|
||||
|
||||
for (int x = 0; x < texture->width; ++x)
|
||||
{
|
||||
//printf("%u ", (unsigned int)bitmap->buffer[0]);
|
||||
}
|
||||
|
||||
//FT_Done_Face(face);
|
||||
|
||||
//FT_Done_FreeType(ft);
|
||||
|
||||
|
||||
|
||||
return texture;
|
||||
|
||||
//this->show_image();
|
||||
|
||||
|
||||
}
|
||||
|
||||
void draw_bitmap( 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++ )
|
||||
{
|
||||
//if ( i < 0 || j < 0 || i >= WIDTH || j >= HEIGHT )
|
||||
//continue;
|
||||
|
||||
//this->data[j + (i * 512)] |= bitmap->buffer[q * bitmap->width + p];
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void show_image( void )
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
11
application/source/engine/hints.c
Normal file
11
application/source/engine/hints.c
Normal file
@@ -0,0 +1,11 @@
|
||||
|
||||
|
||||
|
||||
class Hints
|
||||
{
|
||||
unsigned long flags;
|
||||
unsigned long functions;
|
||||
unsigned long decorations;
|
||||
long inputMode;
|
||||
unsigned long status;
|
||||
}
|
||||
28
application/source/engine/member.c
Normal file
28
application/source/engine/member.c
Normal file
@@ -0,0 +1,28 @@
|
||||
|
||||
#define GL_GLEXT_PROTOTYPES
|
||||
|
||||
#include <GL/glext.h>
|
||||
|
||||
#include <GL/gl.h> // GL 1.1 functions
|
||||
|
||||
#include <GL/glx.h>
|
||||
|
||||
|
||||
|
||||
class member{
|
||||
|
||||
char * name;
|
||||
|
||||
GLint index;
|
||||
|
||||
GLint offset;
|
||||
|
||||
GLint size;
|
||||
|
||||
GLenum type;
|
||||
|
||||
GLuint arrayStride;
|
||||
|
||||
GLuint topLevelSize;
|
||||
|
||||
}
|
||||
703
application/source/engine/mesh.c
Normal file
703
application/source/engine/mesh.c
Normal file
@@ -0,0 +1,703 @@
|
||||
|
||||
|
||||
#define GL_GLEXT_PROTOTYPES
|
||||
|
||||
#include <GL/glext.h>
|
||||
|
||||
#include <GL/gl.h> // GL 1.1 functions
|
||||
|
||||
#include <GL/glx.h>
|
||||
|
||||
#include "block.h"
|
||||
|
||||
#include "shader.h"
|
||||
|
||||
#include "program.h"
|
||||
|
||||
#include "floatArray.h"
|
||||
|
||||
#include "unsignedIntegerArray.h"
|
||||
|
||||
|
||||
|
||||
class mesh{
|
||||
|
||||
struct program * program;
|
||||
|
||||
struct unsignedIntegerArray * indices;
|
||||
|
||||
|
||||
struct floatArray * textureCoordinates;
|
||||
|
||||
struct floatArray * vertexCoordinates;
|
||||
|
||||
struct floatArray * normalCoordinates;
|
||||
|
||||
|
||||
struct array * blocks = new array();
|
||||
|
||||
|
||||
GLuint vertexArrayObject;
|
||||
|
||||
|
||||
GLuint uniformBuffer;
|
||||
|
||||
GLuint indexBuffer;
|
||||
|
||||
GLuint vertexbuffer;
|
||||
|
||||
GLuint textureCoordinateBuffer;
|
||||
|
||||
GLuint meshIndexBuffer;
|
||||
|
||||
GLuint uvBuffer;
|
||||
|
||||
struct unsignedIntegerArray * uniformBuffers = new unsignedIntegerArray();
|
||||
|
||||
|
||||
|
||||
struct block * getUniformBlock( char * blockName ) {
|
||||
|
||||
int blockCount = this->blocks->length();
|
||||
|
||||
for ( int i = 0; i < blockCount; ++i )
|
||||
{
|
||||
struct block * currentBlock = this->blocks->get( i );
|
||||
|
||||
char * currentBlockName = currentBlock->name;
|
||||
|
||||
if( currentBlockName == blockName ) {
|
||||
|
||||
return currentBlock;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void bindBlock( struct block * blockInstance ) {
|
||||
|
||||
//printf("%s\n", blockInstance);
|
||||
|
||||
blockInstance->createBuffer();
|
||||
|
||||
this->blocks->add( blockInstance );
|
||||
|
||||
}
|
||||
|
||||
void setProgram( struct program * currentProgram ) {
|
||||
|
||||
this->program = currentProgram;
|
||||
|
||||
}
|
||||
|
||||
GLuint getGLTypeSize( 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 getComponentType( 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 getItemSize( 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 createBuffer( char * attributeName, void * data, GLenum target, GLenum usage ) {
|
||||
|
||||
GLuint itemSize;
|
||||
|
||||
GLuint componentType;
|
||||
|
||||
GLuint componentSize;
|
||||
|
||||
GLuint attributeLocation;
|
||||
|
||||
//GLenum target;
|
||||
|
||||
GLuint isIndexBuffer = 0;
|
||||
|
||||
GLuint buffer;
|
||||
|
||||
glGenBuffers( 1, &buffer );
|
||||
|
||||
|
||||
if( attributeName == "index" ) {
|
||||
|
||||
isIndexBuffer = 1;
|
||||
|
||||
componentType = GL_INT;
|
||||
|
||||
componentSize = this->getGLTypeSize( componentType );
|
||||
|
||||
target = GL_ELEMENT_ARRAY_BUFFER;
|
||||
|
||||
glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, buffer );
|
||||
|
||||
} else {
|
||||
|
||||
attribute * attribute = this->program->getAttributeByName( attributeName );
|
||||
|
||||
if( attribute == NULL ) {
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
itemSize = this->getItemSize( attribute->type );
|
||||
|
||||
componentType = this->getComponentType( attribute->type );
|
||||
|
||||
componentSize = this->getGLTypeSize( componentType );
|
||||
|
||||
attributeLocation = attribute->location;
|
||||
|
||||
target = GL_ARRAY_BUFFER;
|
||||
|
||||
glEnableVertexAttribArray( attribute->location );
|
||||
|
||||
glBindBuffer( GL_ARRAY_BUFFER, buffer );
|
||||
|
||||
}
|
||||
|
||||
//printf("Name: %s itemSize: %i componentSize: %i ", attributeName, itemSize, componentSize);
|
||||
|
||||
|
||||
int itemCount;
|
||||
|
||||
GLuint bufferSize;
|
||||
|
||||
|
||||
if( componentType == GL_UNSIGNED_INT || componentType == GL_INT ) {
|
||||
|
||||
unsignedIntegerArray * test = ( unsignedIntegerArray * ) data;
|
||||
|
||||
itemCount = test->length();
|
||||
|
||||
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 );
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//printf("itemCount: %i\n\n", bufferSize);
|
||||
|
||||
GLint compareSize = 0;
|
||||
|
||||
glGetBufferParameteriv( target, GL_BUFFER_SIZE, &compareSize );
|
||||
|
||||
if( bufferSize != compareSize )
|
||||
{
|
||||
|
||||
glDeleteBuffers(1, &buffer);
|
||||
|
||||
printf("ERROR: size error");
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
return buffer;
|
||||
|
||||
}
|
||||
|
||||
|
||||
void createBuffers( ) {
|
||||
|
||||
struct unsignedIntegerArray * indices = new unsignedIntegerArray();
|
||||
|
||||
struct floatArray * textureCoordinates = new floatArray();
|
||||
|
||||
struct floatArray * vertexCoordinates = new floatArray();
|
||||
|
||||
struct floatArray * normalCoordinates = new floatArray();
|
||||
|
||||
struct unsignedIntegerArray * meshIndices = new unsignedIntegerArray();
|
||||
|
||||
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 = meshIndices->length();
|
||||
|
||||
//printf("Number of vectex cnumVertsAcrossoordinates: %i\n\n", vertexCoordinates->length());
|
||||
|
||||
int numVertsAcross = subdivisionsWidth + 1;
|
||||
|
||||
for ( int z = 0; z < subdivisionsDepth; z++ ) {
|
||||
|
||||
for ( int x = 0; x < subdivisionsWidth; x++ ) {
|
||||
|
||||
// triangle 1 of quad
|
||||
indices->add( ( z + 0 ) * numVertsAcross + x + meshStartIndex );
|
||||
|
||||
indices->add( ( z + 1 ) * numVertsAcross + x + meshStartIndex );
|
||||
|
||||
indices->add( ( z + 0 ) * numVertsAcross + x + 1 + meshStartIndex );
|
||||
|
||||
// triangle 2 of quad
|
||||
indices->add( ( z + 1 ) * numVertsAcross + x + meshStartIndex );
|
||||
|
||||
indices->add( ( z + 1 ) * numVertsAcross + x + 1 + meshStartIndex );
|
||||
|
||||
indices->add( ( z + 0 ) * numVertsAcross + x + 1 + meshStartIndex );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
for ( int z = 0; z <= subdivisionsDepth; z++ ) {
|
||||
|
||||
for ( int x = 0; x <= subdivisionsWidth; x++ ) {
|
||||
|
||||
|
||||
float u = ( float ) x;// / subdivisionsWidth;
|
||||
|
||||
float v = ( float ) z;// / subdivisionsDepth;
|
||||
|
||||
|
||||
textureCoordinates->add( u );
|
||||
|
||||
textureCoordinates->add( ( 1 - v ) );
|
||||
|
||||
|
||||
vertexCoordinates->add( width * u - width * 0.5 );
|
||||
|
||||
vertexCoordinates->add( depth * v - depth * 0.5 );
|
||||
|
||||
vertexCoordinates->add( 0 );
|
||||
|
||||
|
||||
normalCoordinates->add( 0 );
|
||||
|
||||
normalCoordinates->add( 0 );
|
||||
|
||||
normalCoordinates->add( 1 );
|
||||
|
||||
|
||||
meshIndices->add( meshIndex );
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
glGenVertexArrays( 1, &this->vertexArrayObject );
|
||||
|
||||
glBindVertexArray( this->vertexArrayObject );
|
||||
|
||||
|
||||
this->vertexbuffer = this->createBuffer( "position", vertexCoordinates, GL_ARRAY_BUFFER, GL_STATIC_DRAW );
|
||||
|
||||
this->textureCoordinateBuffer = this->createBuffer( "textureCoordinates", textureCoordinates, GL_ARRAY_BUFFER, GL_STATIC_DRAW );
|
||||
|
||||
this->vertexbuffer = this->createBuffer( "meshIndex", meshIndices, GL_ARRAY_BUFFER, GL_STATIC_DRAW );
|
||||
|
||||
this->indexBuffer = this->createBuffer( "index", indices, GL_ARRAY_BUFFER, GL_STATIC_DRAW );
|
||||
|
||||
//this->subMeshPositions = this->createBuffer( "subMeshPositions", indices, GL_SHADER_STORAGE_BUFFER, GL_STATIC_DRAW );
|
||||
|
||||
int blockCount = this->blocks->length();
|
||||
|
||||
for (int i = 0; i < blockCount; ++i)
|
||||
{
|
||||
|
||||
block * currentBlock = this->blocks->get( i );
|
||||
|
||||
int size = currentBlock->bufferSize;
|
||||
|
||||
printf("Bind block %s bufferSize: %i bindingPoint: %i bufferType: %s \n\n", currentBlock->name, currentBlock->bufferSize, currentBlock->bindingPoint, currentBlock->getBufferTypeText( ) );
|
||||
|
||||
|
||||
|
||||
glBindBuffer( currentBlock->bufferType, currentBlock->buffer );
|
||||
|
||||
glBindBufferBase( currentBlock->bufferType, currentBlock->bindingPoint, currentBlock->buffer );
|
||||
|
||||
glBufferData( currentBlock->bufferType, currentBlock->bufferSize, 0, GL_DYNAMIC_DRAW );
|
||||
|
||||
}
|
||||
|
||||
|
||||
glBindVertexArray( 0 );
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
|
||||
unsigned int uniformBufferSize = 152; // allocate 152 bytes of memory
|
||||
|
||||
glGenBuffers( 1, &this->uniformBuffer );
|
||||
|
||||
glBindBuffer( GL_UNIFORM_BUFFER, this->uniformBuffer );
|
||||
|
||||
glBufferData( GL_UNIFORM_BUFFER, uniformBufferSize, NULL, GL_DYNAMIC_DRAW );
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
glBindBuffer( GL_UNIFORM_BUFFER, this->uniformBuffer );
|
||||
|
||||
//glBufferData( this->uniformBuffer, size, data );
|
||||
|
||||
glBufferSubData( this->uniformBuffer, offset, size, data );
|
||||
*/
|
||||
|
||||
//glBindBufferRange( GL_UNIFORM_BUFFER, 0, uboMatrices, 0, 2 * sizeof(glm::mat4) );
|
||||
|
||||
|
||||
/*
|
||||
glm::mat4 projection = glm::perspective(glm::radians(45.0f), (float)width/(float)height, 0.1f, 100.0f);
|
||||
glBindBuffer(GL_UNIFORM_BUFFER, uboMatrices);
|
||||
glBufferSubData(GL_UNIFORM_BUFFER, 0, sizeof(glm::mat4), glm::value_ptr(projection));
|
||||
glBindBuffer(GL_UNIFORM_BUFFER, 0);
|
||||
|
||||
|
||||
glm::mat4 view = camera.GetViewMatrix();
|
||||
glBindBuffer(GL_UNIFORM_BUFFER, uboMatrices);
|
||||
glBufferSubData(GL_UNIFORM_BUFFER, sizeof(glm::mat4), sizeof(glm::mat4), glm::value_ptr(view));
|
||||
glBindBuffer(GL_UNIFORM_BUFFER, 0); */
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//glBufferSubData( GL_ELEMENT_ARRAY_BUFFER, 0, indexBufferSize, indices->items );
|
||||
|
||||
|
||||
/*
|
||||
int vertexCount = vertexCoordinates->length();
|
||||
|
||||
for (int i = 0; i < vertexCount; ++i)
|
||||
{
|
||||
|
||||
float currentVertex = vertexCoordinates->get( i );
|
||||
|
||||
printf(" %i: %f \n", i, currentVertex);
|
||||
|
||||
}
|
||||
|
||||
int indexCount = indices->length();
|
||||
|
||||
printf("\n\n");
|
||||
|
||||
for (int i = 0; i < indexCount; ++i)
|
||||
{
|
||||
|
||||
int currentIndex = indices->get( i );
|
||||
|
||||
printf(" %i: %i \n", i, currentIndex);
|
||||
|
||||
}
|
||||
|
||||
printf("number of indices: %i\n", indices->length());
|
||||
*/
|
||||
|
||||
this->indices = indices;
|
||||
|
||||
this->textureCoordinates = textureCoordinates;
|
||||
|
||||
this->vertexCoordinates = vertexCoordinates;
|
||||
|
||||
this->normalCoordinates = normalCoordinates;
|
||||
|
||||
}
|
||||
|
||||
createOrderedTriangleStripQuad() {
|
||||
|
||||
|
||||
/*
|
||||
vector3 * a = new vector3(0.0, 0.0, 0.0);
|
||||
|
||||
vector3 * b = new vector3(0.0, 0.5, 0.0);
|
||||
|
||||
vector3 * c = new vector3(0.5, 0.0, 0.0);
|
||||
|
||||
vector3 * d = new vector3(0.5, 0.5, 0.0);
|
||||
|
||||
GLfloat g_vertex_buffer_data[ 12 * 2 ];
|
||||
|
||||
for (int i = 0; i < 2; ++i)
|
||||
{
|
||||
|
||||
int vectorIndex = i * 3;
|
||||
|
||||
float index = 0.5 *i;
|
||||
|
||||
g_vertex_buffer_data[ vectorIndex + 0 ] = 0.0 - index;
|
||||
|
||||
g_vertex_buffer_data[ vectorIndex + 1 ] = 0.;
|
||||
|
||||
g_vertex_buffer_data[ vectorIndex + 2 ] = 0.0;
|
||||
|
||||
|
||||
g_vertex_buffer_data[ vectorIndex + 3 ] = 0.0 - index;
|
||||
|
||||
g_vertex_buffer_data[ vectorIndex + 4 ] = 0.5;
|
||||
|
||||
g_vertex_buffer_data[ vectorIndex + 5 ] = 0.0;
|
||||
|
||||
|
||||
g_vertex_buffer_data[ vectorIndex + 6 ] = 0.5 - index;
|
||||
|
||||
g_vertex_buffer_data[ vectorIndex + 7 ] = 0.0;
|
||||
|
||||
g_vertex_buffer_data[ vectorIndex + 8 ] = 0.0;
|
||||
|
||||
|
||||
g_vertex_buffer_data[ vectorIndex + 9 ] = 0.5 - index;
|
||||
|
||||
g_vertex_buffer_data[ vectorIndex + 10 ] = 0.5;
|
||||
|
||||
g_vertex_buffer_data[ vectorIndex + 11 ] = 0.0;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
GLfloat g_vertex_buffer_data[] = {
|
||||
0.0, 0.0, 0.0f,
|
||||
0.0, 0.5, 0.0f,
|
||||
0.5f, 0.0f, 0.0f,
|
||||
.5, 0.5, 0.0
|
||||
|
||||
};
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
338
application/source/engine/opengl.c
Normal file
338
application/source/engine/opengl.c
Normal file
@@ -0,0 +1,338 @@
|
||||
|
||||
#include "./mesh.h"
|
||||
|
||||
#include "./shader.h"
|
||||
|
||||
#include "./sampler2D.h"
|
||||
|
||||
#include "./texture2D.h"
|
||||
|
||||
#include "./floatArray.h"
|
||||
|
||||
#include "./unsignedIntegerArray.h"
|
||||
|
||||
#include "./eventManager.h"
|
||||
|
||||
#include "./pipeline.h"
|
||||
|
||||
|
||||
#include "./renderPasses/renderPassQuads.h"
|
||||
|
||||
#include "./renderPasses/renderPassFont.h"
|
||||
|
||||
#include "./renderPasses/renderPassCompute.h"
|
||||
|
||||
#include "./renderPasses/renderPassCompute2.h"
|
||||
|
||||
#include "./renderPasses/renderPassTesselation.h"
|
||||
|
||||
|
||||
|
||||
#include "./resourceManager.h"
|
||||
|
||||
#include "./windowManager.h"
|
||||
|
||||
#include "./event.h"
|
||||
|
||||
|
||||
#include <math.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <X11/Xlib.h>
|
||||
|
||||
#include <X11/keysym.h>
|
||||
|
||||
#define GL_GLEXT_PROTOTYPES
|
||||
|
||||
#include <GL/glext.h>
|
||||
|
||||
#include <GL/gl.h> // GL 1.1 functions
|
||||
|
||||
#include <GL/glx.h>
|
||||
|
||||
|
||||
#include <time.h>
|
||||
|
||||
#include <zlib.h>
|
||||
|
||||
|
||||
|
||||
|
||||
event * globalEvent;
|
||||
|
||||
resourceManager * resources;
|
||||
|
||||
|
||||
|
||||
class opengl{
|
||||
|
||||
Display * mainDisplay;
|
||||
|
||||
Window mainWindow;
|
||||
|
||||
int MainScreen;
|
||||
|
||||
Window RootWindow;
|
||||
|
||||
|
||||
int lastTime = clock();
|
||||
|
||||
struct timespec startTime;
|
||||
|
||||
int frameCount = 0;
|
||||
|
||||
|
||||
|
||||
sampler2D * testSampler;
|
||||
|
||||
struct windowManager * windowManager = new windowManager();
|
||||
|
||||
|
||||
|
||||
struct eventManger * eventManger = new eventManger();
|
||||
|
||||
struct pipeline * pipeline = new pipeline();
|
||||
|
||||
|
||||
|
||||
|
||||
initialize() {
|
||||
|
||||
printf("initialize opengl.\n");
|
||||
|
||||
resources = new resourceManager();
|
||||
|
||||
this->setupWindow();
|
||||
|
||||
this->setupManagers();
|
||||
|
||||
this->showVersion();
|
||||
|
||||
//this->createTexture();
|
||||
|
||||
this->setupPipeline();
|
||||
|
||||
//this->loadFont();
|
||||
|
||||
this->setupTime();
|
||||
|
||||
this->setupRenderLoop();
|
||||
|
||||
}
|
||||
|
||||
showExtensions() {
|
||||
|
||||
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);
|
||||
|
||||
|
||||
}
|
||||
|
||||
showVersion() {
|
||||
|
||||
printf("opengl version : %s\n\n", glGetString(GL_VERSION) );
|
||||
|
||||
}
|
||||
|
||||
setupTime() {
|
||||
|
||||
clock_gettime( CLOCK_REALTIME, &this->startTime );
|
||||
|
||||
}
|
||||
|
||||
setupManagers() {
|
||||
|
||||
this->eventManger->mainDisplay = this->mainDisplay;
|
||||
|
||||
this->eventManger->mainWindow = this->mainWindow;
|
||||
|
||||
this->eventManger->RootWindow = this->RootWindow;
|
||||
|
||||
}
|
||||
|
||||
setupWindow() {
|
||||
|
||||
this->windowManager->setupDisplay();
|
||||
|
||||
this->windowManager->setupWindow();
|
||||
|
||||
|
||||
this->mainDisplay = this->windowManager->mainDisplay;
|
||||
|
||||
this->mainWindow = this->windowManager->mainWindow;
|
||||
|
||||
this->RootWindow = this->windowManager->RootWindow;
|
||||
|
||||
}
|
||||
|
||||
setupRenderLoop() {
|
||||
|
||||
int IsProgramRunning = 1;
|
||||
|
||||
while( IsProgramRunning ) {
|
||||
|
||||
while( XPending( this->mainDisplay ) ) {
|
||||
|
||||
XEvent GeneralEvent = {};
|
||||
|
||||
XNextEvent( this->mainDisplay, &GeneralEvent );
|
||||
|
||||
switch( GeneralEvent.type ) {
|
||||
|
||||
case ClientMessage:
|
||||
|
||||
|
||||
IsProgramRunning = 0;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
this->render();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
setupPipeline() {
|
||||
|
||||
quads * quadsPass = new quads();
|
||||
|
||||
font * fontPass = new font();
|
||||
|
||||
compute * computePass = new compute();
|
||||
|
||||
compute2 * computePass2 = new compute2();
|
||||
|
||||
tesselation * tesselationPass = new tesselation();
|
||||
|
||||
|
||||
//this->pipeline->addRenderPass( fontPass );
|
||||
|
||||
this->pipeline->addRenderPass( quadsPass );
|
||||
|
||||
//this->pipeline->addRenderPass( computePass );
|
||||
|
||||
//this->pipeline->addRenderPass( computePass2 );
|
||||
|
||||
//this->pipeline->addRenderPass( tesselationPass );
|
||||
|
||||
|
||||
}
|
||||
|
||||
double clockToMilliseconds( clock_t ticks ){
|
||||
|
||||
return ( ticks / ( double ) CLOCKS_PER_SEC );
|
||||
|
||||
}
|
||||
|
||||
render() {
|
||||
|
||||
//this->clearColor( 0.0, 0.0, 0.0, 0.0 );
|
||||
|
||||
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
|
||||
|
||||
this->clear( GL_DEPTH_BUFFER_BIT );
|
||||
|
||||
globalEvent = this->eventManger->fetchEvent();
|
||||
|
||||
this->pipeline->render();
|
||||
|
||||
this->swapBuffers();
|
||||
|
||||
//this->displayFPS();
|
||||
|
||||
}
|
||||
|
||||
displayFPS() {
|
||||
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
clear( GLbitfield mask ) {
|
||||
|
||||
glClear( mask );
|
||||
|
||||
}
|
||||
|
||||
clearColor( float r, float g, float b, float a ) {
|
||||
|
||||
glClearColor( r, g, b, a );
|
||||
|
||||
}
|
||||
|
||||
swapBuffers() {
|
||||
|
||||
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 );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
82
application/source/engine/pipeline.c
Normal file
82
application/source/engine/pipeline.c
Normal file
@@ -0,0 +1,82 @@
|
||||
|
||||
#include "../int.h"
|
||||
|
||||
#include "../array.h"
|
||||
|
||||
#include "./renderPasses/renderPass.h"
|
||||
|
||||
#include "./vector.h"
|
||||
|
||||
#include "../classConfiguration.h"
|
||||
|
||||
|
||||
|
||||
reflect
|
||||
class pipeline{
|
||||
|
||||
array * renderPasses = new array();
|
||||
|
||||
vector<int> * classIndices = new vector();
|
||||
|
||||
vector<int> * methodIndices = new vector();
|
||||
|
||||
addRenderPass( ... ) {
|
||||
|
||||
va_list args;
|
||||
|
||||
va_start( args, count );
|
||||
|
||||
int classIndex = datatypes[0];
|
||||
|
||||
this->classIndices->add( classIndex );
|
||||
|
||||
|
||||
|
||||
void * voidPointer = va_arg( args, void * );
|
||||
|
||||
int methodIndex = getMethodIndexByPropertyName( classIndex, "prepare" );
|
||||
|
||||
int renderMethodIndex = getMethodIndexByPropertyName( classIndex, "render" );
|
||||
|
||||
|
||||
this->methodIndices->add( renderMethodIndex );
|
||||
|
||||
|
||||
|
||||
int classIndexTest = this->classIndices->get( 0 );
|
||||
|
||||
//printf("\n\n\n\n%i\n\n\n\n", classIndexTest);
|
||||
|
||||
callMethodOfClass( classIndex, methodIndex, voidPointer );
|
||||
|
||||
printf("\n");
|
||||
|
||||
va_end( args );
|
||||
|
||||
|
||||
this->renderPasses->add( voidPointer );
|
||||
|
||||
}
|
||||
|
||||
render() {
|
||||
|
||||
array * renderPasses = this->renderPasses;
|
||||
|
||||
int renderPassCount = renderPasses->length();
|
||||
|
||||
for (int i = 0; i < renderPassCount; ++i)
|
||||
{
|
||||
|
||||
int classIndex = this->classIndices->get( i );
|
||||
|
||||
void * voidPointer = renderPasses->get( i );
|
||||
|
||||
int methodIndex = this->methodIndices->get( i );
|
||||
|
||||
callMethodOfClass( classIndex, methodIndex, voidPointer );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
534
application/source/engine/program.c
Normal file
534
application/source/engine/program.c
Normal file
@@ -0,0 +1,534 @@
|
||||
|
||||
#include "block.h"
|
||||
|
||||
#include "member.h"
|
||||
|
||||
#include "uniform.h"
|
||||
|
||||
|
||||
#define GL_GLEXT_PROTOTYPES
|
||||
|
||||
#include <GL/glext.h>
|
||||
|
||||
#include <GL/gl.h> // GL 1.1 functions
|
||||
|
||||
#include <GL/glx.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "fileSystem.h"
|
||||
|
||||
#include "../array.h"
|
||||
|
||||
#include "../char.h"
|
||||
|
||||
#include "sampler2D.h"
|
||||
|
||||
#include "shader.h"
|
||||
|
||||
class program{
|
||||
|
||||
|
||||
GLuint samplerIndex = 0;
|
||||
|
||||
array * uniforms = new array();
|
||||
|
||||
array * attributes = new array();
|
||||
|
||||
array * blocks = new array();
|
||||
|
||||
array * shaders = new array();
|
||||
|
||||
GLuint glProgram;
|
||||
|
||||
|
||||
|
||||
addShader( struct shader * shaderInstance ) {
|
||||
|
||||
this->shaders->add( shaderInstance );
|
||||
|
||||
}
|
||||
|
||||
|
||||
GLint glGetProgramResourceiv( GLint programProperty, GLint index, GLint Property ) {
|
||||
|
||||
GLint offsetValues;
|
||||
|
||||
glGetProgramResourceiv( this->glProgram, programProperty, index, 1, &Property , 1, 0, &offsetValues );
|
||||
|
||||
return offsetValues;
|
||||
|
||||
}
|
||||
|
||||
GLchar * glGetProgramResourceName( 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 extractBlocks() {
|
||||
|
||||
GLint programInterfaces[2] = { GL_SHADER_STORAGE_BLOCK, GL_UNIFORM_BLOCK }; // GL_UNIFORM_BLOCK
|
||||
|
||||
GLint programProperties[2] = { GL_BUFFER_VARIABLE, GL_UNIFORM }; // GL_UNIFORM , GL_PROGRAM_INPUT
|
||||
|
||||
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]; // GL_UNIFORM_BLOCK
|
||||
|
||||
GLint programProperty = programProperties[blockTypeIndex]; // GL_UNIFORM
|
||||
|
||||
GLenum programBufferType = programBufferTypes[blockTypeIndex];
|
||||
|
||||
glGetProgramInterfaceiv( program, programInterface, GL_ACTIVE_RESOURCES, &numActiveResources );
|
||||
|
||||
//printf("extractShaderStorageBuffers %i\n\n", numActiveResources);
|
||||
|
||||
for ( GLuint blockIndex = 0; blockIndex < numActiveResources; blockIndex++ ) {
|
||||
|
||||
struct block * blockInstance = new block();
|
||||
|
||||
//GLint blockIndex = this->glGetProgramResourceiv( programInterface, blockIndex, GL_BLOCK_INDEX );
|
||||
|
||||
GLint blockNameLength = this->glGetProgramResourceiv( programInterface, blockIndex, GL_NAME_LENGTH );
|
||||
|
||||
blockInstance->bufferSize = this->glGetProgramResourceiv( programInterface, blockIndex, GL_BUFFER_DATA_SIZE );
|
||||
|
||||
GLint numberActiveVariables = this->glGetProgramResourceiv( programInterface, blockIndex, GL_NUM_ACTIVE_VARIABLES );
|
||||
|
||||
blockInstance->bindingPoint = this->glGetProgramResourceiv( programInterface, blockIndex, GL_BUFFER_BINDING );
|
||||
|
||||
//const GLchar * name = this->glGetProgramResourceName( programInterface, blockIndex, blockNameLength );
|
||||
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);
|
||||
|
||||
// add block
|
||||
|
||||
|
||||
for ( GLuint index = 0; index < numberActiveVariables; index++ )
|
||||
{
|
||||
|
||||
struct member * memberInstance = new member();
|
||||
|
||||
|
||||
GLint itemIndex = indices[ index ];
|
||||
|
||||
memberInstance->index = itemIndex;
|
||||
|
||||
GLint nameLength = this->glGetProgramResourceiv( programProperty, itemIndex, GL_NAME_LENGTH );
|
||||
|
||||
memberInstance->offset = this->glGetProgramResourceiv( programProperty, itemIndex, GL_OFFSET );
|
||||
|
||||
memberInstance->type = this->glGetProgramResourceiv( programProperty, itemIndex, GL_TYPE );
|
||||
|
||||
memberInstance->arrayStride = this->glGetProgramResourceiv( programProperty, itemIndex, GL_ARRAY_STRIDE );
|
||||
|
||||
|
||||
memberInstance->size = this->glGetProgramResourceiv( programProperty, itemIndex, GL_ARRAY_SIZE );
|
||||
|
||||
int topLevelSize = this->glGetProgramResourceiv( programProperty, itemIndex, GL_TOP_LEVEL_ARRAY_SIZE );
|
||||
|
||||
int topLevelStride = this->glGetProgramResourceiv( programProperty, itemIndex, GL_TOP_LEVEL_ARRAY_STRIDE );
|
||||
|
||||
|
||||
if( memberInstance->arrayStride == 0 ) {
|
||||
|
||||
memberInstance->arrayStride = topLevelStride;
|
||||
|
||||
}
|
||||
|
||||
memberInstance->topLevelSize = topLevelSize;
|
||||
|
||||
|
||||
// memberInstance->name = this->glGetProgramResourceName( programProperty, itemIndex, nameLength );
|
||||
|
||||
|
||||
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 );
|
||||
|
||||
|
||||
|
||||
blockInstance->add( memberInstance );
|
||||
|
||||
}
|
||||
|
||||
blockInstance->createBuffer();
|
||||
|
||||
this->blocks->add( blockInstance );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
struct block * createNewBlock( char * blockName ) {
|
||||
|
||||
printf("Copy buffer: %s\n\n", blockName);
|
||||
|
||||
block * originalBlock = this->getBlock( blockName );
|
||||
|
||||
block * blockCopy = new block();
|
||||
|
||||
blockCopy->members = originalBlock->members;
|
||||
|
||||
blockCopy->bindingPoint = originalBlock->bindingPoint;
|
||||
|
||||
blockCopy->index = originalBlock->index;
|
||||
|
||||
blockCopy->bufferSize = originalBlock->bufferSize;
|
||||
|
||||
blockCopy->createBuffer();
|
||||
|
||||
return blockCopy;
|
||||
|
||||
}
|
||||
|
||||
struct block * getBlock( char * blockName ) {
|
||||
|
||||
int blockCount = this->blocks->length();
|
||||
|
||||
for ( int i = 0; i < blockCount; ++i )
|
||||
{
|
||||
block * currentBlock = this->blocks->get( i );
|
||||
|
||||
char * currentBlockName = currentBlock->name;
|
||||
|
||||
if( currentBlockName == blockName ) {
|
||||
|
||||
return currentBlock;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
||||
}
|
||||
|
||||
create() {
|
||||
|
||||
this->glProgram = glCreateProgram();
|
||||
|
||||
|
||||
array * shaders = this->shaders;
|
||||
|
||||
int shaderCount = shaders->length();
|
||||
|
||||
|
||||
for (int i = 0; i < shaderCount; ++i)
|
||||
{
|
||||
|
||||
shader * currentShader = shaders->get( i );
|
||||
|
||||
glAttachShader( this->glProgram, currentShader->glShader );
|
||||
|
||||
}
|
||||
|
||||
glLinkProgram( this->glProgram );
|
||||
|
||||
glUseProgram( this->glProgram );
|
||||
|
||||
|
||||
this->extractBlocks();
|
||||
|
||||
this->extractAttributes();
|
||||
|
||||
this->extractUniforms();
|
||||
|
||||
}
|
||||
|
||||
bindBlock( char * blockName ) {
|
||||
|
||||
block * currentBlock = this->getBlock( blockName );
|
||||
|
||||
glBindBufferBase( currentBlock->bufferType, currentBlock->bindingPoint, currentBlock->buffer );
|
||||
|
||||
}
|
||||
|
||||
use() {
|
||||
|
||||
glUseProgram( this->glProgram );
|
||||
|
||||
}
|
||||
|
||||
|
||||
extractUniforms() {
|
||||
|
||||
int attributeCount = 0;
|
||||
|
||||
GLsizei bufSize = 64;
|
||||
|
||||
GLsizei length; // name length
|
||||
|
||||
GLint size;
|
||||
|
||||
GLenum type; // type of the variable (float, vec3 or mat4, etc)
|
||||
|
||||
int uniformCount = 0;
|
||||
|
||||
glGetProgramiv( this->glProgram, GL_ACTIVE_UNIFORMS, &uniformCount );
|
||||
|
||||
for (int i = 0; i < uniformCount; i++)
|
||||
{
|
||||
|
||||
struct uniform * uniformInstance = new uniform();
|
||||
|
||||
GLenum type;
|
||||
|
||||
GLchar name[bufSize];
|
||||
|
||||
glGetActiveUniform( this->glProgram, ( GLuint ) i, bufSize, &length, &size, &type, uniformInstance->name );
|
||||
|
||||
//printf( " Uniform #%d Type: %u Name: %s\n", i, type, uniformInstance->name );
|
||||
|
||||
GLint uniformLocation = glGetUniformLocation( this->glProgram, uniformInstance->name );
|
||||
|
||||
uniformInstance->location = uniformLocation;
|
||||
|
||||
uniformInstance->type = type;
|
||||
|
||||
this->uniforms->add( uniformInstance );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extractAttributes() {
|
||||
|
||||
int attributeCount = 0;
|
||||
|
||||
GLsizei bufSize = 64;
|
||||
|
||||
GLsizei length; // name length
|
||||
|
||||
GLint size;
|
||||
|
||||
GLenum type; // type of the variable (float, vec3 or mat4, etc)
|
||||
|
||||
glGetProgramiv( this->glProgram, GL_ACTIVE_ATTRIBUTES, &attributeCount );
|
||||
|
||||
for (int i = 0; i < attributeCount; i++)
|
||||
{
|
||||
GLenum type;
|
||||
|
||||
attribute * attributeInstance = new attribute();
|
||||
|
||||
glGetActiveAttrib( this->glProgram, ( GLuint ) i, bufSize, &length, &size, &type, attributeInstance->name);
|
||||
|
||||
//printf(" Attribute #%d Type: %u Name: %s size: %i\n", i, type, attributeInstance->name, size);
|
||||
|
||||
GLint attributeLocation = glGetAttribLocation( this->glProgram, attributeInstance->name );
|
||||
|
||||
glEnableVertexAttribArray( attributeLocation );
|
||||
|
||||
|
||||
attributeInstance->location = attributeLocation;
|
||||
|
||||
//attributeInstance.name = name;
|
||||
|
||||
attributeInstance->type = type;
|
||||
|
||||
this->attributes->add( attributeInstance );
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
struct attribute * getAttributeByName( char * attributeName ) {
|
||||
|
||||
int attributeCount = this->attributes->length();
|
||||
|
||||
//printf("uniformCount: %i\n\n", attributeCount);
|
||||
|
||||
for ( int i = 0; i < attributeCount; ++i )
|
||||
{
|
||||
struct attribute * currentAttribute = this->attributes->get( i );
|
||||
|
||||
char * currentAttributeName = currentAttribute->name;
|
||||
|
||||
//printf("attributeName->name: %s %s\n\n", currentAttributeName, attributeName );
|
||||
|
||||
if( currentAttributeName == attributeName ) {
|
||||
|
||||
return currentAttribute;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
||||
}
|
||||
|
||||
void setUniform( char * name, void * value ) {
|
||||
|
||||
int uniformCount = this->uniforms->length();
|
||||
|
||||
// printf("uniformCount: %i\n\n", uniformCount);
|
||||
|
||||
for (int i = 0; i < uniformCount; ++i)
|
||||
{
|
||||
uniform * currentUniform = this->uniforms->get( i );
|
||||
|
||||
char * uniformName = (char *)currentUniform->name;
|
||||
|
||||
// printf("currentUniform->name: %s\n\n", uniformName);
|
||||
|
||||
if( uniformName == name ) {
|
||||
|
||||
//printf("\n\n Update this uniform %s\n\n", name);
|
||||
|
||||
switch( currentUniform->type ) {
|
||||
|
||||
|
||||
case GL_FLOAT_VEC2:
|
||||
|
||||
vector2 * vector2Value = ( vector2 * ) value;
|
||||
|
||||
//printf("\n\n this is an float vec2 %f %f \n\n", vector2Value->x, vector2Value->y );
|
||||
|
||||
glUniform2f( currentUniform->location, vector2Value->x, vector2Value->y );
|
||||
|
||||
break;
|
||||
|
||||
case GL_FLOAT_VEC3:
|
||||
|
||||
vector3 * vector3Value = ( vector3 * ) value;
|
||||
|
||||
//printf("\n\n this is an float vec3 %f %f %f \n\n", vector3Value->x, vector3Value->y, vector3Value->z);
|
||||
|
||||
glUniform3f( currentUniform->location, vector3Value->x, vector3Value->y, vector3Value->z );
|
||||
|
||||
break;
|
||||
|
||||
case GL_SAMPLER_2D:
|
||||
|
||||
this->updateSampler2D( currentUniform, value );
|
||||
|
||||
break;
|
||||
|
||||
|
||||
case GL_SAMPLER_2D_ARRAY:
|
||||
|
||||
this->updateSampler2D( currentUniform, value );
|
||||
|
||||
break;
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
updateSampler2D( 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++;
|
||||
|
||||
sampler->bind();
|
||||
|
||||
//printf("sampler->index: %i \n", sampler->index);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
glActiveTexture( GL_TEXTURE0 + sampler->index );
|
||||
|
||||
glBindTexture( sampler->target, sampler->glTexture );
|
||||
|
||||
//glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB,GL_UNSIGNED_BYTE, texture );
|
||||
|
||||
glUniform1i( currentUniform->location, sampler->index );
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
40
application/source/engine/quadMesh.c
Normal file
40
application/source/engine/quadMesh.c
Normal file
@@ -0,0 +1,40 @@
|
||||
|
||||
#include "vector2.h"
|
||||
|
||||
#include "vector3.h"
|
||||
|
||||
#include "vector.h"
|
||||
|
||||
|
||||
|
||||
class quadMesh {
|
||||
|
||||
vector2 position;
|
||||
|
||||
vector2 size;
|
||||
|
||||
vector3 color;
|
||||
|
||||
float zIndex;
|
||||
|
||||
float opacity;
|
||||
|
||||
int textureIndex;
|
||||
|
||||
int features;
|
||||
|
||||
int elementIndex;
|
||||
|
||||
|
||||
|
||||
|
||||
// ------------
|
||||
|
||||
//float PADDING;
|
||||
|
||||
// -----------
|
||||
|
||||
//struct vector<int> * characters;
|
||||
|
||||
|
||||
}
|
||||
27
application/source/engine/renderPasses/renderPass.c
Normal file
27
application/source/engine/renderPasses/renderPass.c
Normal file
@@ -0,0 +1,27 @@
|
||||
|
||||
#include "shader.h"
|
||||
|
||||
#include "mesh.h"
|
||||
|
||||
|
||||
class renderPass{
|
||||
|
||||
bool enabled = true;
|
||||
|
||||
struct shader * shader;
|
||||
|
||||
struct mesh * mesh;
|
||||
|
||||
prepare() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
render() {
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
96
application/source/engine/renderPasses/renderPassCompute.c
Normal file
96
application/source/engine/renderPasses/renderPassCompute.c
Normal file
@@ -0,0 +1,96 @@
|
||||
|
||||
|
||||
#include "./renderPass.h"
|
||||
|
||||
#include "../event.h"
|
||||
|
||||
#include "../vector2.h"
|
||||
|
||||
#include "../shader.h"
|
||||
|
||||
#include "../program.h"
|
||||
|
||||
#include "../int.h"
|
||||
|
||||
#include "../sampler2D.h"
|
||||
|
||||
#include "stdbool.h"
|
||||
|
||||
#include "../block.h"
|
||||
|
||||
#include "../vector.h"
|
||||
|
||||
#include "../mesh.h"
|
||||
|
||||
|
||||
class compute extends renderPass{
|
||||
|
||||
|
||||
struct program * program;
|
||||
|
||||
int active = true;
|
||||
|
||||
prepare() {
|
||||
|
||||
printf("\n\n\n Prepare renderPass Compute\n\n\n\n\n");
|
||||
|
||||
shader * computeShader = new shader( GL_COMPUTE_SHADER );
|
||||
|
||||
computeShader->loadFromFile( "assets/shaders/addition.comp" );
|
||||
|
||||
|
||||
this->program = new program();
|
||||
|
||||
this->program->addShader( computeShader );
|
||||
|
||||
this->program->create();
|
||||
|
||||
|
||||
vector<vector2> * inputA = new vector();
|
||||
|
||||
for (int i = 0; i < 100; ++i)
|
||||
{
|
||||
|
||||
vector2 a = new vector2( i, i );
|
||||
|
||||
inputA->add( a );
|
||||
|
||||
}
|
||||
|
||||
vector<vector2> * inputB = new vector();
|
||||
|
||||
for (int i = 0; i < 100; ++i)
|
||||
{
|
||||
|
||||
vector2 a = new vector2( 0, 10 );
|
||||
|
||||
inputB->add( a );
|
||||
|
||||
}
|
||||
|
||||
block * inputBlock = this->program->getBlock( "inputBlock" );
|
||||
|
||||
inputBlock->setMemberArray( "array_a[0]", ( float * ) inputA->items );
|
||||
|
||||
inputBlock->setMemberArray( "array_b[0]", ( float * ) inputB->items );
|
||||
|
||||
inputBlock->upload();
|
||||
|
||||
}
|
||||
|
||||
render() {
|
||||
|
||||
this->program->use();
|
||||
|
||||
this->program->bindBlock( "inputBlock");
|
||||
|
||||
this->program->bindBlock( "outputBlock");
|
||||
|
||||
|
||||
glDispatchCompute( 1, 1, 1 );
|
||||
|
||||
glMemoryBarrier( GL_SHADER_STORAGE_BARRIER_BIT );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
80
application/source/engine/renderPasses/renderPassCompute2.c
Normal file
80
application/source/engine/renderPasses/renderPassCompute2.c
Normal file
@@ -0,0 +1,80 @@
|
||||
|
||||
#include "renderPass.h"
|
||||
|
||||
#include "../event.h"
|
||||
|
||||
#include "../../vector2.h"
|
||||
|
||||
#include "../shader.h"
|
||||
|
||||
#include "../program.h"
|
||||
|
||||
#include "../../int.h"
|
||||
|
||||
#include "../sampler2D.h"
|
||||
|
||||
#include "stdbool.h"
|
||||
|
||||
#include "../block.h"
|
||||
|
||||
|
||||
class compute2 extends renderPass{
|
||||
|
||||
struct program * program;
|
||||
|
||||
int active = true;
|
||||
|
||||
|
||||
prepare() {
|
||||
|
||||
printf("\n\n\n Prepare renderPass Compute 2\n\n\n\n\n");
|
||||
|
||||
shader * computeShader = new shader( GL_COMPUTE_SHADER );
|
||||
|
||||
computeShader->loadFromFile( "assets/shaders/addition2.comp" );
|
||||
|
||||
|
||||
this->program = new program();
|
||||
|
||||
this->program->addShader( computeShader );
|
||||
|
||||
this->program->create();
|
||||
|
||||
}
|
||||
|
||||
render() {
|
||||
|
||||
if( this->active ) {
|
||||
|
||||
this->program->use();
|
||||
|
||||
this->program->bindBlock( "outputBlock2" );
|
||||
|
||||
|
||||
glDispatchCompute( 1, 1, 1 );
|
||||
|
||||
|
||||
block * outputBlock = this->program->getBlock( "outputBlock2" );
|
||||
|
||||
vector<vector2> * output = outputBlock->getMemberArray( "array_d[0]" );
|
||||
|
||||
int count = output->length();
|
||||
|
||||
for (int i = 0; i < count; ++i)
|
||||
{
|
||||
|
||||
vector2 currentVector = output->get( i );
|
||||
|
||||
printf("%i = %f %f \n", i, i, currentVector.x, currentVector.y );
|
||||
|
||||
}
|
||||
|
||||
printf("length: %i\n\n", count);
|
||||
|
||||
this->active = false;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
174
application/source/engine/renderPasses/renderPassFont.c
Normal file
174
application/source/engine/renderPasses/renderPassFont.c
Normal file
@@ -0,0 +1,174 @@
|
||||
|
||||
|
||||
#include "renderPass.h"
|
||||
|
||||
#include "../event.h"
|
||||
|
||||
#include "../vector2.h"
|
||||
|
||||
#include "../shader.h"
|
||||
|
||||
#include "int.h"
|
||||
|
||||
#include "../fontRenderer.h"
|
||||
|
||||
#include "../program.h"
|
||||
|
||||
#include "../mesh.h"
|
||||
|
||||
class font extends renderPass{
|
||||
|
||||
|
||||
struct program * program;
|
||||
|
||||
struct mesh * mesh;
|
||||
|
||||
fontRenderer * font = new fontRenderer();
|
||||
|
||||
sampler2D * samplerArray;
|
||||
|
||||
char * textFromNumber( int i) {
|
||||
|
||||
char * fileName = malloc( sizeof( char ) * 100 );
|
||||
|
||||
sprintf( fileName, "%d", i );
|
||||
|
||||
return fileName;
|
||||
|
||||
}
|
||||
|
||||
prepare() {
|
||||
|
||||
printf("\n\n\n Prepare renderPass Font\n\n\n\n\n");
|
||||
|
||||
|
||||
|
||||
|
||||
shader * vertexShader = new shader( GL_VERTEX_SHADER );
|
||||
|
||||
vertexShader->loadFromFile( "assets/shaders/quad.vertex" );
|
||||
|
||||
|
||||
shader * fragmentShader = new shader( GL_FRAGMENT_SHADER );
|
||||
|
||||
fragmentShader->loadFromFile( "assets/shaders/quad.fragment" );
|
||||
|
||||
|
||||
|
||||
this->program = new program();
|
||||
|
||||
this->program->addShader( vertexShader );
|
||||
|
||||
this->program->addShader( fragmentShader );
|
||||
|
||||
this->program->create();
|
||||
|
||||
|
||||
sampler2D * samplerArray = new sampler2D();
|
||||
|
||||
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 = new vector3( 128, 128, 170 );
|
||||
|
||||
samplerArray->UNPACK_ALIGNMENT = true;
|
||||
|
||||
|
||||
this->samplerArray = samplerArray;
|
||||
|
||||
block * fontBlock = this->program->getBlock( "fontData" );
|
||||
|
||||
|
||||
this->mesh = new mesh();
|
||||
|
||||
this->mesh->setProgram( this->program );
|
||||
|
||||
this->mesh->createBuffers();
|
||||
|
||||
|
||||
glUseProgram( this->program->glProgram );
|
||||
|
||||
for ( int i = 1; i < 170; ++i )
|
||||
{
|
||||
texture2D * characterTexture = this->font->loadFont( 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 = new vector2( characterTexture->width, characterTexture->height );
|
||||
|
||||
fontBlock->setMemberItem( "fontOffsets[0]", i - 35, offset );
|
||||
|
||||
//if( i > 34 ) {
|
||||
|
||||
fontBlock->setMemberItem( "fontSizes[0]", i - 35, size );
|
||||
|
||||
//}
|
||||
|
||||
samplerArray->addTexture( characterTexture );
|
||||
|
||||
}
|
||||
|
||||
fontBlock->upload();
|
||||
|
||||
this->program->setUniform( "samplerArray", samplerArray );
|
||||
|
||||
|
||||
|
||||
vector<int> * textArray = new vector();
|
||||
|
||||
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 );
|
||||
|
||||
textArray->add( charNumber );//
|
||||
|
||||
}
|
||||
|
||||
block * inputBlock = this->program->getBlock( "inputBlock" );
|
||||
|
||||
inputBlock->setMemberArray( "characters[0]", ( float * ) textArray->items );
|
||||
|
||||
inputBlock->upload();
|
||||
|
||||
}
|
||||
|
||||
render() {
|
||||
|
||||
int numItems = 12;
|
||||
|
||||
|
||||
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
|
||||
|
||||
|
||||
this->program->use();
|
||||
|
||||
this->program->bindBlock( "inputBlock");
|
||||
|
||||
this->program->bindBlock( "fontData");
|
||||
|
||||
|
||||
this->program->setUniform( "samplerArray", this->samplerArray );
|
||||
|
||||
|
||||
|
||||
glBindVertexArray( this->mesh->vertexArrayObject );
|
||||
|
||||
glDrawElements( GL_TRIANGLES, numItems, GL_UNSIGNED_INT, ( void * ) 0 );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
700
application/source/engine/renderPasses/renderPassQuads.c
Normal file
700
application/source/engine/renderPasses/renderPassQuads.c
Normal file
@@ -0,0 +1,700 @@
|
||||
|
||||
#include "renderPass.h"
|
||||
|
||||
#include "../event.h"
|
||||
|
||||
#include "../vector2.h"
|
||||
|
||||
#include "../vector3.h"
|
||||
|
||||
#include "../vector4.h"
|
||||
|
||||
#include "../program.h"
|
||||
|
||||
#include "../shader.h"
|
||||
|
||||
#include "../program.h"
|
||||
|
||||
#include "../../int.h"
|
||||
|
||||
#include "../fontRenderer.h"
|
||||
|
||||
#include "../resourceManager.h"
|
||||
|
||||
#include "../mesh.h"
|
||||
|
||||
#include "../quadMesh.h"
|
||||
|
||||
#include "../element.h"
|
||||
|
||||
|
||||
|
||||
|
||||
extern event * globalEvent;
|
||||
|
||||
extern resourceManager * resources;
|
||||
|
||||
|
||||
|
||||
class quads extends renderPass{
|
||||
|
||||
mesh * mesh;
|
||||
|
||||
fontRenderer * font = new fontRenderer();
|
||||
|
||||
sampler2D * samplerArray;
|
||||
|
||||
program * program;
|
||||
|
||||
vector<quadMesh> * meshes = new vector();
|
||||
|
||||
vector<element> * elements = new vector();
|
||||
|
||||
vector<int> * mouseOverElements = new vector();
|
||||
|
||||
char * textFromNumber( int i) {
|
||||
|
||||
char * fileName = malloc( sizeof( char ) * 100 );
|
||||
|
||||
sprintf( fileName, "%d", i );
|
||||
|
||||
return fileName;
|
||||
|
||||
}
|
||||
|
||||
prepare() {
|
||||
|
||||
printf("\n\n\n Prepare renderPass Quad\n\n\n\n\n");
|
||||
|
||||
/*
|
||||
sampler2D * sampler1 = new sampler2D();
|
||||
|
||||
sampler1->texture = resources->loadPngImage( "logo.png" );
|
||||
|
||||
*/
|
||||
|
||||
this->samplerArray = new sampler2D();
|
||||
|
||||
|
||||
for (int i = 1; i < 10; ++i )
|
||||
{
|
||||
|
||||
char * fileName = this->textFromNumber( i );
|
||||
|
||||
fileName += ".png";
|
||||
|
||||
printf("load png: %s\n", fileName);
|
||||
|
||||
//this->samplerArray->addTexture( resources->loadPngImage( fileName ) );
|
||||
|
||||
}
|
||||
|
||||
printf("\n\n");
|
||||
|
||||
this->samplerArray->target = GL_TEXTURE_2D_ARRAY;
|
||||
|
||||
|
||||
shader * vertexShader = new shader( GL_VERTEX_SHADER );
|
||||
|
||||
vertexShader->loadFromFile( "assets/shaders/multiQuad.vertex" );
|
||||
|
||||
|
||||
shader * fragmentShader = new shader( GL_FRAGMENT_SHADER );
|
||||
|
||||
fragmentShader->loadFromFile( "assets/shaders/multiQuad.fragment" );
|
||||
|
||||
|
||||
this->program = new program();
|
||||
|
||||
this->program->addShader( vertexShader );
|
||||
|
||||
this->program->addShader( fragmentShader );
|
||||
|
||||
this->program->create();
|
||||
|
||||
|
||||
|
||||
//block * eventsBlock = this->program->getBlock( "events" );
|
||||
|
||||
block * orientationBlock = this->program->getBlock( "orientation" );
|
||||
|
||||
block * meshesBlock = this->program->getBlock( "meshes" );
|
||||
|
||||
|
||||
this->mesh = new mesh();
|
||||
|
||||
this->mesh->setProgram( this->program );
|
||||
|
||||
this->mesh->createBuffers();
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
for (int vertexIndex = 0; vertexIndex < 100; ++vertexIndex)
|
||||
{
|
||||
|
||||
int mod = vertexIndex % 10;
|
||||
|
||||
vector2 test = new vector2( mod * 0.1 , floor( vertexIndex / 10 ) * 0.1 );
|
||||
|
||||
meshesBlock->setMemberItem( "meshArray[0].position", vertexIndex, &test );
|
||||
|
||||
|
||||
vector2 size = new vector2( .05 , .05 );
|
||||
|
||||
meshesBlock->setMemberItem( "meshArray[0].size", vertexIndex, &size );
|
||||
|
||||
vector3 color = new vector3( (float)rand()/RAND_MAX, (float)rand()/RAND_MAX, (float)rand()/RAND_MAX);
|
||||
|
||||
|
||||
printf("Random: %f %f %f\n", color.x, color.y, color.z);
|
||||
|
||||
meshesBlock->setMemberItem( "meshArray[0].color", vertexIndex, &color );
|
||||
|
||||
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
this->createMeshes();
|
||||
|
||||
//this->program->setUniform( "samplerArray", this->samplerArray );
|
||||
|
||||
|
||||
this->samplerArray->addTexture( resources->loadPngImage( "1.png" ) );
|
||||
|
||||
|
||||
meshesBlock->upload();
|
||||
|
||||
}
|
||||
|
||||
sortOpacity( struct vector< struct quadMesh > * meshes ) {
|
||||
|
||||
|
||||
int count = meshes->length();
|
||||
|
||||
int i, j;
|
||||
|
||||
struct quadMesh temp;
|
||||
|
||||
for (i = 0; i < (count - 1); ++i)
|
||||
{
|
||||
for (j = 0; j < count - 1 - i; ++j )
|
||||
{
|
||||
|
||||
struct quadMesh quadA = meshes->get( j );
|
||||
|
||||
struct quadMesh quadB = meshes->get( 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;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
createMeshes() {
|
||||
|
||||
|
||||
vector<quadMesh> * meshes = this->meshes;
|
||||
|
||||
meshes->resize( 100 );
|
||||
|
||||
/*
|
||||
for (int i = 0; i < 100; ++i)
|
||||
{
|
||||
|
||||
int mod = i % 10;
|
||||
|
||||
quadMesh meshInstance = new quadMesh();
|
||||
|
||||
meshInstance.position = new vector2( mod * 0.1 , floor( i / 10 ) * 0.1 );
|
||||
|
||||
meshInstance.size = new vector2( .05 , .05 );
|
||||
|
||||
meshInstance.color = new vector3( (float) rand() / RAND_MAX, (float) rand() / RAND_MAX, (float) rand() / RAND_MAX);
|
||||
|
||||
// meshInstance.textureIndex = 0;
|
||||
|
||||
meshes->add( meshInstance );
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
vector<element> * elements = this->elements;
|
||||
|
||||
|
||||
{
|
||||
|
||||
element instance = new element();
|
||||
|
||||
instance.position = new vector3( 200, 200, 1100 );
|
||||
|
||||
instance.size = new vector2( 200., 200. );
|
||||
|
||||
//instance.background = new vector3( 0, 256, 0 );
|
||||
|
||||
instance.opacity = 1;
|
||||
|
||||
instance.background = "9.png";
|
||||
|
||||
//instance.background = new vector3( 0, 256, 0 );
|
||||
|
||||
elements->add( instance );
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
|
||||
element instance = new element();
|
||||
|
||||
instance.position = new vector3( 100, 100, 500 );
|
||||
|
||||
instance.size = new vector2( 400., 400. );
|
||||
|
||||
instance.background = "3.png";
|
||||
|
||||
//instance.background = "#2196f354";
|
||||
|
||||
//instance.background = new vector3( 0, 0, 256 );
|
||||
|
||||
instance.opacity = .9;
|
||||
|
||||
|
||||
/*
|
||||
|
||||
instance.addEventListener( "click", void clickEvent( event * e ) {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
} );
|
||||
|
||||
*/
|
||||
|
||||
|
||||
|
||||
//instance.background = new vector2( 100, 200 );
|
||||
|
||||
//instance.background = new vector3( 100, 200, 300 );
|
||||
|
||||
// instance.background = new vector4( 100, 200, 300, 400 );
|
||||
|
||||
//instance.background = "something/something.png";
|
||||
|
||||
elements->add( instance );
|
||||
|
||||
|
||||
|
||||
{
|
||||
|
||||
element instance = new element();
|
||||
|
||||
instance.position = new vector3( 20, 0, 1300 );
|
||||
|
||||
instance.size = new vector2( 40., 40. );
|
||||
|
||||
instance.background = "7.png";
|
||||
|
||||
instance.opacity = 1;
|
||||
|
||||
elements->add( instance );
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int count = elements->length();
|
||||
|
||||
for (int i = 0; i < count; ++i)
|
||||
{
|
||||
|
||||
element currentElement = elements->get( i );
|
||||
|
||||
quadMesh meshInstance = new quadMesh();
|
||||
|
||||
|
||||
meshInstance.elementIndex = i;
|
||||
|
||||
meshInstance.position = new vector2( 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 ) {
|
||||
|
||||
|
||||
//int featureValue = currentElement->getFeatureValueByFeatureName("useBackgroundImage");
|
||||
|
||||
|
||||
meshInstance.textureIndex = this->samplerArray->getTextureIndex();
|
||||
|
||||
printf("use background image. %s \n", currentElement.backgroundImagePath );
|
||||
|
||||
this->samplerArray->addTexture( resources->loadPngImage( 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 = currentElement.updateFeature();
|
||||
|
||||
meshInstance.opacity = currentElement.opacity;
|
||||
|
||||
//printf("value: %i\n", value);
|
||||
|
||||
|
||||
currentElement.setOriginal();
|
||||
|
||||
elements->set( i, currentElement );
|
||||
|
||||
|
||||
meshes->add( meshInstance );
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
this->sortOpacity( meshes );
|
||||
|
||||
|
||||
|
||||
}
|
||||
/*
|
||||
|
||||
|
||||
{
|
||||
quadMesh meshInstance = new quadMesh();
|
||||
|
||||
meshInstance.position = new vector2( 0. , 0. );
|
||||
|
||||
meshInstance.size = new vector2( 50. , 50. );
|
||||
|
||||
meshInstance.color = new vector3( 0.0, 1.0, 1.0 );
|
||||
|
||||
|
||||
meshes->add( meshInstance );
|
||||
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
quadMesh meshInstance = new quadMesh();
|
||||
|
||||
meshInstance.position = new vector2( 50. , 50. );
|
||||
|
||||
meshInstance.size = new vector2( 100. , 100. );
|
||||
|
||||
meshInstance.color = new vector3( 0.0, 0.0, 1.0 );
|
||||
|
||||
|
||||
meshes->add( meshInstance );
|
||||
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
quadMesh meshInstance = new quadMesh();
|
||||
|
||||
meshInstance.position = new vector2( 150. , 150. );
|
||||
|
||||
meshInstance.size = new vector2( 50. , 50. );
|
||||
|
||||
meshInstance.color = new vector3( 1.0, 0.0, 1.0 );
|
||||
|
||||
|
||||
meshes->add( meshInstance );
|
||||
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
block * meshesBlock = this->program->getBlock( "meshes" );
|
||||
|
||||
meshesBlock->setData( ( float * ) meshes->items );
|
||||
|
||||
}
|
||||
|
||||
|
||||
quadMesh updateMesh( quadMesh currentMesh, element currentElement ) {
|
||||
|
||||
vector2 position = new vector2( 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 callElementEvents( event * currentEvent, element * currentElement, int elementIndex ) {
|
||||
|
||||
vector<char *> * mouseEvents = currentEvent->mouse->eventTypes;
|
||||
|
||||
int mouseEventCount = mouseEvents->length();
|
||||
|
||||
for (int k = 0; k < mouseEventCount; ++k)
|
||||
{
|
||||
char * mouseEventCode = mouseEvents->get( k );
|
||||
|
||||
printf(" mouse event: %s\n", mouseEventCode);
|
||||
|
||||
|
||||
if( mouseEventCode == "click" ) {
|
||||
|
||||
currentElement->click();
|
||||
|
||||
//printf("trigger click event\n\n");
|
||||
|
||||
}
|
||||
|
||||
if( mouseEventCode == "mousedown" ) {
|
||||
|
||||
currentElement->mousedown();
|
||||
|
||||
//printf("trigger mousedown event\n\n");
|
||||
|
||||
}
|
||||
|
||||
|
||||
if( mouseEventCode == "mouseup" ) {
|
||||
|
||||
currentElement->mouseup();
|
||||
|
||||
//printf("trigger mouseup event\n\n");
|
||||
|
||||
}
|
||||
|
||||
if( mouseEventCode == "mousemove" ) {
|
||||
|
||||
if( !this->integerContains( this->mouseOverElements, elementIndex ) ) {
|
||||
|
||||
currentElement->mouseover();
|
||||
|
||||
this->mouseOverElements->add( elementIndex );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool integerContains( vector<int> * numbers, int a ) {
|
||||
|
||||
int count = numbers->length();
|
||||
|
||||
for (int j = 0; j < count; ++j)
|
||||
{
|
||||
|
||||
int b = numbers->get( j );
|
||||
|
||||
if( a == b ) {
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
render() {
|
||||
|
||||
program * currentProgram = this->program;
|
||||
|
||||
event * currentEvent = globalEvent;
|
||||
|
||||
|
||||
block * eventsBlock = currentProgram->getBlock( "events" );
|
||||
|
||||
//block * orientationBlock = currentProgram->getBlock( "orientation" );
|
||||
|
||||
|
||||
block * meshesBlock = currentProgram->getBlock( "meshes" );
|
||||
|
||||
|
||||
eventsBlock->autoUpload = true;
|
||||
|
||||
eventsBlock->setMember( "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 = meshes->length();
|
||||
|
||||
for (int i = 0; i < count; ++i)
|
||||
{
|
||||
quadMesh currentMesh = meshes->get( 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 = elements->get( elementIndex );
|
||||
|
||||
this->callElementEvents( currentEvent, ¤tElement, elementIndex );
|
||||
|
||||
currentMesh = this->updateMesh( currentMesh, currentElement );
|
||||
|
||||
elements->set( elementIndex, currentElement );
|
||||
|
||||
meshesBlock->setMemberArrayRow( "meshArray[0].color", i, ( float * ) & currentMesh );
|
||||
|
||||
} else {
|
||||
|
||||
if( this->integerContains( this->mouseOverElements, elementIndex ) ) {
|
||||
|
||||
printf("mouseout\n\n");
|
||||
|
||||
this->mouseOverElements->delete( elementIndex );
|
||||
|
||||
element currentElement = elements->get( elementIndex );
|
||||
|
||||
|
||||
currentElement->mouseleave();
|
||||
|
||||
|
||||
|
||||
currentMesh = this->updateMesh( currentMesh, currentElement );
|
||||
|
||||
elements->set( elementIndex, currentElement );
|
||||
|
||||
meshesBlock->setMemberArrayRow( "meshArray[0].color", i, ( float * ) & currentMesh );
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
//eventsBlock->setMember( "mouse", currentEvent->mouse->position );
|
||||
|
||||
|
||||
//vector2 * position = new vector2( 0.0, 0.0 );
|
||||
|
||||
//orientationBlock->setMember( "quadPosition", position );
|
||||
|
||||
// meshesBlock->upload();
|
||||
|
||||
|
||||
vector2 * position2 = new vector2( 0.4, 0 );
|
||||
|
||||
//meshesBlock->upload();
|
||||
|
||||
|
||||
|
||||
this->program->setUniform( "samplerArray", this->samplerArray );
|
||||
|
||||
glUseProgram( currentProgram->glProgram );
|
||||
|
||||
int numItems = 200;
|
||||
|
||||
|
||||
|
||||
/* Depth buffer setup */
|
||||
//glClearDepth(1.0f);
|
||||
|
||||
/* Enables Depth Testing */
|
||||
//glDisable(GL_CULL_FACE);
|
||||
|
||||
//glClear(GL_DEPTH_BUFFER_BIT)
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
|
||||
|
||||
|
||||
//glDepthMask(GL_TRUE);
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
//glDepthMask(GL_FALSE);
|
||||
|
||||
|
||||
glDepthRange(0.0, 1.0);
|
||||
|
||||
glDepthFunc(GL_ALWAYS);
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
|
||||
glEnable(GL_CULL_FACE);
|
||||
|
||||
/* The Type Of Depth Test To Do */
|
||||
//glDepthFunc( GL_LEQUAL );
|
||||
|
||||
|
||||
glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST );
|
||||
|
||||
|
||||
|
||||
glBindVertexArray( this->mesh->vertexArrayObject );
|
||||
|
||||
glDrawElements( GL_TRIANGLES, numItems, GL_UNSIGNED_INT, ( void * ) 0 );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
118
application/source/engine/renderPasses/renderPassTesselation.c
Normal file
118
application/source/engine/renderPasses/renderPassTesselation.c
Normal file
@@ -0,0 +1,118 @@
|
||||
|
||||
|
||||
#include "renderPass.h"
|
||||
|
||||
#include "../event.h"
|
||||
|
||||
#include "../vector2.h"
|
||||
|
||||
#include "../shader.h"
|
||||
|
||||
#include "int.h"
|
||||
|
||||
#include "../fontRenderer.h"
|
||||
|
||||
#include "../program.h"
|
||||
|
||||
#include "../mesh.h"
|
||||
|
||||
class tesselation extends renderPass{
|
||||
|
||||
|
||||
struct program * program;
|
||||
|
||||
struct mesh * mesh;
|
||||
|
||||
fontRenderer * font = new fontRenderer();
|
||||
|
||||
sampler2D * samplerArray;
|
||||
|
||||
char * textFromNumber( int i) {
|
||||
|
||||
char * fileName = malloc( sizeof( char ) * 100 );
|
||||
|
||||
sprintf( fileName, "%d", i );
|
||||
|
||||
return fileName;
|
||||
|
||||
}
|
||||
|
||||
prepare() {
|
||||
|
||||
shader * vertexShader = new shader( GL_VERTEX_SHADER );
|
||||
|
||||
vertexShader->loadFromFile( "assets/shaders/quadScale.vertex" );
|
||||
|
||||
|
||||
shader * fragmentShader = new shader( GL_FRAGMENT_SHADER );
|
||||
|
||||
fragmentShader->loadFromFile( "assets/shaders/color.fragment" );
|
||||
|
||||
|
||||
shader * geometryShader = new shader( GL_GEOMETRY_SHADER );
|
||||
|
||||
geometryShader->loadFromFile( "assets/shaders/tesselation.geometry.shader" );
|
||||
|
||||
|
||||
shader * tesselationControlShader = new shader( GL_TESS_CONTROL_SHADER );
|
||||
|
||||
tesselationControlShader->loadFromFile( "assets/shaders/tesselation.triangle.tsc.shader" );
|
||||
|
||||
|
||||
shader * tesselationEvaluationShader = new shader( GL_TESS_EVALUATION_SHADER );
|
||||
|
||||
tesselationEvaluationShader->loadFromFile( "assets/shaders/tesselation.triangle.shader" );
|
||||
|
||||
|
||||
|
||||
this->program = new program();
|
||||
|
||||
this->program->addShader( vertexShader );
|
||||
|
||||
this->program->addShader( fragmentShader );/*
|
||||
|
||||
this->program->addShader( geometryShader );
|
||||
|
||||
this->program->addShader( tesselationControlShader );
|
||||
|
||||
this->program->addShader( tesselationEvaluationShader );*/
|
||||
|
||||
|
||||
|
||||
this->program->create();
|
||||
|
||||
|
||||
|
||||
|
||||
this->mesh = new mesh();
|
||||
|
||||
this->mesh->setProgram( this->program );
|
||||
|
||||
this->mesh->createBuffers();
|
||||
|
||||
|
||||
glUseProgram( this->program->glProgram );
|
||||
|
||||
|
||||
}
|
||||
|
||||
render() {
|
||||
|
||||
glUseProgram( this->program->glProgram );
|
||||
|
||||
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
|
||||
|
||||
int numItems = 12;
|
||||
|
||||
//this->program->setUniform( "samplerArray", this->samplerArray );
|
||||
|
||||
glBindVertexArray( this->mesh->vertexArrayObject );
|
||||
|
||||
|
||||
|
||||
|
||||
glDrawElements( GL_LINE_STRIP, numItems, GL_UNSIGNED_INT, ( void * ) 0 );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
112
application/source/engine/resourceManager.c
Normal file
112
application/source/engine/resourceManager.c
Normal file
@@ -0,0 +1,112 @@
|
||||
|
||||
|
||||
#include "texture2D.h"
|
||||
|
||||
#include <png.h>
|
||||
|
||||
#include "stdbool.h"
|
||||
|
||||
#include "string.h"
|
||||
|
||||
class resourceManager{
|
||||
|
||||
texture2D * loadPngImage( char * name ) {
|
||||
|
||||
texture2D * texture = new texture2D();
|
||||
|
||||
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++) {
|
||||
|
||||
// note that png is ordered top to
|
||||
// bottom, but OpenGL expect it bottom to top
|
||||
// so the order or swapped
|
||||
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
208
application/source/engine/sampler2D.c
Normal file
208
application/source/engine/sampler2D.c
Normal file
@@ -0,0 +1,208 @@
|
||||
|
||||
#define GL_GLEXT_PROTOTYPES
|
||||
|
||||
#include <GL/glext.h>
|
||||
|
||||
#include <GL/gl.h> // GL 1.1 functions
|
||||
|
||||
#include <GL/glx.h>
|
||||
|
||||
#include "./texture2D.h"
|
||||
|
||||
#include "stdbool.h"
|
||||
|
||||
#include "../array.h"
|
||||
|
||||
#include "../vector3.h"
|
||||
|
||||
class sampler2D{
|
||||
|
||||
texture2D * texture;
|
||||
|
||||
array * textures = new array();
|
||||
|
||||
|
||||
GLuint glTexture;
|
||||
|
||||
|
||||
GLint binded = false;
|
||||
|
||||
|
||||
GLint filter = GL_LINEAR;
|
||||
|
||||
|
||||
GLint MIN_FILTER = GL_LINEAR;
|
||||
|
||||
GLint MAG_FILTER = GL_LINEAR;
|
||||
|
||||
GLint WRAP_S = GL_REPEAT;
|
||||
|
||||
GLint WRAP_T = GL_REPEAT;
|
||||
|
||||
|
||||
GLint datatype = GL_RGBA;
|
||||
|
||||
GLint format = GL_RGBA;
|
||||
|
||||
GLint internalFormat = GL_RGBA;
|
||||
|
||||
|
||||
GLint target = GL_TEXTURE_2D;
|
||||
|
||||
GLint type = GL_UNSIGNED_BYTE;//gl.FLOAT;
|
||||
|
||||
|
||||
vector3 * cubeSize = NULL;
|
||||
|
||||
|
||||
GLint border = false;
|
||||
|
||||
GLint generateMipmap = true;
|
||||
|
||||
bool UNPACK_ALIGNMENT = false;
|
||||
|
||||
//GLint FLIP_Y = true; pixelStorei
|
||||
|
||||
GLuint index = 0;
|
||||
|
||||
constructor() {
|
||||
|
||||
glGenTextures( 1, &this->glTexture );
|
||||
|
||||
}
|
||||
|
||||
addTexture( texture2D * texture ) {
|
||||
|
||||
this->textures->add( texture );
|
||||
|
||||
}
|
||||
|
||||
int getTextureIndex() {
|
||||
|
||||
int numberOfTextures = this->textures->length();
|
||||
|
||||
return numberOfTextures;
|
||||
|
||||
}
|
||||
|
||||
bind() {
|
||||
|
||||
this->binded = true;
|
||||
/*
|
||||
texture2D * texture = this->texture;
|
||||
|
||||
if( texture == NULL ) {
|
||||
|
||||
printf("Error: Texture not loaded.\n\n");
|
||||
|
||||
return ;
|
||||
|
||||
}
|
||||
*/
|
||||
//printf("Created sampler with id #%i\n", this->index);
|
||||
|
||||
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 ) {
|
||||
|
||||
//printf("create 2d array texture");
|
||||
|
||||
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 = this->textures->get( 0 );
|
||||
|
||||
int numberOfTextures = this->textures->length();
|
||||
|
||||
|
||||
if( this->cubeSize == NULL ) {
|
||||
|
||||
this->cubeSize = new vector3( texture1->width, texture1->height, numberOfTextures );
|
||||
|
||||
}
|
||||
|
||||
//glTexSubImage3D( this->target, levelOfDetail, offsetX, offsetY, offsetZ, texture->width, texture->height, depth, this->format, this->type, texture->data );
|
||||
|
||||
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 = this->textures->get( i );
|
||||
|
||||
float test = 0;//this->cubeSize->y - currentTexture->height - 1;
|
||||
|
||||
glTexSubImage3D( this->target,
|
||||
0,
|
||||
offsetX, test , i,
|
||||
currentTexture->width, currentTexture->height, 1,
|
||||
this->format,
|
||||
this->type,
|
||||
currentTexture->data );
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
texture2D * texture = this->textures->get( 0 );
|
||||
|
||||
glTexImage2D( this->target, 0, this->internalFormat, texture->width, texture->height, this->border, this->format, this->type, texture->data ); //GL_FLOAT
|
||||
|
||||
}
|
||||
|
||||
|
||||
if( this->generateMipmap ) {
|
||||
|
||||
glGenerateMipmap( this->target );
|
||||
|
||||
}
|
||||
|
||||
|
||||
//glBindTexture( this->target, NULL );
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
90
application/source/engine/shader.c
Normal file
90
application/source/engine/shader.c
Normal file
@@ -0,0 +1,90 @@
|
||||
|
||||
|
||||
#include "block.h"
|
||||
|
||||
#include "member.h"
|
||||
|
||||
#include "uniform.h"
|
||||
|
||||
|
||||
#define GL_GLEXT_PROTOTYPES
|
||||
|
||||
#include <GL/glext.h>
|
||||
|
||||
#include <GL/gl.h> // GL 1.1 functions
|
||||
|
||||
#include <GL/glx.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "../fileSystem.h"
|
||||
|
||||
#include "../array.h"
|
||||
|
||||
#include "../char.h"
|
||||
|
||||
#include "sampler2D.h"
|
||||
|
||||
|
||||
class attribute{
|
||||
|
||||
GLchar name[64];
|
||||
|
||||
GLint location;
|
||||
|
||||
GLenum type;
|
||||
|
||||
}
|
||||
|
||||
class shader{
|
||||
|
||||
GLuint glShader;
|
||||
|
||||
constructor( GLuint shaderType ) {
|
||||
|
||||
this->glShader = glCreateShader( shaderType );
|
||||
|
||||
}
|
||||
|
||||
loadFromFile( char * shaderPath ) {
|
||||
|
||||
text * shaderSource = filesystem->readFile( shaderPath, "utf8" );
|
||||
|
||||
glShaderSource( this->glShader, 1, &shaderSource->value, NULL );
|
||||
|
||||
glCompileShader( this->glShader );
|
||||
|
||||
this->checkShaderForErrors( this->glShader );
|
||||
|
||||
}
|
||||
|
||||
checkShaderForErrors( 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;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
26
application/source/engine/texture2D.c
Normal file
26
application/source/engine/texture2D.c
Normal file
@@ -0,0 +1,26 @@
|
||||
|
||||
|
||||
#define GL_GLEXT_PROTOTYPES
|
||||
|
||||
#include <GL/glext.h>
|
||||
|
||||
#include <GL/gl.h> // GL 1.1 functions
|
||||
|
||||
#include <GL/glx.h>
|
||||
|
||||
#include "vector2.h"
|
||||
|
||||
|
||||
class texture2D{
|
||||
|
||||
GLubyte * data;
|
||||
|
||||
int width;
|
||||
|
||||
int height;
|
||||
|
||||
int hasAlpha;
|
||||
|
||||
vector2 * offset;
|
||||
|
||||
}
|
||||
27
application/source/engine/uniform.c
Normal file
27
application/source/engine/uniform.c
Normal file
@@ -0,0 +1,27 @@
|
||||
|
||||
|
||||
#define GL_GLEXT_PROTOTYPES
|
||||
|
||||
#include <GL/glext.h>
|
||||
|
||||
#include <GL/gl.h> // GL 1.1 functions
|
||||
|
||||
#include <GL/glx.h>
|
||||
|
||||
|
||||
|
||||
class uniform{
|
||||
|
||||
char name[64];
|
||||
|
||||
GLint index;
|
||||
|
||||
GLint location;
|
||||
|
||||
GLint offset;
|
||||
|
||||
GLint size;
|
||||
|
||||
GLenum type;
|
||||
|
||||
}
|
||||
167
application/source/engine/uniformBlock.c
Normal file
167
application/source/engine/uniformBlock.c
Normal file
@@ -0,0 +1,167 @@
|
||||
|
||||
|
||||
#include "block.h"
|
||||
|
||||
#include "member.h"
|
||||
|
||||
#include <uniform.h>
|
||||
|
||||
|
||||
|
||||
|
||||
#define GL_GLEXT_PROTOTYPES
|
||||
|
||||
#include <GL/glext.h>
|
||||
|
||||
#include <GL/gl.h> // GL 1.1 functions
|
||||
|
||||
#include <GL/glx.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "fileSystem.h"
|
||||
|
||||
#include "array.h"
|
||||
|
||||
#include "char.h"
|
||||
|
||||
#include "sampler2D.h"
|
||||
|
||||
|
||||
|
||||
class uniformBlock{
|
||||
|
||||
array * uniforms = new array();
|
||||
|
||||
GLint buffer;
|
||||
|
||||
GLuint index;
|
||||
|
||||
GLint size;
|
||||
|
||||
GLchar name[64];
|
||||
|
||||
GLuint bindingPoint;
|
||||
|
||||
float * data;
|
||||
|
||||
GLint autoUpload = 0;
|
||||
|
||||
createBuffer() {
|
||||
|
||||
unsigned int uniformBufferSize = this->size; // allocate 152 bytes of memory
|
||||
|
||||
printf("create GL_UNIFORM_BUFFER of size: %i index: %i \n", uniformBufferSize, this->index);
|
||||
|
||||
this->data = ( float * ) malloc( uniformBufferSize );
|
||||
|
||||
glGenBuffers( 1, &this->buffer );
|
||||
|
||||
glBindBuffer( GL_UNIFORM_BUFFER, this->buffer );
|
||||
|
||||
glBindBufferBase( GL_UNIFORM_BUFFER, this->index, this->buffer );
|
||||
|
||||
glBufferData( GL_UNIFORM_BUFFER, uniformBufferSize, 0, GL_DYNAMIC_DRAW );
|
||||
|
||||
//glBufferData( GL_UNIFORM_BUFFER, uniformBufferSize, NULL, GL_DYNAMIC_DRAW );
|
||||
|
||||
}
|
||||
|
||||
void upload() {
|
||||
|
||||
//printf("upload uniform buffer: %f %f %f %f\n", this->data[0], this->data[1], this->data[2], this->data[3]);
|
||||
|
||||
//printf("upload uniform buffer: %i\n", this->index);
|
||||
|
||||
glBindBuffer( GL_UNIFORM_BUFFER, this->buffer );
|
||||
|
||||
glBindBufferBase( GL_UNIFORM_BUFFER, this->bindingPoint, this->buffer );
|
||||
|
||||
glBufferData( GL_UNIFORM_BUFFER, this->size, this->data, GL_DYNAMIC_DRAW );
|
||||
|
||||
}
|
||||
|
||||
enableAutoUpload() {
|
||||
|
||||
this->autoUpload = 1;
|
||||
|
||||
}
|
||||
|
||||
void setUniform( char * name, void * value ) {
|
||||
|
||||
int uniformCount = this->uniforms->length();
|
||||
|
||||
//printf("uniformCount: %i\n\n", uniformCount);
|
||||
|
||||
for (int i = 0; i < uniformCount; ++i)
|
||||
{
|
||||
uniform * currentUniform = this->uniforms->get( i );
|
||||
|
||||
char * uniformName = (char *) currentUniform->name;
|
||||
|
||||
if( uniformName == name ) {
|
||||
|
||||
//printf("\n\n Update this uniform from uniform block %s\n\n", name);
|
||||
|
||||
switch( currentUniform->type ) {
|
||||
|
||||
case GL_FLOAT_VEC2:
|
||||
|
||||
vector2 * vector2Value = ( vector2 * ) value;
|
||||
|
||||
GLuint size = 8;
|
||||
|
||||
GLint offset = currentUniform->offset;
|
||||
|
||||
|
||||
if( this->autoUpload ) {
|
||||
|
||||
float data[2] = { vector2Value->x, vector2Value->y };
|
||||
|
||||
|
||||
glBindBuffer( GL_UNIFORM_BUFFER, this->buffer );
|
||||
|
||||
glBindBufferBase( GL_UNIFORM_BUFFER, 0, this->buffer );
|
||||
|
||||
// glBufferData( GL_UNIFORM_BUFFER, 16, data2, GL_DYNAMIC_DRAW );
|
||||
|
||||
glBufferSubData( GL_UNIFORM_BUFFER, offset, size, data );
|
||||
|
||||
//printf("using autoUpload %i %i %f %f\n", offset, size, data[0], data[1]);
|
||||
|
||||
} 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;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
156
application/source/engine/unsignedIntegerArray.c
Normal file
156
application/source/engine/unsignedIntegerArray.c
Normal file
@@ -0,0 +1,156 @@
|
||||
|
||||
#include <vector3.h>
|
||||
|
||||
#include <vector2.h>
|
||||
|
||||
|
||||
class unsignedIntegerArray{
|
||||
|
||||
int capacity = 10;
|
||||
|
||||
int total = 0;
|
||||
|
||||
unsigned int * items = malloc( 10000000 );
|
||||
|
||||
int length()
|
||||
{
|
||||
|
||||
return this->total;
|
||||
|
||||
}
|
||||
|
||||
unsigned int get( int index )
|
||||
{
|
||||
|
||||
return this->items[index];
|
||||
|
||||
}
|
||||
|
||||
void set( int index, unsigned int item )
|
||||
{
|
||||
|
||||
if ( index >= 0 && index < this->total ){
|
||||
|
||||
this->items[ index ] = item;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void resize( int capacity )
|
||||
{
|
||||
|
||||
int * items = realloc( this->items, sizeof( int ) * capacity );
|
||||
|
||||
|
||||
this->items = items;
|
||||
|
||||
this->capacity = capacity;
|
||||
|
||||
}
|
||||
|
||||
void addVector2( struct vector2 * item ) {
|
||||
|
||||
this->add( item->x );
|
||||
|
||||
this->add( item->y );
|
||||
|
||||
}
|
||||
|
||||
void addVector3( struct vector3 * item ) {
|
||||
|
||||
this->add( item->x );
|
||||
|
||||
this->add( item->y );
|
||||
|
||||
this->add( item->z );
|
||||
|
||||
}
|
||||
|
||||
void add( unsigned int item )
|
||||
{
|
||||
|
||||
if ( this->capacity == this->total ){
|
||||
|
||||
this->resize( this->capacity * 2 );
|
||||
|
||||
}
|
||||
|
||||
this->items[ this->total++ ] = item;
|
||||
|
||||
}
|
||||
|
||||
void delete( 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 ){
|
||||
|
||||
this->resize( this->capacity / 2 );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
unsigned int array_push( unsigned int item ) {
|
||||
|
||||
this->add( item );
|
||||
|
||||
return this->total;
|
||||
|
||||
}
|
||||
|
||||
void unshift( int item ) {
|
||||
|
||||
int length = this->total;
|
||||
|
||||
this->total++;
|
||||
|
||||
if ( this->capacity == this->total ){
|
||||
|
||||
this->resize( this->capacity * 2 );
|
||||
|
||||
}
|
||||
|
||||
for ( int i = length - 1; i >= 0; --i ) {
|
||||
|
||||
this->items[ i + 1 ] = this->items[ i ];
|
||||
|
||||
}
|
||||
|
||||
this->items[ 0 ] = item;
|
||||
|
||||
}
|
||||
|
||||
unsigned int pop() {
|
||||
|
||||
int length = this->total;
|
||||
|
||||
int lastIndex = length - 1;
|
||||
|
||||
int lastItem = this->get( lastIndex );
|
||||
|
||||
this->delete( lastIndex );
|
||||
|
||||
return lastItem;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
213
application/source/engine/vector.c
Normal file
213
application/source/engine/vector.c
Normal file
@@ -0,0 +1,213 @@
|
||||
|
||||
|
||||
|
||||
#include "element.h"
|
||||
|
||||
#include "quadMesh.h"
|
||||
|
||||
#include "../vector2.h"
|
||||
|
||||
#include "../int.h"
|
||||
|
||||
|
||||
template<T>
|
||||
class vector{
|
||||
|
||||
int capacity = 10;
|
||||
|
||||
int total = 0;
|
||||
|
||||
T * items = malloc( 10000000 );
|
||||
|
||||
int length()
|
||||
{
|
||||
|
||||
return this->total;
|
||||
|
||||
}
|
||||
|
||||
T get( int index )
|
||||
{
|
||||
|
||||
return this->items[index];
|
||||
|
||||
}
|
||||
|
||||
void set( int index, T item )
|
||||
{
|
||||
|
||||
if ( index >= 0 && index < this->total ){
|
||||
|
||||
this->items[ index ] = item;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void resize( int capacity )
|
||||
{
|
||||
|
||||
T * items = realloc( this->items, sizeof( T ) * capacity );
|
||||
|
||||
|
||||
this->items = items;
|
||||
|
||||
this->capacity = capacity;
|
||||
|
||||
}
|
||||
|
||||
void add( T item )
|
||||
{
|
||||
|
||||
if ( this->capacity == this->total ){
|
||||
|
||||
this->resize( this->capacity * 2 );
|
||||
|
||||
}
|
||||
|
||||
this->items[ this->total++ ] = item;
|
||||
|
||||
}
|
||||
|
||||
void delete( int index )
|
||||
{
|
||||
|
||||
//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;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
// bug preprocessor + operator on pointer of vector2 or vector3.
|
||||
//memmove( this->items + index, this->items + index + 1, ( ( this->total - index ) - 1) * ( sizeof( T ) ) );
|
||||
|
||||
|
||||
this->total--;
|
||||
|
||||
//if ( this->total > 0 && this->total == this->capacity / 4 ){
|
||||
|
||||
// this->resize( this->capacity / 2 );
|
||||
|
||||
//}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
int array_push( T item ) {
|
||||
|
||||
this->add( item );
|
||||
|
||||
return this->total;
|
||||
|
||||
}
|
||||
|
||||
void unshift( T item ) {
|
||||
|
||||
int length = this->total;
|
||||
|
||||
this->total++;
|
||||
|
||||
if ( this->capacity == this->total ){
|
||||
|
||||
this->resize( this->capacity * 2 );
|
||||
|
||||
}
|
||||
|
||||
for ( int i = length - 1; i >= 0; --i ) {
|
||||
|
||||
this->items[ i + 1 ] = this->items[ i ];
|
||||
|
||||
}
|
||||
|
||||
this->items[ 0 ] = item;
|
||||
|
||||
}
|
||||
/*
|
||||
bool includes() {
|
||||
|
||||
//#if TEMPLATE_1
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
T pop() {
|
||||
|
||||
int length = this->total;
|
||||
|
||||
int lastIndex = length - 1;
|
||||
|
||||
T lastItem = this->get( lastIndex );
|
||||
|
||||
this->delete( lastIndex );
|
||||
|
||||
return lastItem;
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
template<>
|
||||
class <char *>vector{
|
||||
|
||||
includes( char * value ) {
|
||||
|
||||
int count = this->items->length();
|
||||
|
||||
for (int i = 0; i < count; ++i)
|
||||
{
|
||||
|
||||
char * current = this->items->get( i );
|
||||
|
||||
if( current == value ) {
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
template<>
|
||||
class <int>vector{
|
||||
|
||||
bool includes( int value ) {
|
||||
|
||||
int count = this->items->length();
|
||||
|
||||
for (int i = 0; i < count; ++i)
|
||||
{
|
||||
|
||||
int current = this->items->get( i );
|
||||
|
||||
if( current == value ) {
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
*/
|
||||
56
application/source/engine/vector4.c
Normal file
56
application/source/engine/vector4.c
Normal file
@@ -0,0 +1,56 @@
|
||||
|
||||
|
||||
|
||||
|
||||
class vector4{
|
||||
|
||||
float x;
|
||||
|
||||
float y;
|
||||
|
||||
float z;
|
||||
|
||||
float w;
|
||||
|
||||
|
||||
constructor( float x, float y, float z, float w ) {
|
||||
|
||||
this->x = x;
|
||||
|
||||
this->y = y;
|
||||
|
||||
this->z = z;
|
||||
|
||||
this->w = w;
|
||||
|
||||
}
|
||||
|
||||
vector4 * operator+( vector4 * b ) {
|
||||
|
||||
this->add( b );
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
vector4 * operator+=( vector4 * b ) {
|
||||
|
||||
this->add( b );
|
||||
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
void add( vector4 * b ) {
|
||||
|
||||
this->x += b->x;
|
||||
|
||||
this->y += b->y;
|
||||
|
||||
this->z += b->z;
|
||||
|
||||
this->w += b->w;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
164
application/source/engine/windowManager.c
Normal file
164
application/source/engine/windowManager.c
Normal file
@@ -0,0 +1,164 @@
|
||||
|
||||
|
||||
#include <X11/Xlib.h>
|
||||
|
||||
#include <X11/keysym.h>
|
||||
|
||||
#define GL_GLEXT_PROTOTYPES
|
||||
|
||||
#include <GL/glext.h>
|
||||
|
||||
#include <GL/gl.h> // GL 1.1 functions
|
||||
|
||||
#include <GL/glx.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <hints.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,
|
||||
};
|
||||
|
||||
|
||||
|
||||
class windowManager{
|
||||
|
||||
Display * mainDisplay;
|
||||
|
||||
Window mainWindow;
|
||||
|
||||
int MainScreen;
|
||||
|
||||
Window RootWindow;
|
||||
|
||||
|
||||
setupDisplay() {
|
||||
|
||||
this->mainDisplay = XOpenDisplay( 0 );
|
||||
|
||||
this->MainScreen = XDefaultScreen( this->mainDisplay );
|
||||
|
||||
}
|
||||
|
||||
setupWindow() {
|
||||
|
||||
|
||||
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;
|
||||
|
||||
|
||||
//XMatchVisualInfo( this->mainDisplay, this->MainScreen, 32, TrueColor, &VisualInfo);
|
||||
|
||||
|
||||
GLXContext OpenGLContext = glXCreateContext( this->mainDisplay, VisualInfo, ShareList, IsDirectRendering );
|
||||
|
||||
|
||||
|
||||
int WindowX = 0;
|
||||
|
||||
int WindowY = 0;
|
||||
|
||||
int WindowWidth = 1000;//;1920;
|
||||
|
||||
int WindowHeight = 1024;//;72;
|
||||
|
||||
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 = 0xffafe9af;
|
||||
|
||||
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, 0, 800 );
|
||||
|
||||
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 );
|
||||
|
||||
|
||||
//W = DisplayWidth(display, defaultScreen);
|
||||
//H = DisplayHeight(display, defaultScreen);
|
||||
|
||||
|
||||
/*
|
||||
|
||||
Remove borders
|
||||
|
||||
*/
|
||||
|
||||
/*
|
||||
|
||||
Atom window_type = XInternAtom( this->mainDisplay, "_MOTIF_WM_HINTS", True );
|
||||
|
||||
Hints hints;
|
||||
|
||||
Atom property;
|
||||
|
||||
hints.flags = 2;
|
||||
|
||||
hints.decorations = 0;
|
||||
|
||||
XChangeProperty( this->mainDisplay, this->mainWindow, window_type, window_type, 32, PropModeReplace, ( unsigned char * ) & hints, 5 );
|
||||
|
||||
|
||||
*/
|
||||
|
||||
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" );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user