Static Simple Graphics

  • 两种五角星画法 homework of Computer Graphic
  • 花花的三角形, 点和线的像素宽度, 写字
  • 同时出现两个窗口 描边
  • 交互式画图
  • 国民党旗 共青团徽 自定义边数的花

五角星 可以和下面的五角星对比一下

  • 参考模板讲解
// #pragma comment (lib, "opengl32.lib")
// #pragma comment (lib, "glu32.lib")
// #pragma comment (lib, "glut32.lib")//Windows VC6.0环用
#include <GL/glut.h>
#include <stdio.h>
// #include <windows.h> // Under Windows to Use Sleep(50)
#include <unistd.h>  // 在gcc编译器中,使用的头文件因gcc版本的不同而不同
#include <stdlib.h>
#include <time.h>
#include <iostream>
#include <math.h>
using namespace std;
const double PI = acos(-1.0);
float pCenter[] = {200.0, 200.0}; //五角星中心点坐标
float Length = 100;
float angle = 0; //五角星便宜正方向的角度
float R, G, B;
void myDraw(GLfloat Pos[2], GLfloat Length, GLfloat theta) //Pos[2]=五角星坐标,Length=五角星大圆半径
{
    glBegin(GL_LINE_LOOP);
    //float Short = Length * (2 - 2 * cos(0.2 * PI));
    //Wiki: 五角星 红色/蓝色 = 蓝色/绿色 可以找到大小圆半径的关系
    float Short = Length * sin(0.1 * PI) / sin(0.7 * PI);
    float beta = 18 + theta; //五角星NE的长半径和x轴的夹角
    float p1[2];
    glColor3f(R, G, B);
    for (int i = 0; i < 5; i++) //从最右边的那个长边顶点开始画
    {
        p1[0] = Length * cos(i * 2 * 0.2 * PI + beta * 3.1415926 / 180.0) + Pos[0]; //x坐标 18 * 3.1415926 = 56.55
        p1[1] = Length * sin(i * 2 * 0.2 * PI + beta * 3.1415926 / 180.0) + Pos[1]; //y坐标
        glVertex2fv(p1);
        p1[0] = Short * cos((i * 2 + 1) * 0.2 * PI + beta * 3.1415926 / 180.0) + Pos[0];
        p1[1] = Short * sin((i * 2 + 1) * 0.2 * PI + beta * 3.1415926 / 180.0) + Pos[1];
        glVertex2fv(p1);
    }
    glEnd();
}
void display()
{
    glClearColor(0, 1.0, 0, 0);
    glClear(GL_COLOR_BUFFER_BIT);
    // Sleep(50); // Windows <windows.h> unsigned Sleep(unsigned millon_seconds);
    // sleep(1); // <unistd.h> unsigned sleep(unsigned seconds);
    usleep(100000); // <unistd.h> void usleep(int micro_seconds);
    srand(time(NULL));
    for(int k = 0; k < 10; k++)
    {
        float i;
        i = rand() % 400 + 1; /* i是[1,200]区间内的一个整数 */
        pCenter[0] = (float)i;
        //srand(time(NULL)); //这里不能写,否则会生成相同的
        i = rand() % 200 + 1;
        pCenter[1] = (float)i;
        //srand(time(NULL));
        i = rand() % 200;
        i = rand() % 200 + 1;
        R = i / 200;
        //srand(time(NULL));
        i = rand() % 200 + 1;
        G = i / 200;
        //srand(time(NULL));
        i = rand() % 200 + 1;
        B = i / 200;
        //srand(time(NULL));
        i = rand() % 200 + 1;
        angle += i;
        Length = (float)i;
        myDraw(pCenter, Length, angle);
        //printf("%f\n", i);
    }
    glFlush();
}
void Reshape(int w, int h) {
    display();
}
void randomChange() {
    display();
}
int main(int argc, char* argv[])
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DEPTH | GLUT_SINGLE | GLUT_RGB);
    glutInitWindowSize(400, 400);
    glutInitWindowPosition(300, 300);
    glutCreateWindow("coder352");
    gluOrtho2D(0, 400, 0, 400);
    glutDisplayFunc(display);
    //glutReshapeFunc(Reshape);
    glutIdleFunc(randomChange);
    glutMainLoop();
    return 0;
}

