Skip to content

Instantly share code, notes, and snippets.

@vumbumy
Created February 3, 2017 05:09
Show Gist options
  • Save vumbumy/1a9eccb237ac5ab58892d57cd2af5856 to your computer and use it in GitHub Desktop.
Save vumbumy/1a9eccb237ac5ab58892d57cd2af5856 to your computer and use it in GitHub Desktop.
void DoDisplay()
{
float jump = 0.25f;
Vec3f vertex;
vector<GLubyte> indices;
Vec3f texture;
#ifdef AUTO_CALC
for (GLfloat y = size; y >= -size; y -= jump){
for (GLfloat x = -size; x <= size; x += jump){
vertex.push(x, y);
GLfloat i = (x + 1.0) / 2;
GLfloat j = (y + 1.0) / 2;
texture.push(i, j);
}
}
int w = 2.0 * size / jump + 1;
int n = w - 1;
int h = w;
int m = h - 1;
for (int j = 0; j < m; j++){
for (int i = 0; i < n; i++){
int index = w * j + i;
indices.push_back(index);
indices.push_back(index + w);
indices.push_back(index + 1);
indices.push_back(index + w);
indices.push_back(index + 1);
indices.push_back(index + w + 1);
}
}
#else
vertex.push_back(-1); vertex.push_back(1);
vertex.push_back(-1); vertex.push_back(-1);
vertex.push_back(1); vertex.push_back(1);
vertex.push_back(1); vertex.push_back(-1);
texture.push_back(0); texture.push_back(1);
texture.push_back(0); texture.push_back(0);
texture.push_back(1); texture.push_back(1);
texture.push_back(1); texture.push_back(0);
#endif // AUTO_CALC
load_texture();
// 텍스처 환경 설정
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, EnvMode);
// 텍스처 필터 설정
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, TexFilter);
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, TexFilter);
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
/*
glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glScalef(1.0f, -1.0f, 1.0f);
*/
glMatrixMode(GL_MODELVIEW);
glRotatef(xAngle, 1.0f, 0.0f, 0.0f);
glRotatef(yAngle, 0.0f, 1.0f, 0.0f);
glRotatef(zAngle, 0.0f, 0.0f, 1.0f);
glEnable(GL_TEXTURE_2D);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glVertexPointer(VERTEX_NUM, GL_FLOAT, 0, &vertex[0]);
glTexCoordPointer(VERTEX_NUM, GL_FLOAT, 0, &texture[0]);
glBindTexture(GL_TEXTURE_2D, g_texid);
#ifdef AUTO_CALC
glDrawElements(GL_TRIANGLES, indices.size(), GL_UNSIGNED_BYTE, &indices[0]);
#else
glDrawArrays(GL_TRIANGLE_STRIP, 0, vertex.size() / VERTEX_NUM);
#endif // AUTO_CALC
//glDisable(GL_TEXTURE_2D);
glPopMatrix();
glFlush();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment