zoukankan      html  css  js  c++  java
  • 绘制图形与3D增强技巧(二)----直线图元

    一.

    glBegin(GL_LINES);

    glend();

    二.线带和线环

    glBegin(GL_LINE_STRIP);

    glend();

    glBegin(GL_LINE_LOOP);

    glend();

    三.设置直线宽度

    glLineWidth(GLfloat width);

    四.获得直线宽度范围和增量

    GLfloat sizes[2];

    GLfloat add;

    glGetFloatv(GL_LINE_WIDTH_RANGE,sizes);

    glGetFloatv(GL_LINE_WIDTH_GRANULARITY,&add);

    直线示范例程序

    /
    
    #include "stdafx.h"
    #include<GLglut.h>
    #include<math.h>
    #define PI 3.14
    
    GLfloat xRot=0.0f;
    GLfloat yRot=0.0f;
    void Init()
    {
        glClearColor(0.0,0.0,0.0,0.0);
        
    
    }
    void ChangeSize(int w,int h)
    {
        glViewport(0,0,w,h);
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        GLfloat aspect=w/h;
        if (w<=h)
        {
            glOrtho(-100.0,100.0,-100.0/aspect,100.0/aspect,-100.0,100.0);
        }
        else
        {
            glOrtho(-100.0*aspect,100.0*aspect,-100.0,100.0,-100.0,100.0);
        }
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
    
    
    }
    
    void Mydisplay()
    {
        GLfloat x,y,angle,z=0.0f;
        GLfloat sizes[2];
        glColor3f(0.0f,1.0f,0.0f);
        glClear(GL_COLOR_BUFFER_BIT);
        glPushMatrix();
        glRotatef(xRot,1.0,0.0,0.0);
        glRotatef(yRot,0.0,1.0,0.0);
    
    
        for (angle = 0.0f; angle <2*PI; angle+=0.1f)
        {
            
                glBegin(GL_LINES);
                x=50.0f*cos(angle);
                y=50.0f*sin(angle);
                glVertex3f(x,y,z);
                x=50.0f*cos(angle+PI);
                y=50.0f*sin(angle+PI);
                glVertex3f(x,y,z);
                glEnd();
        }
        
    
        glPopMatrix();
        glutSwapBuffers();
    
    
    }
    void Mykeys(int key,int x,int y)
    {
        if (key==GLUT_KEY_LEFT)
        {
            yRot-=5.0f;
        }
        if (key==GLUT_KEY_RIGHT)
        {
            yRot+=5.0f;
        }
        if (key==GLUT_KEY_UP)
        {
            xRot-=5.0f;
        }
        if (key==GLUT_KEY_DOWN)
        {
            xRot+=5.0f;
        }
        if (xRot>355.0f)
        {
            xRot=0.0f;
        }
        if (xRot<=-5.0f)
        {
            xRot=355.0f;
        }
        if (yRot>355.0f)
        {
            yRot=0.0f;
        }
        if (yRot<=-5.0f)
        {
            yRot=355.0f;
        }
    
    
        glutPostRedisplay();
    
    }
    int main(int argc,char ** argv)
    {
        
        
        
        glutInit(&argc,argv);
        glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE);
    
        glutInitWindowPosition(500,500);
        glutInitWindowSize(800,800);
        glutCreateWindow("Points");
    
        Init();
        glutDisplayFunc(Mydisplay);
        glutReshapeFunc(ChangeSize);
        glutSpecialFunc(Mykeys);
        glutMainLoop();
    
    
    }
    亲爱的听众朋友我是你的代班DJ
  • 相关阅读:
    flask中程序和请求上下文
    flask的初始化
    git 强制覆盖本地代码
    python编写一个带参数的装饰器
    Android 11 unexpected LOCAL_MODULE_CLASS for prebuilts: FAKE
    systemctl自定义service执行shell脚本时报错:code=exited, status=203/EXEC
    shell应用记录
    ssm在maven项目中的需要的依赖
    swiper 5张卡片轮播图实现效果
    Codeforces 1534 题解
  • 原文地址:https://www.cnblogs.com/YTYMblog/p/5699409.html
Copyright © 2011-2022 走看看