glBegin画各种图形 圆 五角星 菱形 三角形

  • 参考模板讲解
#include<GL/glut.h>
#include<math.h>
const GLfloat R = 0.8f;
const GLfloat PI = 3.1415926536f;
const int n = 600;
void basicshape2()
{
    int i;
    glClearColor(1.0, 1.0, 0.0, 0.8);
    glClear(GL_COLOR_BUFFER_BIT);
    /* ---------------------- ----------------------*/
    glLineWidth(3);
    glBegin(GL_LINE_LOOP);  //以闭合折线方式画圆
    glColor3f(1.0f, 0.0f, 0.0f);
    for (i = 0; i < n; ++i)
        glVertex2f(R * cos(2 * PI / n * i), R * sin(2 * PI / n * i));
    glEnd();
    /* ---------------------- ----------------------*/
    glBegin(GL_LINE_LOOP);  //以闭合折线方式画五角星
    glColor3f(0.0f, 1.0f, 0.0f);
    GLfloat bx = R * cos(18 * PI / 180);
    GLfloat by = R * sin(18 * PI / 180);
    GLfloat cx = R * sin(36 * PI / 180);
    GLfloat cy = R * cos(36 * PI / 180);
    glVertex2f(-bx, by);
    glVertex2f(bx, by);
    glVertex2f(-cx, -cy);
    glVertex2f(0.0f, R);
    glVertex2f(cx, -cy);
    glEnd();
    /* ---------------------- ----------------------*/
    glBegin(GL_POLYGON);    //以填充方式画菱形,多边形,五角星也是可以的啦~
    glVertex2f(-0.8f, 0.95f);
    glVertex2f(-0.7f, 0.85f);
    glVertex2f(-0.8f, 0.75f);
    glVertex2f(-0.9f, 0.85f);
    glEnd();
    glBegin(GL_POLYGON);    //对称一下
    glVertex2f(0.8f, 0.95f);
    glVertex2f(0.7f, 0.85f);
    glVertex2f(0.8f, 0.75f);
    glVertex2f(0.9f, 0.85f);
    glEnd();
    //这里有两个菱形,可以用GL_QUADS一次搞定,独立的~
    /* ---------------------- ----------------------*/
    glColor3f(0.0f, 0.0f, 1.0f);
    glBegin(GL_TRIANGLES);  //两个三角形
    glVertex2f(-1.0f, -1.0f);
    glVertex2f(-0.95f, -0.7f);
    glVertex2f(-0.8f, -0.7f);
    glVertex2f(-1.0f, -1.0f);
    glVertex2f(-0.8f, -0.75f);
    glVertex2f(-0.8f, -0.95f);
    glEnd();
    /* ---------------------- ----------------------*/
    glFlush(); //最后flush一下
}
int main(int argc, char *argv[])
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
    glutInitWindowPosition(150, 150);
    glutInitWindowSize(500, 500);
    glutCreateWindow("Baisc Shape2");
    glutDisplayFunc(basicshape2);
    glutMainLoop();
    return 0;
}

小图形

  • 花花的三角形, 点和线的像素宽度, 写字
