사용자가 마우스로 클릭 한 다음 사용자가 사각형을 그려서 프로그램을 작성하면 사용자가 위, 아래, 왼쪽 및 오른쪽으로 이동할 수 있습니다. 사용자가 객체를 이동할 때의 문제는 hide입니다.이동했을 때보기에서 삼각형이 사라짐
누구든 나를 도울 수 있습니다.
이 코드의 샘플입니다
#include <GL/glut.h>
#include<iostream.h>
#define ORTHO_SCALE 10.
GLint triangle_vertices[] = {15, 20,30, 20,10, 15};
GLint triangle_vertices2[] = {50, 70,80, 90,100, 130};
struct {
struct {
struct {
GLfloat x, y;
} pos;
GLfloat rot;
} triangle;
} sceneinfo;
void clearScreen()
{
glutSwapBuffers();
glColor3f (1.0, 1.0, 1.0);
int ver[]={38,0,1143,0,1143,800,38,1105};
glPushMatrix();
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(2, GL_INT, 0, ver);
glDrawArrays(GL_QUADS, 0, 4);
glDisableClientState(GL_VERTEX_ARRAY);
glPopMatrix();
glutSwapBuffers();
}
void mouse(int btn, int state, int x, int y)
{
if(btn==GLUT_RIGHT_BUTTON && state==GLUT_DOWN)
exit(0);
if(btn==GLUT_LEFT_BUTTON && state==GLUT_DOWN)
{
glutSwapBuffers();
glPushMatrix();
glTranslatef(sceneinfo.triangle.pos.x, sceneinfo.triangle.pos.y, 0);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(2, GL_INT, 0, triangle_vertices2);
glDrawArrays(GL_TRIANGLES, 0, 3);
glPopMatrix();
glutSwapBuffers();
}
}
void display(void);
void special(int key, int x, int y);
void init (void)
{
glClearColor (1.0, 1.0, 1.0, 0.0); // Set display-window color to white.
glMatrixMode (GL_PROJECTION); // Set projection parameters.
gluOrtho2D (0.0, 200.0, 0.0, 150.0);
}
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE);
glutCreateWindow("test");
init();
glutDisplayFunc(display);
glutSpecialFunc(special);
glutMouseFunc(mouse);
glutMainLoop();
return 0;
}
void display(void)
{
glColor3f(0.0, 0.0, 0.0);//set color of object
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glTranslatef(sceneinfo.triangle.pos.x, sceneinfo.triangle.pos.y, 0.);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(2, GL_INT, 0, triangle_vertices);
glDrawArrays(GL_TRIANGLES, 0, 3);
glPopMatrix();
glutSwapBuffers();
}
void special(int key, int x, int y)
{
switch(key) {
case GLUT_KEY_LEFT:
sceneinfo.triangle.pos.x -= 0.2;
break;
case GLUT_KEY_RIGHT:
sceneinfo.triangle.pos.x += 0.2;
break;
case GLUT_KEY_UP:
sceneinfo.triangle.pos.y += 0.2;
break;
case GLUT_KEY_DOWN:
sceneinfo.triangle.pos.y -= 0.2;
break;
}
glutPostRedisplay();
}
sceneinfo.triangle.pos에 문제가 없습니다. 내 문제 어떻게 새 위치에있는 모든 객체를 다시 그릴 수 있습니까? – Developer
나는 단지 여러분이 버퍼를 바꾸고'clearscreen()'을 그리는 것을 보았을 뿐이므로 그것도 제거해야한다. 렌더링 프로세스에서 사용되는 깊이, 렌더링 및 기타 버퍼를 지울 때만 사용해야합니다. –
도와 주셔서 감사합니다. – Developer