2020年3月11日 星期三

時間

2020.03.11
zuvio review glut project
program first glut

#include <GL/glut.h>
void display(void)
{
    glutcolor3f (1,0,0);
    glutWireTeapot(0.3);
    glutSwapBuffers();
}
int main(int argc,char *argv[])
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("week 02 CCE");
    glutDisplayFunc(display);
    glutMainLoop();
}


topic: color

#include <GL/glut.h>
void display()
{
    glBegin(GL_POLYGON);
        glColor3f(1,0,0);glVertex2f(1,0);
        glColor3f(0,1,0);glVertex2f(-1,1);
        glColor3f(0,0,1);glVertex2f(-1,-1);
        glEnd();
        glutSwapBuffers();
}
int main(int argc,char *argv[])
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("week 02 CCE");
    glutDisplayFunc(display);
    glutMainLoop();
}




topic:dot、edge、face

coordinate & painter

pro by mouse

hw







TRY TO PRACTICE WHAT I GOOGLED.


#include <stdlib.h>
#include <GL/glut.h>
#include<iostream>
#pragma comment(lib, "glut32.lib")
using namespace std;
GLfloat roate = 0.0;// set rote of roate ying yu bu hao  bu zhuang le 设置旋转速率
GLfloat rote = 0.0;//shezhi旋转角度
GLfloat anglex = 0.0;//X 轴旋转
GLfloat angley = 0.0;//Y 轴旋转
GLfloat anglez = 0.0;//Z 轴旋转
GLint WinW = 400;
GLint WinH = 400;
GLfloat oldx;//当左键按下时记录鼠标坐标
GLfloat oldy;
void init(void)
{
glClearColor(1.0, 1.0, 1.0, 1.0); //背景黑色
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0, 0.0, 0.0); //画笔红色
glLoadIdentity();  //加载单位矩阵
gluLookAt(0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
glRotatef(rote, 0.0f, 1.0f, 0.0f);
glRotatef(anglex,1.0,0.0,0.0);
glRotatef(angley,0.0,1.0,0.0);
glRotatef(anglez,0.0,0.0,1.0);
glutWireTeapot(2);
rote += roate;
//glRotatef(angle, 0.0, 1.0, 0.0);
//angle += 1.0f;
glutSwapBuffers();
}
void reshape(int w, int h)
{
glViewport(0, 0, (GLsizei)w, (GLsizei)h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60.0, (GLfloat)w / (GLfloat)h, 1.0, 20.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
}
void mouse(int button, int state, int x, int y)
{
if (button == GLUT_LEFT_BUTTON)
{
if (state == GLUT_DOWN)
{
roate = 0;
rote = 0;
oldx = x;//当左键按下时记录鼠标坐标
oldy = y;
cout << "left" << endl;
}

}
if (button == GLUT_RIGHT_BUTTON)
{
if (state == GLUT_DOWN)
{
roate += 1.0f;
cout << "right" << endl;
}

}

}
void motion(int x, int y)
{
GLint deltax = oldx - x;
GLint deltay = oldy - y;
anglex  += 360 * (GLfloat)deltax / (GLfloat)WinW;//根据屏幕上鼠标滑动的距离来设置旋转的角度
angley += 360 * (GLfloat)deltay / (GLfloat)WinH;
anglez += 360 * (GLfloat)deltay / (GLfloat)WinH;
oldx = x;//记录此时的鼠标坐标,更新鼠标坐标
oldy = y;//若是没有这两句语句,滑动是旋转会变得不可控
glutPostRedisplay();
glutPostRedisplay();
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize(600, 600);
glutInitWindowPosition(100, 100);
glutCreateWindow(argv[0]);
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMouseFunc(mouse);
glutMotionFunc(motion);
glutIdleFunc(display);
glutMainLoop();
return 0;
}






沒有留言:

張貼留言