我希望在openGL中更改顶点值,我找到了一种方法来改变它,但是它是错误的,程序绘制一个三角形,当我在运行时更改顶点值时,我看到矩形,有什么问题?
代码
#include "stdAfx.h"
#include <stdio.h>
#include <stdlib.h>
#include <glut.h>
void DataSource();
void showObject();
void cont();
void inti(int argcp,char **argv)
{
glutInit(&argcp,argv);
glutInitWindowSize(500,500);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
glutCreateWindow("square");
glClearColor(0.0,0.0,0.0,0.0);
glutDisplayFunc(showObject);
glutIdleFunc(cont);
}
int main(int argcp,char **argv)
{
inti(argcp,argv);
DataSource(0.1);
glutMainLoop();
return 0;
}
void DataSource(float adding)
{
GLfloat triangle1[]={(-0.9+adding),0.3+adding,(-0.9+adding),0.8+adding, (-0.4+adding),0.8+adding, -0.9,0.3,-0.4,0.8,-0.4,0.3};
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(2,GL_FLOAT,0,triangle1);
}
void showObject()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glDrawArrays(GL_TRIANGLES,0,3);
glutPostRedisplay();
glutSwapBuffers();
}
void cont()
{
glutPostRedisplay();
}