Opengl 金刚石(貌似是)

仅供个人学习记录使用,如有错误,感谢指正!!!!!!!!!!

#define _CRT_SECURE_NO_WARNINGS
#include<stdlib.h>
#include<math.h>
#include<Windows.h>
#include<stdio.h> //86
#include<GL/glut.h>
void Init() {
    glClearColor(0.7f, 0.8f, 1.0f, 0.0f);  //浅蓝//rgb透明度 背景色
}
void Reshape(int w,int h) {
    glViewport(0, 0, w, h);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluOrtho2D(0, (double)w,0,(double)h);

}

void myDisplay() {          //金刚石 400 400 100//由团扇变化而来
    int x0, y0, r;
    scanf("%d %d %d", &x0, &y0, &r);
    int i, n = 20;
    float st;
    glClear(GL_COLOR_BUFFER_BIT);
    st = (360.0 / n) * (3.14 / 180);//角度转换为弧度
    glColor3f(0.3f, 0.4f, 1.0f);
    glBegin(GL_LINE_LOOP);
    //for (int j = 0; j < r; j += r / n) {
        for (int i = 0; i < n; i++) {
            glVertex2f(x0 + r * cos(i * st), y0 + r * sin(i * st));

        }
    //}
    glEnd();
    glFlush();
    glBegin(GL_LINES);
    for (int j = n; j >=0; j-=1) {
        for (int i = 0; i < n; i++) {
            glVertex2f(x0 + r * cos(j * st), y0 + r * sin(j * st));
            glVertex2f(x0 + r * cos(i * st), y0 + r * sin(i * st));

        }
    }
    glEnd();
    glFlush();
}

int main(int argc,char *argv[])
{
    glutInit(&argc,argv);
    glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
    glutInitWindowPosition(100, 100);
    glutInitWindowSize(800, 700);
    glutCreateWindow("the forth");
    Init();
    glutReshapeFunc(Reshape);
    glutDisplayFunc(myDisplay);
    glutMainLoop();

    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值