• 大小: 8.48MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-11-12
  • 语言: 其他
  • 标签: OpenGL  

资源简介

Opengl初级入学源代码,实现三维动画绘图,天体绘图,提升自我编码能力

资源截图

代码片段和文件信息

#include
#include
#include
#include
static int day=50;

double CalFrequency()
{
    static int count;
    static double save;
    static clock_t lastcurrent;
    double timegap;

    ++count;
    if(count<=50)
        return save;
    count=0;
    last=current;
    current=clock();
    timegap=(current-last)/(double)CLK_TCK;
    save=50.0/timegap;
    return save;
}


void myDisplay(void)
{
     double FPS=CalFrequency();
    printf(“FPS=%f\n“FPS);
   
    glEnable(GL_DEPTH_TEST);
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(100116.00000000);//gluPerspective第一个参数  可视度范围从0到1800几乎在物体里面   180在最远处,可以理解为无限远处
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt(02.000000002.00000000000001);//后面6个数表示从(0,0,0)到(0,0,1)的有向向量为正方向
    //绘制红色太阳
    glColor3f(1.0f0.0f0.0f);
    glutSolidSphere(0.069600002020);
    //绘制蓝色地球
    glColor3f(0.0f0.0f1.0f);
    glRotatef(day/360.0*360.00.0f0.0f-1.0f);//后三个数表示(000)到(xyz)为向轴,逆时针旋转;
    glTranslatef(1.500000000.0f0.0f);
    glutSolidSphere(0.15945000100100);
    //绘制黄色月亮
    glColor3f(1.0f1.0f0.0f);
    glRotatef(day/30.0*360.0-day/360.0*360.00.0f0.0f-1.0f);
    glTranslatef(0.380000000.0f0.0f);
    glutSolidSphere(0.043450002020);

    
    glFlush();
    glutSwapBuffers();
}

void myIdle(void)
{
    ++day;
    if(day>=360)
        day=0;
    myDisplay();
}
int main(int argcchar*argv[])
{
    glutInit(&argcargv);
    glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE);
    glutInitWindowPosition(100100);
    glutInitWindowSize(400400);
    glutCreateWindow(“11“);
    glutDisplayFunc(&myDisplay);
    glutIdleFunc(&myIdle);
    glutMainLoop();


    return 0;
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2015-09-09 20:04  test太阳和月亮\
     目录           0  2015-09-09 10:43  test太阳和月亮\Debug\
     文件       33792  2015-09-09 20:03  test太阳和月亮\Debug\test太阳和月亮.exe
     文件      266516  2015-09-09 20:03  test太阳和月亮\Debug\test太阳和月亮.ilk
     文件      445440  2015-09-09 20:03  test太阳和月亮\Debug\test太阳和月亮.pdb
     目录           0  2015-09-03 14:07  test太阳和月亮\test太阳和月亮\
     文件    28835840  2015-09-09 20:04  test太阳和月亮\test太阳和月亮.sdf
     文件         924  2015-09-01 19:30  test太阳和月亮\test太阳和月亮.sln
     文件       20480  2015-09-09 20:04  test太阳和月亮\test太阳和月亮.v11.suo
     目录           0  2015-09-09 20:03  test太阳和月亮\test太阳和月亮\Debug\
     文件         666  2015-09-09 20:03  test太阳和月亮\test太阳和月亮\Debug\cl.command.1.tlog
     文件        1914  2015-09-09 20:03  test太阳和月亮\test太阳和月亮\Debug\CL.read.1.tlog
     文件         404  2015-09-09 20:03  test太阳和月亮\test太阳和月亮\Debug\CL.write.1.tlog
     文件           2  2015-09-09 20:03  test太阳和月亮\test太阳和月亮\Debug\link-cvtres.read.1.tlog
     文件           2  2015-09-09 20:03  test太阳和月亮\test太阳和月亮\Debug\link-cvtres.write.1.tlog
     文件           2  2015-09-09 20:03  test太阳和月亮\test太阳和月亮\Debug\link-rc.read.1.tlog
     文件           2  2015-09-09 20:03  test太阳和月亮\test太阳和月亮\Debug\link-rc.write.1.tlog
     文件        1202  2015-09-09 20:03  test太阳和月亮\test太阳和月亮\Debug\link.command.1.tlog
     文件        2740  2015-09-09 20:03  test太阳和月亮\test太阳和月亮\Debug\link.read.1.tlog
     文件         486  2015-09-09 20:03  test太阳和月亮\test太阳和月亮\Debug\link.write.1.tlog
     文件       13430  2015-09-09 20:03  test太阳和月亮\test太阳和月亮\Debug\OpenGLSunAndMoon.obj
     文件         100  2015-09-09 20:03  test太阳和月亮\test太阳和月亮\Debug\test太阳和月亮.lastbuildstate
     文件         156  2015-09-09 20:03  test太阳和月亮\test太阳和月亮\Debug\test太阳和月亮.log
     文件       35840  2015-09-09 20:03  test太阳和月亮\test太阳和月亮\Debug\vc110.idb
     文件       77824  2015-09-09 20:03  test太阳和月亮\test太阳和月亮\Debug\vc110.pdb
     文件        1951  2015-09-09 20:03  test太阳和月亮\test太阳和月亮\OpenGLSunAndMoon.c
     文件        4029  2015-09-01 19:31  test太阳和月亮\test太阳和月亮\test太阳和月亮.vcxproj
     文件         952  2015-09-01 19:31  test太阳和月亮\test太阳和月亮\test太阳和月亮.vcxproj.filters

评论

共有 条评论