invisible
annotate src/tesquad.cc @ 25:96b022f1210e
'w' to switch to wireframe
author | Eleni Maria Stea <eleni@mutantstargoat.com> |
---|---|
date | Sun, 17 Nov 2013 12:46:45 +0200 |
parents | f756fc9fdd3e |
children |
rev | line source |
---|---|
eleni@19 | 1 #include <GL/gl.h> |
eleni@19 | 2 #include "tesquad.h" |
eleni@19 | 3 |
eleni@19 | 4 void draw_tess_quad(float x, float y, float w, float h, int usub, int vsub, bool ortho) |
eleni@19 | 5 { |
eleni@23 | 6 glPushAttrib(GL_ENABLE_BIT); |
eleni@23 | 7 glDisable(GL_DEPTH_TEST); |
eleni@23 | 8 glDisable(GL_LIGHTING); |
eleni@23 | 9 |
eleni@19 | 10 if(ortho) { |
eleni@19 | 11 glMatrixMode(GL_PROJECTION); |
eleni@19 | 12 glPushMatrix(); |
eleni@19 | 13 glLoadIdentity(); |
eleni@19 | 14 } |
eleni@19 | 15 |
eleni@19 | 16 float du = 1.0 / usub; |
eleni@19 | 17 float dv = 1.0 / vsub; |
eleni@19 | 18 |
eleni@19 | 19 float dx = du * w; |
eleni@19 | 20 float dy = dv * h; |
eleni@19 | 21 |
eleni@19 | 22 glBegin(GL_QUADS); |
eleni@19 | 23 for (int i=0; i<vsub; i++) { |
eleni@19 | 24 for (int j=0; j<usub; j++) { |
eleni@19 | 25 float u = j * du; |
eleni@19 | 26 float v = 1.0 - i * dv; |
eleni@19 | 27 float sx = x + j * dx; |
eleni@19 | 28 float sy = y + i * dy; |
eleni@19 | 29 |
eleni@19 | 30 glTexCoord2f(u, v); |
eleni@19 | 31 glVertex2f(sx, sy); |
eleni@19 | 32 glTexCoord2f(u + du, v); |
eleni@19 | 33 glVertex2f(sx + dx, sy); |
eleni@19 | 34 glTexCoord2f(u + du, v - dv); |
eleni@19 | 35 glVertex2f(sx + dx, sy + dy); |
eleni@19 | 36 glTexCoord2f(u, v - dv); |
eleni@19 | 37 glVertex2f(sx, sy + dy); |
eleni@19 | 38 } |
eleni@19 | 39 } |
eleni@19 | 40 glEnd(); |
eleni@19 | 41 |
eleni@19 | 42 if(ortho) { |
eleni@19 | 43 glPopMatrix(); |
eleni@19 | 44 } |
eleni@23 | 45 glPopAttrib(); |
eleni@19 | 46 } |