main.cpp

來源:互聯網
上載者:User

#include <windows.h>
#include <GL/gl.h>
#include <GL/glaux.h>

void myinit(void);
void CALLBACK display(void);
void CALLBACK reshape(GLsizei w,GLsizei h);

void myinit(void)
{
auxInitDisplayMode(AUX_DOUBLE|AUX_RGBA);
auxInitPosition(0,0,500,500);
auxInitWindow("sample1");
glClearColor(0.0,0.0,0.0,0.0);
glClear(GL_COLOR_BUFFER_BIT);
// glShadeModel(GL_FLAT);

//首先定義一個材質,定義方法非常類似前面講到的光源定義。
GLfloat mat_ambient[]={0.8,0.8,0.8,1.0};
//定義 紫色 的漫反射特性
GLfloat mat_diffuse[]={0.8,0.0,0.8,1.0};
//定義 亮紫色 的鏡面反射特性
GLfloat mat_specular[]={1.0,0.0,1.0,1.0};
//定義鏡面反射的光亮度
GLfloat mat_shininess[]={50.0};
//將以上材質定義應用
glMaterialfv(GL_FRONT,GL_AMBIENT,mat_ambient);
glMaterialfv(GL_FRONT,GL_DIFFUSE,mat_diffuse);
glMaterialfv(GL_FRONT,GL_SPECULAR,mat_specular);
glMaterialfv(GL_FRONT,GL_SHININESS,mat_shininess);

//這裡我們簡化光源,以顯示材質的效果。
//這裡我們只指定光源位置,其他預設:白色光源。
//你也可以加入光源的定義,看看光源和材質的合成的效果
//正是因為它們能夠合成,才能產生比真實生活中多的多的效果,這也正是
//3D技術迷人的魅力所在。
GLfloat light_position[]={1.0,1.0,1.0,0.0};
glLightfv(GL_LIGHT0,GL_POSITION,light_position);
// GLfloat light_diffuse[]={0.0,0.0,1.0,1.0};
// glLightfv(GL_LIGHT0,GL_DIFFUSE,light_diffuse);

//將光源設定應用
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);

//著色消隱
//*******其實說白樂,這就是大名鼎鼎的 Z-BUFFER 呀************//
glDepthFunc(GL_LESS);
glEnable(GL_DEPTH_TEST);
}

void CALLBACK reshape(GLsizei w,GLsizei h)
{
glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if(w<=h)
glOrtho(-2.0,2.0,-2.0*(GLfloat)h/(GLfloat)w,
2.0*(GLfloat)h/(GLfloat)w,-10.0,10.0);
else
glOrtho(-2.0*(GLfloat)h/(GLfloat)w,
2.0*(GLfloat)h/(GLfloat)w,-2.0,2.0,-10.0,10.0);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}

void draw(void)
{
auxSolidSphere(1.0);
}

void CALLBACK display(void)
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

glLoadIdentity();
draw();
glFlush();
}
void main(void)
{
myinit();

auxReshapeFunc(reshape);
auxMainLoop(display);
}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.