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

SCM Repository

[diderot] Diff of /examples/iso2d-demo/main.c
ViewVC logotype

Diff of /examples/iso2d-demo/main.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1919, Thu Jun 7 22:43:16 2012 UTC revision 1920, Fri Jun 8 12:11:49 2012 UTC
# Line 18  Line 18 
18  #include "util.h"  #include "util.h"
19  #include "load-png.h"  #include "load-png.h"
20  #include "iso2d.h"  #include "iso2d.h"
21    #include <unistd.h>
22    
23  /* pixel dimensions of output */  /* pixel dimensions of output */
24  #define WIDTH   512  #define WIDTH   990
25  #define HEIGHT  512  #define HEIGHT  990
26    
27    /* world bounds */
28    #define WRLD_MIN_X      0.0
29    #define WRLD_MIN_Y      0.0
30    #define WRLD_MAX_X      1.0
31    #define WRLD_MAX_Y      1.0
32    #define WRLD_CENTER_X   0.5
33    #define WRLD_CENTER_Y   0.5
34    
35  #define STEP_SIZE       1  #define STEP_SIZE       1
36    #define SLEEP_MS        250
37    
38  static inline void CheckError ()  static inline void CheckError ()
39  {  {
# Line 53  Line 63 
63      glClearColor (0, 0, 0, 1);      glClearColor (0, 0, 0, 1);
64      glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);      glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
65    
66      glEnable(GL_DEPTH_TEST);      glDisable(GL_DEPTH_TEST);
67      glDisable(GL_CULL_FACE);      glDisable(GL_CULL_FACE);
68    
69    // Draw background    // Draw background
     float       halfWid = 0.5 * (float)Width;  
     float       halfHt = 0.5 * (float)Height;  
70      glEnable (GL_TEXTURE_2D);      glEnable (GL_TEXTURE_2D);
71      glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);      glActiveTexture (GL_TEXTURE0);
72      glBindTexture (GL_TEXTURE_2D, ImageTexture);      glBindTexture (GL_TEXTURE_2D, ImageTexture);
73        glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
74      glBegin (GL_QUADS);      glBegin (GL_QUADS);
75          glColor3f (0.1, 0.1, 0.1);          glColor3f (0.1, 0.1, 0.1);
76          glTexCoord2f (0.0, 0.0);          glTexCoord2f (0.0, 0.0);
77          glVertex2f (-halfWid, -halfHt);          glVertex2f (WRLD_MIN_X, WRLD_MIN_Y);
78          glTexCoord2f (1.0, 0.0);          glTexCoord2f (1.0, 0.0);
79          glVertex2f (halfWid, -halfHt);          glVertex2f (WRLD_MAX_X, WRLD_MIN_Y);
80          glTexCoord2f (1.0, 1.0);          glTexCoord2f (1.0, 1.0);
81          glVertex2f (halfWid, halfHt);          glVertex2f (WRLD_MAX_X, WRLD_MAX_Y);
82          glTexCoord2f (0.0, 1.0);          glTexCoord2f (0.0, 1.0);
83          glVertex2f (-halfWid, halfHt);          glVertex2f (WRLD_MIN_X, WRLD_MAX_Y);
84      glEnd();      glEnd();
85      glDisable (GL_TEXTURE_2D);      glDisable (GL_TEXTURE_2D);
86      CheckError ();      CheckError ();
87    
88    // Draw current render state    // Draw current particle state
89        glEnable (GL_POINT_SMOOTH);
90    //    glPointSize (2.0);
91    // it would be more efficient to do this as a single buffer, but it is fast enough
92        float *p = (float *)(positions->data);
93        unsigned int nPoints = positions->axis[1].size;
94        glBegin (GL_POINTS);
95          // first draw some points at known locations for testing purposes
96    //      glColor3f (1.0, 0.0, 0.0);
97    //      glVertex2f (WRLD_MIN_X, WRLD_MIN_Y);
98    //      glVertex2f (WRLD_MAX_X, WRLD_MIN_Y);
99    //      glVertex2f (WRLD_MAX_X, WRLD_MAX_Y);
100    //      glVertex2f (WRLD_MIN_X, WRLD_MAX_Y);
101            glColor3f (0.2, 1.0, 0.2);
102            for (int i = 0;  i < nPoints;  i++) {
103                glVertex2fv(p);
104                p += 2;
105            }
106        glEnd ();
107    
108    // Draw tweak bars    // Draw tweak bars
109      TwDraw();      TwDraw();
# Line 88  Line 115 
115  // Callback function called by GLFW when window size changes  // Callback function called by GLFW when window size changes
116  void GLFWCALL WindowSizeCB (int width, int height)  void GLFWCALL WindowSizeCB (int width, int height)
117  {  {
118      double      halfWid = 0.5 * (double)width;  printf("window size = %d x %d\n", width, height);
     double      halfHt = 0.5 * (double)height;  
   
119    // Set OpenGL viewport and camera    // Set OpenGL viewport and camera
120      glViewport(0, 0, width, height);      glViewport(0, 0, width, height);
121    
122      glMatrixMode(GL_PROJECTION);      glMatrixMode(GL_PROJECTION);
123      glLoadIdentity();      glLoadIdentity();
124      gluOrtho2D (-halfWid, halfWid, -halfHt, halfHt);      double pad = 0.05*(WRLD_MAX_X - WRLD_MIN_X);  // add 10% to world dimensions
125        gluOrtho2D (
126            WRLD_MIN_X - pad, WRLD_MAX_X + pad,
127            WRLD_MAX_Y + pad, WRLD_MIN_Y - pad);
128    
129      glMatrixMode (GL_MODELVIEW);      glMatrixMode (GL_MODELVIEW);
130      glLoadIdentity ();      glLoadIdentity ();
131      gluLookAt (      gluLookAt (
132    //      WRLD_CENTER_X, WRLD_CENTER_Y, 1.0,
133          0.0, 0.0, 1.0,          0.0, 0.0, 1.0,
134    //      WRLD_CENTER_X, WRLD_CENTER_Y, 0.0,
135          0.0, 0.0, 0.0,          0.0, 0.0, 0.0,
136          0.0, 1.0, 0.0);          0.0, 1.0, 0.0);
137    
# Line 116  Line 147 
147  // initialize a texture from a grayscale Nrrd file  // initialize a texture from a grayscale Nrrd file
148  void InitTexture ()  void InitTexture ()
149  {  {
150      Image2D_t *img = LoadImage ("data/ddro-tx.png", false, GRAY_IMAGE);      Image2D_t *img = LoadImage ("data/ddro-tx.png", true, GRAY_IMAGE);
151      if (img == 0) {      if (img == 0) {
152          fprintf (stderr, "unable to load texture file\n");          fprintf (stderr, "unable to load texture file\n");
153          exit (1);          exit (1);
# Line 133  Line 164 
164          fprintf(stderr, "error loading texture\n");          fprintf(stderr, "error loading texture\n");
165          exit (1);          exit (1);
166      }      }
167        glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
168        glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
169    
170      FreeImage (img);      FreeImage (img);
171    
# Line 224  Line 257 
257              while ((state.running != 0) && (ISO_NumActive(wrld) > 0)) {              while ((state.running != 0) && (ISO_NumActive(wrld) > 0)) {
258                // step the computation                // step the computation
259                  NumSteps += ISO_Run (wrld, STEP_SIZE);                  NumSteps += ISO_Run (wrld, STEP_SIZE);
 printf("%d steps, %d active\n", NumSteps, ISO_NumActive(wrld));  
260                // get and render the state                // get and render the state
261                  GetData (wrld, nData);                  GetData (wrld, nData);
262                  Draw (nData);                  Draw (nData);
263                    usleep (SLEEP_MS * 1000);  // sleep for a bit
264              }              }
265              if (ISO_NumActive(wrld) == 0) {              if (ISO_NumActive(wrld) == 0) {
266                // get and render final state                // get and render final state

Legend:
Removed from v.1919  
changed lines
  Added in v.1920

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