我的代碼的工作原理如下: 繪製一個三角形,然後單擊「1」時,縮放三角形,但是發生的是三角形縮放和平移。在opengl中縮放
這裏是我的代碼: 全局變量
#include <glut.h>
void Display(void);
void MyKeyboard(unsigned char,int,int);
void MyMouse(int,int,int,int);
int x1 =20 .0f;
int y1 = 30.0f;
int x2 = 40.0f;
int y2 = 50.0f;
int x3 = 60.0f;
int y3 = 10.0f;
主要方法
void main(int argc,char** argr)
{
glutInit(&argc,argr);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(1000,600);
glutInitWindowPosition(50,50);
glutCreateWindow("Mouse and Keyboard");
glutDisplayFunc(Display);
glutKeyboardFunc(MyKeyboard);
glutMouseFunc(MyMouse);
glClearColor(0.0f,0.0f,0.0f,0.0f);
gluOrtho2D(0.0,1000.0,0.0,600.0);
glutMainLoop();
}
顯示方法
void Display()
{
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
glBegin(GL_TRIANGLES);
glColor3f(0.0f,0.0f,1.0f);
glVertex3f(x1, 600-y1, 0.0f);
glVertex3f(x2, 600-y2, 0.0f);
glVertex3f(x3, 600-y3, 0.0f);
glEnd();
glPopMatrix();
glFlush();
}
鍵盤事件
void MyKeyboard(unsigned char key,int mouseX,int mouseY)
{
if (key == '1')
{
glScaled (0.5f ,0.5f ,1.0f);
glutPostRedisplay();
return;
}
沒有什麼變化,三角形縮放,但移動(翻譯) – ahmed
我需要它保持在其位置 – ahmed