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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2950 - (view) (download) (as text)

1 : lamonts 2950 #include "view.h"
2 :     #include "utils/utils.h"
3 :     #include "utils/circle.h"
4 :     #include <math.h>
5 :    
6 :     static void view_getLocations(View * view);
7 :    
8 :     GLint posLoc; //!< the vertex attribute location for the position
9 :     GLint colorLoc; //!< the vertex attribute location for the color
10 :     GLint modelLoc;
11 :     GLint projecLoc;
12 :     GLint cBoidLoc; //!< the vertex attribute location for the color
13 :    
14 :     View * view_createView(int32_t width, int32_t height){
15 :    
16 :     View * view = NULL;
17 :    
18 :     if((view = malloc(sizeof(View))) == NULL){
19 :     fprintf(stderr, "Could not allocate view\n");
20 :     exit(EXIT_FAILURE);
21 :     }
22 :     view->width = width;
23 :     view->height = height;
24 :    
25 :     return view;
26 :     }
27 :     /* Initiliazes the view */
28 :     bool view_init(View * view,const char * vFile, const char * fFile){
29 :    
30 :     /* Load shader file */
31 :     view->vshId = utils_loadShadersFromFile(GL_VERTEX_SHADER, vFile);
32 :     view->fshId = utils_loadShadersFromFile(GL_FRAGMENT_SHADER, fFile);
33 :    
34 :     /* Create GL program */
35 :     view->progId = utils_createGLProgram(view->vshId, view->fshId);
36 :    
37 :     mat4x4_identity(view->projection);
38 :    
39 :     // mat4x4_ortho(view->projection, -view->width/2.0f, view->width/2.0f, -view->height/2.0f, view->height/2.0f, -1.0, 1.0f);
40 :     double pad = 0.05*(WRLD_MAX_X - WRLD_MIN_X); // add 10% to world dimensions
41 :     mat4x4_ortho(view->projection, WRLD_MIN_X - pad, WRLD_MAX_X + pad, WRLD_MAX_Y + pad, WRLD_MIN_Y - pad, -1.0, 1.0f);
42 :    
43 :     view_getLocations(view);
44 :    
45 :    
46 :     return true;
47 :     }
48 :     static void view_getLocations(View * view) {
49 :    
50 :     if((posLoc = glGetAttribLocation (view->progId, "pos")) < 0){
51 :     fprintf(stderr,"Coult not get attribute location for pos\n\n");
52 :     exit(EXIT_FAILURE);
53 :     }
54 :     if((modelLoc = glGetAttribLocation (view->progId, "model")) < 0){
55 :     fprintf(stderr,"Coult not get attribute location for model\n\n");
56 :     exit(EXIT_FAILURE);
57 :     }
58 :     if((projecLoc = glGetUniformLocation (view->progId, "projection")) < 0){
59 :     fprintf(stderr,"Coult not get uniform location for projection\n\n");
60 :     exit(EXIT_FAILURE);
61 :     }
62 :     if((cBoidLoc = glGetAttribLocation (view->progId, "color")) < 0){
63 :     fprintf(stderr,"Coult not get uniform location for boid color\n");
64 :     exit(EXIT_FAILURE);
65 :     }
66 :     }
67 :     void view_render(Circle * boids, View * view){
68 :    
69 :     //Declare a black color
70 :     const GLfloat color[] = { 0.0f, 0.0f , 0.0f, 1.0f};
71 :    
72 :     // Clear the screen
73 :     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
74 :    
75 :     // Set the background to black
76 :     glClearBufferfv(GL_COLOR,0,color);
77 :    
78 :     glEnable(GL_DEPTH_TEST);
79 :    
80 :     //Start the shader program
81 :     glUseProgram (view->progId);
82 :    
83 :     //Pass in the modelView and projection matrices
84 :     GL_CHECK(glUniformMatrix4fv (projecLoc, 1, GL_FALSE, &(view->projection[0][0])));
85 :    
86 :     //render mesh
87 :     circle_render(boids, posLoc, cBoidLoc, modelLoc);
88 :    
89 :     }

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