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
  • 相关阅读:
    xls与csv文件的区别
    青音,经典爱情语录
    win7用户账户自动登录方法汇总
    How to using Procedure found Lead Blocker
    FTS(3) BSD 库函数手册 遍历文件夹(二)
    FTS(3) BSD 库函数手册 遍历文件夹(一)
    DisplayMetrics类 获取手机显示屏的基本信息 包括尺寸、密度、字体缩放等信息
    About App Distribution 关于应用发布
    FTS(3) 遍历文件夹实例
    OpenCV 2.1.0 with Visual Studio 2008
  • 原文地址:https://www.cnblogs.com/YTYMblog/p/5699409.html
Copyright © 2011-2022 走看看