#include<GL/glut.h>
#pragma comment(linker,"/subsystem:\"windows\" /entry:\"mainCRTStartup\"")
void mydisplay(void)
{
    glClearColor(0.0, 1.0, 0.0, 0.0); //设置背景为绿色
    glClear(GL_COLOR_BUFFER_BIT);
    //在左上角画一个黄色的矩形
    glColor3f(1.0f, 1.0f, 0.0f);
    glRectf(-0.9f, 0.0f, 0.0f, 0.9f); //分别是左下角和右上角两点坐标
    //在右上角画一个花花的三角形
    glBegin(GL_TRIANGLES);
    glColor3f(1.0f, 0.0f, 0.0f);  glVertex2f(0.9f, 0.0f);
    glColor3f(0.0f, 1.0f, 0.0f);  glVertex2f(0.5f, 0.6f);
    glColor3f(0.0f, 0.0f, 1.0f);  glVertex2f(0.1f, 0.0f);
    glEnd();
    //画两个点
    glPointSize(5); //表示点的像素
    glBegin(GL_POINTS);
    glColor3f(0.0f, 0.0f, 0.0f);  glVertex2f(0.05f, 0.0f);
    glColor3f(1.0f, 0.0f, 0.0f);  glVertex2f(0.05f, -0.5f);
    glEnd();
    //写一个我的"可"字
    glLineWidth(5); //表示线的宽度
    glBegin(GL_LINES);
    glColor3f(1.0f, 1.0f, 0.0f);  glVertex2f(0.5f, -0.5f);
    glColor3f(1.0f, 1.0f, 0.0f);  glVertex2f(0.8f, -0.5f);
    glColor3f(1.0f, 1.0f, 0.0f);  glVertex2f(0.75f, -0.5f);
    glColor3f(1.0f, 1.0f, 0.0f);  glVertex2f(0.75f, -0.8f);
    glEnd();
    glColor3f(1.0f, 1.0f, 0.0f);
    glRectf(0.55f, -0.7f, 0.7f, -0.55f);
    glFlush();
}
int main(int argc, char *argv[])
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
    glutInitWindowPosition(100, 100);
    glutInitWindowSize(600, 600);
    glutCreateWindow("Basic Shape");
    glutDisplayFunc(mydisplay);
    glutMainLoop();
    return 0;
}

升级2 更加对称的图形

  • 同时出现两个窗口 描边
#include<GL/glut.h>
#include<math.h>
#pragma comment(linker,"/subsystem:\"windows\" /entry:\"mainCRTStartup\"")
const float R1 = 0.8f;
const float R2 = 0.4f;
const float PI = 3.1415926;
void myDisplay_1()
{
    glClearColor(1.0f, 1.0f, 1.0f, 0.0f);
    glClear(GL_COLOR_BUFFER_BIT);
    //*****下面开始画矩形和三角形
    glColor3f(1.0f, 0.0f, 0.0f);
    glBegin(GL_POLYGON);
    glVertex2f(0.4f, 0);
    glVertex2f(0, 0.4f);
    glVertex2f(-0.4f, 0);
    glVertex2f(0, -0.4f);
    glEnd();
    glBegin(GL_TRIANGLES);  //四个三角形
    glColor3f(1.0f, 1.0f, 0.0f);
    glVertex2f(0.4f, -0.4f);
    glVertex2f(0.8f, 0);
    glVertex2f(0.4f, 0.4f);
    glColor3f(0.0f, 0.0f, 1.0f);
    glVertex2f(0.4f, 0.4f);
    glVertex2f(-0.4f, 0.4f);
    glVertex2f(0, 0.8f);
    glColor3f(1.0f, 0.0f, 1.0f);
    glVertex2f(-0.4f, 0.4f);
    glVertex2f(-0.4f, -0.4f);
    glVertex2f(-0.8f, 0);
    glColor3f(0.0f, 1.0f, 0.0f);
    glVertex2f(-0.4f, -0.4f);
    glVertex2f(0.4f, -0.4f);
    glVertex2f(0, -0.8f);
    glEnd();
    //******描边
    glColor3f(0.0f, 0.0f, 0.0f);
    glBegin(GL_LINE_LOOP);
    glVertex2f(0.4f, 0); //矩形的边
    glVertex2f(0, 0.4f);
    glVertex2f(-0.4f, 0);
    glVertex2f(0, -0.4f);
    glEnd();
    glBegin(GL_LINE_LOOP);//三角形的边,可当作两个矩形
    glVertex2f(0.8f, 0);
    glVertex2f(0.4f, -0.4f);
    glVertex2f(0, -0.8f);
    glVertex2f(-0.4f, -0.4f);
    glVertex2f(-0.8f, 0);
    glVertex2f(-0.4f, 0.4f);
    glVertex2f(0, 0.8f);
    glVertex2f(0.4f, 0.4f);
    glVertex2f(0.4f, -0.4f);
    glVertex2f(-0.4f, -0.4f);
    glVertex2f(-0.4f, 0.4f);
    glVertex2f(0.4f, 0.4f);
    glEnd();
    glFlush();
}
void myDisplay_2()
{
    glClearColor(1.0f, 1.0f, 1.0f, 0.0f);
    glClear(GL_COLOR_BUFFER_BIT);
    for (int i = 0; i <= 270; i += 90) {
        glColor3f(1.0f, 0.0f, 0.0f);
        glBegin(GL_POLYGON);
        glVertex2f(R1 * cos(i * PI / 180), R1 * sin(i * PI / 180));
        glVertex2f(R2 * cos((i + 25)*PI / 180), R2 * sin((i + 25)*PI / 180));
        glVertex2f(0, 0);
        glVertex2f(R2 * cos((i - 25)*PI / 180), R2 * sin((i - 25)*PI / 180));
        glEnd();
        glColor3f(0.0f, 0.0f, 0.0f);
        glBegin(GL_LINE_LOOP);
        glVertex2f(R1 * cos(i * PI / 180), R1 * sin(i * PI / 180));
        glVertex2f(R2 * cos((i + 25)*PI / 180), R2 * sin((i + 25)*PI / 180));
        glVertex2f(0, 0);
        glVertex2f(R2 * cos((i - 25)*PI / 180), R2 * sin((i - 25)*PI / 180));
        glEnd();
    }
    for (int i = 45; i <= 315; i += 90) {
        glColor3f(0.0f, 1.0f, 0.0f);
        glBegin(GL_POLYGON);
        glVertex2f(R1 * cos(i * PI / 180), R1 * sin(i * PI / 180));
        glVertex2f(R2 * cos((i + 20)*PI / 180), R2 * sin((i + 20)*PI / 180));
        glVertex2f(0, 0);
        glVertex2f(R2 * cos((i - 20)*PI / 180), R2 * sin((i - 20)*PI / 180));
        glEnd();
        glColor3f(0.0f, 0.0f, 0.0f);
        glBegin(GL_LINE_LOOP);
        glVertex2f(R1 * cos(i * PI / 180), R1 * sin(i * PI / 180));
        glVertex2f(R2 * cos((i + 20)*PI / 180), R2 * sin((i + 20)*PI / 180));
        glVertex2f(0, 0);
        glVertex2f(R2 * cos((i - 20)*PI / 180), R2 * sin((i - 20)*PI / 180));
        glEnd();
    }
    glFlush();
}
int main(int argc, char * argv[])
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
    glutInitWindowPosition(100, 100);
    glutInitWindowSize(500, 500);
    glutCreateWindow("sheng2_1");
    glutDisplayFunc(myDisplay_1);
    glutInitWindowPosition(700, 100);
    glutInitWindowSize(500, 500);
    glutCreateWindow("sheng2_2");
    glutDisplayFunc(myDisplay_2);
    glutMainLoop();
    return 0;
}

