2023年2月22日 星期三

week02020202


 week02-1

1.new projec選擇openGLUT


2.紅色球就出現了


week02-2
稍微更改一 下程式碼
就變成茶壺了!
讓他變成黃色 並多新增一個綠色大茶壺


利用點的位置畫三角形
還可以變成彩色的







#include <GL/glut.h>
void display()
{
    glColor3f(247/255.0, 247/255.0, 247/255.0);
    glBegin(GL_POLYGON);
      glVertex2f( 1,1);
      glVertex2f(-1,1);
      glVertex2f(-1,-1);
      glVertex2f( 1,-1);
    glEnd();
glColor3f(244/255.0, 209/255.0, 33/255.0);
     glBegin(GL_POLYGON);
      glVertex2f( (45-100)/100.0, -(134-100)/100.0);
      glVertex2f( (36-100)/100.0, -(171-100)/100.0);
      glVertex2f( (108-100)/100.0, -(179-100)/100.0);
      glVertex2f( (104-100)/100.0, -(117-100)/100.0);
    glEnd();

    glutSwapBuffers();
}
int main(int argc, char *argv[])
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("GLUT Shapes");
    glutDisplayFunc(display);
    glutMainLoop();

}


#include <GL/glut.h>
#include <math.h>
void myCircle(float r, float x, float y)
{
    glBegin(GL_POLYGON);
      for(float a = 0; a<2*3.1415926; a+=0.01){
            glVertex2f(r*cos(a)+x, r*sin(a)+y);
      }
    glEnd();
}
void display()
{
    glColor3f(1,0,1); myCircle(0.6, 0, 0);
    glColor3f(1,0,0); myCircle(0.3, 0.5,0.5);
    glColor3f(0,1,0); myCircle(0.3,-0.5,0.5);
    glColor3f(1,1,0); myCircle(0.3,-0.5,-0.5);
    glColor3f(0,0,1); myCircle(0.3, 0.5,-0.5);
    glutSwapBuffers();
}

int main(int argc, char *argv[])
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
    glutCreateWindow("GLUT Shapes");
    glutDisplayFunc(display);
    glutMainLoop();

}



沒有留言:

張貼留言