Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] View of /examples/iso2d-spatial/view.c
ViewVC logotype

View of /examples/iso2d-spatial/view.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2950 - (download) (as text) (annotate)
Wed Mar 4 20:52:35 2015 UTC (4 years, 7 months ago) by lamonts
File size: 2689 byte(s)
Adding the iso2d demo with particle interaction
#include "view.h"
#include "utils/utils.h"
#include "utils/circle.h"
#include <math.h>

static void view_getLocations(View * view); 

GLint		posLoc;		//!< the vertex attribute location for the position 
GLint		colorLoc;	//!< the vertex attribute location for the color  	
GLint 		modelLoc; 
GLint 		projecLoc; 
GLint		cBoidLoc;	//!< the vertex attribute location for the color  	

View * view_createView(int32_t width, int32_t height){

	View * view = NULL; 

	if((view = malloc(sizeof(View))) == NULL){
		fprintf(stderr, "Could not allocate view\n"); 
		exit(EXIT_FAILURE); 
	}
	view->width = width; 
	view->height = height; 

	return view; 
}
/* Initiliazes the view */ 
bool view_init(View * view,const char * vFile, const char * fFile){

	/* Load shader file */ 
	view->vshId = utils_loadShadersFromFile(GL_VERTEX_SHADER, vFile);
	view->fshId = utils_loadShadersFromFile(GL_FRAGMENT_SHADER, fFile);

	/* Create GL program */
	view->progId = utils_createGLProgram(view->vshId, view->fshId);  

	mat4x4_identity(view->projection); 

	// mat4x4_ortho(view->projection, -view->width/2.0f, view->width/2.0f, -view->height/2.0f, view->height/2.0f, -1.0, 1.0f); 
    double pad = 0.05*(WRLD_MAX_X - WRLD_MIN_X);  // add 10% to world dimensions
	 mat4x4_ortho(view->projection, WRLD_MIN_X - pad, WRLD_MAX_X + pad, WRLD_MAX_Y + pad, WRLD_MIN_Y - pad, -1.0, 1.0f); 

	view_getLocations(view); 


	return true; 
}
static void view_getLocations(View * view) {

	if((posLoc = glGetAttribLocation (view->progId, "pos")) < 0){
		fprintf(stderr,"Coult not get attribute location for pos\n\n"); 
		exit(EXIT_FAILURE); 
	}
	if((modelLoc = glGetAttribLocation (view->progId, "model")) < 0){
		fprintf(stderr,"Coult not get attribute location for model\n\n"); 
		exit(EXIT_FAILURE); 
	} 
	if((projecLoc = glGetUniformLocation (view->progId, "projection")) < 0){
		fprintf(stderr,"Coult not get uniform location for projection\n\n"); 
		exit(EXIT_FAILURE); 
	} 
	if((cBoidLoc = glGetAttribLocation (view->progId, "color")) < 0){
		fprintf(stderr,"Coult not get uniform location for boid color\n"); 
		exit(EXIT_FAILURE); 
	} 
}
void view_render(Circle * boids, View * view){

	//Declare a black color 
	const GLfloat color[] = { 0.0f, 0.0f , 0.0f, 1.0f}; 

	// Clear the screen
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    // Set the background to black 
	glClearBufferfv(GL_COLOR,0,color); 

    glEnable(GL_DEPTH_TEST);

    //Start the shader program 
    glUseProgram (view->progId);

	//Pass in the modelView and projection matrices 
	GL_CHECK(glUniformMatrix4fv (projecLoc, 1, GL_FALSE, &(view->projection[0][0]))); 

	//render mesh 
	circle_render(boids, posLoc, cBoidLoc, modelLoc);

}

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0