交互式画图

#include<GL/glut.h>
#include<stdio.h>
int col;
int p;
void mydisplay()
{
    glShadeModel(GL_FLAT);
    glClearColor(0.0f, 1.0f, 1.0f, 0.0f);
    glClear(GL_COLOR_BUFFER_BIT);
    glColor3f(0.5f, 0.5f, 0.5f);
    glRectf(-0.9, -0.9f, -0.7f, -0.7f);
    switch (col)
    {
    case 1: glColor3f(1.0f, 0.0f, 0.0f); break;
    case 2: glColor3f(0.0f, 1.0f, 0.0f); break;
    case 3: glColor3f(0.0f, 0.0f, 1.0f); break;
    case 4: glColor3f(1.0f, 1.0f, 0.0f); break;
    case 5: glColor3f(1.0f, 0.0f, 1.0f); break;
    case 6: glColor3f(0.0f, 1.0f, 1.0f); break;
    default: printf("没有此种颜色!\n");
    }
    glLineWidth(p);
    glBegin(GL_LINES);
    glVertex2i(-1.0f, -1.0f);
    glVertex2i(0, 0);
    glEnd();
    glLineWidth(1);
    glColor3f(0.0f, 0.0f, 1.0f);
    glBegin(GL_LINES);
    glVertex2f(-0.6f, -1.0f);
    glVertex2f(-0.7f, 0.2f);
    glEnd();
    glPointSize(10);
    glColor3f(1.0f, 1.0f, 0.0f);
    glBegin(GL_POINTS);
    glVertex2f(-1.0f, -1.0f);
    glEnd();
    glFlush();
}
int main(int argc, char * argv[])
{
    glutInit(&argc, argv);
    printf("请选择线的颜色\n");
    printf("1.红色    2.绿色    3.蓝色    4.黄色    5.梅红色  6.青色\n");
    scanf("%d", &col);
    printf("请输入线的宽度:\n");
    scanf("%d", &p);
    glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
    glutInitWindowPosition(800, 100);
    glutInitWindowSize(400, 400);
    glutCreateWindow("jiben2");
    glutDisplayFunc(mydisplay);
    glutMainLoop();
    return 0;
}

国民党旗 共青团徽 自定义边数的花

  • 有BUG,待完善
#include<stdio.h>
#include<GL/glut.h>
#include<math.h>
//#pragma comment(linker,"/subsystem:\"windows\" /entry:\"mainCRTStartup\"")
const double PI = 3.14159265358979f;
const float R = 0.8f;
const float R2 = 0.48f;
const float R3 = 0.45f;
const float R4 = 0.42f;
const float r2 = 0.7f;
//const float r3 = r2*sin(36*PI/180)*2*0.382;//0.618黄金分割
const float r3 = r2 * sin(36 * PI / 180) / sin(72 * PI / 180) * 0.618;
int vn;
//国民党党旗
void GMD()
{
    glClearColor(1.0f, 1.0f, 1.0f, 0.0f);
    glClear(GL_COLOR_BUFFER_BIT);
    glBegin(GL_POLYGON);    //画背景的蓝色圆
    glColor3f(0.0f, 0.0f, 1.0f);
    for (float i = 0; i <= 360; i += 0.1)
        glVertex2f(R * cos(i * PI / 180), R * sin(i * PI / 180));
    glEnd();
    //画12个顶点的太阳
    float p[30][2];
    int j = 0;
    for (int i = 0; i <= 360; i += 30) {
        p[j][0] = R * cos(i * PI / 180);
        p[j][1] = R * sin(i * PI / 180);
        j = j + 2;
    }
    j = 1;
    for (int i = 15; i <= 360; i += 30) {
        p[j][0] = R2 * cos(i * PI / 180);
        p[j][1] = R2 * sin(i * PI / 180);
        j = j + 2;
    }
    glLineWidth(2);
    glColor3f(1.0f, 1.0f, 1.0f);
    for (j = 1; j <= 23; j++) { //填充
        glBegin(GL_POLYGON);
        glVertex2f(0, 0);
        glVertex2f(p[abs(j + 1) % 24][0], p[abs(j + 1) % 24][1]);
        glVertex2f(p[j][0], p[j][1]);
        glVertex2f(p[abs(j - 1) % 24][0], p[abs(j - 1) % 24][1]);
        glEnd();
    }
    //画中间的两个圆
    glBegin(GL_POLYGON);
    glColor3f(0.0f, 0.0f, 1.0f);
    for (int i = 0; i <= 360; i += 0.1)
        glVertex2f(R3 * cos(i * PI / 180), R3 * sin(i * PI / 180));
    glEnd();
    glBegin(GL_POLYGON);
    glColor3f(1.0f, 1.0f, 1.0f);
    for (int i = 0; i <= 360; i += 0.1)
        glVertex2f(R4 * cos(i * PI / 180), R4 * sin(i * PI / 180));
    glEnd();
    glFlush();
}
//******团徽
void GQT()
{
    glClearColor(1.0f, 1.0f, 1.0f, 0.0f);
    glClear(GL_COLOR_BUFFER_BIT);
    glBegin(GL_POLYGON);    //画黄色背景圆
    glColor3f(1.0f, 1.0f, 0.0f);
    for (float i = 0; i <= 360; i += 0.1)
        glVertex2f(R * cos(i * PI / 180), R * sin(i * PI / 180));
    glEnd();
    glBegin(GL_POLYGON);    //画红色背景圆
    glColor3f(1.0f, 0.0f, 0.0f);
    for (int i = 0; i <= 360; i += 0.1)
        glVertex2f(r2 * cos(i * PI / 180), r2 * sin(i * PI / 180));
    glEnd();
    float p[10][2];
    int j = 0;
    for (int i = 90; i <= 270; i += 72) {
        p[j][0] = r2 * cos(i * PI / 180);
        p[j++][1] = r2 * sin(i * PI / 180);
        p[j][0] = r3 * cos((i + 36) * PI / 180);
        p[j][1] = r3 * sin((i + 36) * PI / 180);
        j++;
    }
    j = j--;
    printf("%d", j);
    p[6][0] = -p[4][0];
    p[6][1] = p[4][1];
    p[7][0] = -p[3][0];
    p[7][1] = p[3][1];
    p[8][0] = -p[2][0];
    p[8][1] = p[2][1];
    p[9][0] = -p[1][0];
    p[9][1] = p[1][1];
    glColor3f(1.0f, 1.0f, 0.0f);
    glBegin(GL_POLYGON);
    for (j = 9; j >= 0; j--)
        glVertex2f(p[j][0], p[j][1]);
    glEnd();
    glLineWidth(2);
    //描边
    glColor3f(0.0f, 0.0f, 0.0f);
    glBegin(GL_LINE_LOOP);
    for (j = 0; j <= 9; j++)
        glVertex2f(p[j][0], p[j][1]);
    glEnd();
    //从原点连线
    glColor3f(0.0f, 0.0f, 0.0f);
    for (j = 0; j <= 9; j++) {
        glBegin(GL_LINES);
        glVertex2f(0, 0);
        glVertex2f(p[j][0], p[j][1]);
        glEnd();
    }
    glFlush();
}
//****花型图案
void Flower()
{
    glClearColor(1.0f, 1.0f, 1.0f, 0.0f);
    glClear(GL_COLOR_BUFFER_BIT);
    double p[201][2];
    int j = 0;
    float add = 180 / (vn / 2 + 0.5);
    float add2 = add / 2;
    for (float i = 90; i <= 270; i += add) {
        p[j][0] = R * cos(i * PI / 180);
        p[j++][1] = R * sin(i * PI / 180);
        p[j][0] = R4 * cos((i + add2) * PI / 180);
        p[j++][1] = R4 * sin((i + add2) * PI / 180);
        p[j][0] = R4 * cos((i + add2) * PI / 180);
        p[j--][1] = R4 * sin((i + add2) * PI / 180);
    }
    for (int k = j;; k++)
    {
        if (j < 0) break;
        p[k][0] = -p[j][0];
        p[k][1] = p[j][1];
        j--;
    }   //至此,点全部计算存储完毕~,注意从90度的点开始存储,然后对称右半部分
    k--;
    //画最外边的多边形
    glColor3f(1.0f, 0.0f, 1.0f);
    glBegin(GL_POLYGON);
    for (j = 0; j <= k; j = j + 2)
        glVertex2f(p[j][0], p[j][1]);
    glEnd();
    //描多边形的边
    glColor3f(0.0f, 0.0f, 0.0f);
    glBegin(GL_LINE_STRIP);
    for (j = 0; j <= k; j = j + 2)
        glVertex2f(p[j][0], p[j][1]);
    glEnd();
    //画角
    glColor3f(1.0f, 1.0f, 1.0f);
    for (j = 0; j <= k; j = j + 2) {
        glBegin(GL_POLYGON);
        glVertex2f(0, 0);
        glVertex2f(p[abs(j + 1) % k][0], p[abs(j + 1) % k][1]);
        glVertex2f(p[j][0], p[j][1]);
        glVertex2f(p[abs(j - 1) % k][0], p[abs(j - 1) % k][1]);
        glEnd();
    }
    //为里面的几个尖角描出边界
    glLineWidth(1);
    glColor3f(0.0f, 0.0f, 0.0f);
    glBegin(GL_LINE_STRIP);
    for (j = 0; j <= k; j++)
        glVertex2f(p[j][0], p[j][1]);
    glEnd();
    //从原点向各顶点连线
    for (j = 0; j < k; j++)
    {
        if (j % 2) glColor3f(1.0f, 0.0f, 0.0f);
        else glColor3f(0.0f, 0.0f, 0.0f);
        glBegin(GL_LINES);
        glVertex2f(0, 0);
        glVertex2f(p[j][0], p[j][1]);
        glEnd();
    }
    glFlush();
}
int main(int argc, char * argv[])
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
    glutInitWindowPosition(0, 100);
    glutInitWindowSize(500, 500);
    glutCreateWindow("sheng2_1");
    glutDisplayFunc(GMD);
    glutInitWindowPosition(900, 100);
    glutInitWindowSize(500, 500);
    glutCreateWindow("sheng2_2");
    glutDisplayFunc(GQT);
    printf("输入顶点数可选择花型图案的顶点数!(5~100)\n\n");
    scanf("%d", &vn);
    glutInitWindowPosition(450, 100);
    glutInitWindowSize(500, 500);
    glutCreateWindow("sheng2_1");
    glutDisplayFunc(Flower);
    glutMainLoop();
    return 0;
}
/*
Rshape是不能用在这里的,它起到刷新的作用
用算法来实现的必须要用,因为每一帧都要刷新
用库函数画的就不必了
*/
时间: 2024-10-11 23:29:25

Static Simple Graphics的相关文章

php Late Static Bindings延迟静态绑定

官网说道: As of PHP 5.3.0, PHP implements a feature called late static bindings which can be used to reference the called class in a context of static inheritance. More precisely, late static bindings work by storing the class named in the last "non-forw

EBU5405: 3D Graphics Programming Tools - Coursework 2019

EBU5405: 3D Graphics Programming Tools - Coursework 2019In this coursework you will develop an articulated and interactive object in the shape of acrawling animal using C and OpenGL. The main objectives of this project are to practice anddemonstrate:

自定义基本java类-StdDraw.java

1 /************************************************************************* 2 * Compilation: javac StdDraw.java 3 * Execution: java StdDraw 4 * 5 * Standard drawing library. This class provides a basic capability for 6 * creating drawings with your

Android 官方文档:(一)动画和图像 —— 1.5 画布和画图

The Android framework APIs provides a set 2D drawing APIs that allow you to render your owncustom graphics onto a canvas or to modify existing Views to customize their look and feel.When drawing 2D graphics, you'll typically do so in one of two ways:

OpenGL学习 Our First OpenGL Program

This shows you how to create the main window with the book’s application framework and how to render simple graphics into it. In shaders,we use #version430 core to tell the shader compiler that we intend to use version 4.3 of the shading language.The

如何使用viewpager与fragment写一个app导航activity

今天我们来看一下如何使用viewpager和fragment组合来写一个app导航activity,这里使用到了android开源控件viewpagerindicator,有兴趣的同学可以去它网站上看看它的介绍. 附上效果截图一张: demo中只有一个activity,是用activity_main.xml来布局,其内容如下: <?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:and

一个高人的许多QT开源项目(百度网盘的linux桌面客户端)

许多都是我非常感兴趣的,比如: NeteaseCloudMusic forked from yanunon/NeteaseCloudMusic网易云音乐 WizQTClient forked from WizTeam/WizQTClient为知笔记跨平台客户端 Qt5-Cadaques-In-Chinese forked from cwc1987/QmlBook-In-ChineseQt5 Cadaques In Chinese Qt360使用Qt4模拟360 10.0界面 QtAV forke

Java单例模式--------懒汉式和饿汉式

单件模式用途:单件模式属于工厂模式的特例,只是它不需要输入参数并且始终返回同一对象的引用.单件模式能够保证某一类型对象在系统中的唯一性,即某类在系统中只有一个实例.它的用途十分广泛,打个比方,我们开发了一个简单的留言板,用户的每一次留言都要将留言信息写入到数据库中,最直观的方法是没次写入都建立一个数据库的链接.这是个简单的方法,在不考虑并发的时候这也是个不错的选择.但实际上,一个网站是并发的,并且有可能是存在大量并发操作的.如果我们对每次写入都创建一个数据库连接,那么很容易的系统会出现瓶颈,系统

软件测试——JUnit基础

软件测试——JUnit基础 1. 综述 之前(很久了…)说过JUnit的安装和使用,但其实没有讲JUnit的写法,今天写写JUnit的基础. 博客链接:在Eclipse中使用JUnit4进行单元测试(初级篇) 博客链接:在Eclipse中使用JUnit4进行单元测试(中级篇) 博客链接:在Eclipse中使用JUnit4进行单元测试(高级篇) 2. JUnit基础 一段简单的代码 1 package testing; 2 3 import static org.junit.Assert.*; 4