Thread View: cn.bbs.comp.program
1 messages
1 total messages
Started by ����
Tue, 05 May 1998 00:00
OPENGL(18)
Author: ����
Date: Tue, 05 May 1998 00:00
Date: Tue, 05 May 1998 00:00
257 lines
11120 bytes
11120 bytes
BBSˮľ�廪վ�þ�����
������: yxy (��˿˿#С��ӥ���߲�����), ����: GAME_Designer
�� ��: OPENGL(18 ����4:00�洩 :)
����վ: BBS ˮľ�廪վ (Fri Feb 20 16:20:40 1998)
OPENGL֡����Ͷ���
��Ϊ���һ�أ����ǽ������Լ���ʱ��Ӱ�Ķ�������û��VOODOO����ҿ���OPENGL
��������������ô��Ϊ�İɣ���Ч����������⽫��20�ι�ˮ����Ŀ�ꡣ
����ǰ�棨�����ǵ����ǵ��ĴΣ���������ü��α任ʵ�ֶ�������ʱ��Ч��
���ڿ��϶��������⣬��ΪƵ������˸����������Ҫ�ġ���Ϊ��ʱ������֮ǰҲ
�ǣ����õ��ǵ�����ģʽ����������ʾ�IJ��ֱ�����ı�Ȼ����ٶ�ƿ����
������˸��һ�����Ķ���������ʵ���϶���ͨ��˫����ʵ�ֵģ�Ӳ��Ҳ�ã���
��Ҳ�ã���ҿ��Բο������õ�������Ϸ���98-2�е�һƪ���¡���ǰ̨��ʾ
����������ʾʱ����̨�����Ѿ����м��㣬������ϰ���������ͨ��濽��һ
������ɣ���ֹ��˸�ij��֡�
һ OPENGL֡�����ʵ��
1 ��ɫ���棨Color Buffer���������ݿ�������ɫ�������RGBA��ݣ�����õ�
OPENGLϵͳ֧������ͼ�����������������档
2 ��Ȼ��棨Depth Buffer�� ����Z-BUFFER�����ڱ�������Z�������ֵ�����
��ı����С�Ĵ��棬����ʵ������
3 ģ�建�棨Stencil Buffer�� ���Ա�����Ļ��ijЩλ��ͼ�β��䣬�������
�ػ档��������Ϥ�Ŀ��ɻ�������Ϸ�ļ�ʻ���ӽǣ�ֻ�е�������ľ���
�仯�������DZ�ȵȲ����仯��
4 �ۼƻ��棨Accumulation Buffer�� ֻ����RGBA��ݣ����ںϳ�ͼ��������ij
�����е�λͼ��������ϳ�һ����ͼ��
�� ֡��������
�Ը߷ֱ���ģʽ�����ǹ������������OPENGLһ����Ѱ��Ӳ��ͬʱ��ɣ�
����������ν��������ǰ��ÿ�α��õ�glClearColor()����Ѿ���İ��ɡ�
�����������ֵ
void glClearColor(GLclampf red,GLclampf green,GLclampf blue,GLclampf alpha);
void glClearIndex(GLfloat index);
void glClearDepth(GLclampd depth);
void glClearStencil(GLint s);
void glClerAccum(GLfloat red,GLfloat green,GLfloat blue,GLfloat alpha);
Ȼ��������
void glClear(GLbitfield mask);
mask: GL_COLOR_BUFFER_BIT|
GL_DEPTH_BUFFER_BIT|
GL_STENCIL_BUFFER_BIT|
GL_ACCUM_BUFFER_BIT
�� ˫���涯��
��������еı任�������ɺ�̨����ļ��㣬Ȼ������н����ǰ̨���ɡ�
�������ֻ�����������ݣ�
���ȳ�ʼ��ʱ����
auxInitDisplayMode(AUX_DOUBLE|AUX_RGBA);
��AUX_DOUBLE����AUX_SINGLE���ó�˫����ģʽ
Ȼ���ڻ�����ϣ�glFlush();����
auxSwapBuffers();
���л��濽����Easy like sunday morning!!
��Ȼ��ͬϵͳ�£��������Ҳ�?ͬ���Ͼ��Ǹ���⺯��ô��������X-WINDOWS
�¿���ʹ��glxSwapBuffers()����˼��ȫһ��
��˵˵����������ӵĹ��ܣ�
��һ����ɫ�Ļ���Ϊ���壬��һ����ɫ���������ʾ��Դ��λ�á�
С�ϴ���Ļ���˶����ҷ������Կ�����״���Ϲ�Ӱ�ı仯��
������
������/�Ҽ�ʼ/ֹͣ��Դ���˶�
���� ��/��/��/�ң����ƻ�״��� ǰ��/����/��ת
//////////////////////////////////////////////////////////////////
//sample.cpp
#include "glos.h"
#include <GL/gl.h>
#include <GL/glaux.h>
#include "windows.h"
void myinit(void);
void CALLBACK display(void);
void CALLBACK reshape(GLsizei w,GLsizei h);
void CALLBACK stepDisplay(void);
void CALLBACK startIdleFunc(AUX_EVENTREC *event);
void CALLBACK stopIdleFunc(AUX_EVENTREC *event);
//step�DZ�ʾ��״����ת�IJ���z�ǿ�����ǰ�����IJ���
static GLfloat step=0.0,z=0.0;
//position�ǿ��ƹ�Դ��λ�õIJ���
static GLfloat position[]={-20.0,0.0,-5.0,1.0};
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);
glFrontFace(GL_CW);
glEnable(GL_LIGHTING);
glFrontFace(GL_CW);
// glEnable(GL_POLYGON_SMOOTH);
// glEnable(GL_BLEND);
// glBlendFunc(GL_SRC_ALPHA,GL_ONE);
glDepthFunc(GL_LESS);
glEnable(GL_DEPTH_TEST);
// glShadeModel(GL_FLAT);
}
void CALLBACK reshape(GLsizei w,GLsizei h)
{
glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
/*if(w<=h*3)
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);
*/
//����������Ӿ������н��ԶС��Ч��
glFrustum(-6.0,6.0,-6.0,6.0,3.0,20.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void CALLBACK display(void)
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
//�����ڵ�ǰλ�����ù�Դ
glPushMatrix();
GLfloat light_ambient[]={0.3,0.5,0.3};
GLfloat light_diffuse[]={1.0,1.0,1.0};
GLfloat light_specular[]={0.8,0.8,0.0};
glLightfv(GL_LIGHT0,GL_AMBIENT,light_ambient);
glLightfv(GL_LIGHT0,GL_DIFFUSE,light_diffuse);
glLightfv(GL_LIGHT0,GL_SPECULAR,light_specular);
glLightfv(GL_LIGHT0,GL_POSITION,position);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
//�ڹ�Դ�Ա��ƻ�ɫ������С��־��Դλ��
//С���Դλ����position[]����
glTranslatef(position[0],position[1],position[2]-1.0);
GLfloat mat_ambient[]={1.0,0.0,0.0,1.0};
GLfloat mat_diffuse[]={1.0,1.0,0.0,1.0};
GLfloat mat_specular[]={1.0,1.0,0.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);
auxSolidSphere(0.5);
glPopMatrix();
//�ڵ�ǰλ�û�����ɫ��״���λ����step z��ͬ����
glPushMatrix();
glTranslatef(0.0,0.0,-8.0+z);
glRotatef(135.0+step,0.0,1.0,0.0);
GLfloat mat2_ambient[]={0.0,0.0,1.0,1.0};
GLfloat mat2_diffuse[]={0.2,0.0,0.99,1.0};
GLfloat mat2_specular[]={1.0,1.0,0.0,1.0};
GLfloat mat2_shininess[]={50.0};
glMaterialfv(GL_FRONT,GL_AMBIENT,mat2_ambient);
glMaterialfv(GL_FRONT,GL_DIFFUSE,mat2_diffuse);
glMaterialfv(GL_FRONT,GL_SPECULAR,mat2_specular);
glMaterialfv(GL_FRONT,GL_SHININESS,mat2_shininess);
auxSolidTorus(2.0,3.5);
glPopMatrix();
glFlush();
//������ϣ����潻��
auxSwapBuffers();
}
void CALLBACK Up(void)
{
//���̡��ϡ��Ĵ���
z=z+0.05;
}
void CALLBACK Down(void)
{
//���̡��¡��Ĵ���
z=z-0.05;
}
void CALLBACK Left(void)
{
//���̡��Ĵ���
step=step+2.0;
}
void CALLBACK Right(void)
{
//���̡��ҡ��Ĵ���
step=step-2.0;
}
void CALLBACK stepDisplay(void)
{
//ϵͳ��ʱ�ĵ��ù��
position[0]=position[0]+0.5;
if(position[0]>20.0) position[0]=-20.0;
display();
}
void CALLBACK startFunc(AUX_EVENTREC *event)
{
//������Ĵ���
auxIdleFunc(stepDisplay);
}
void CALLBACK stopIdleFunc(AUX_EVENTREC *event)
{
//����Ҽ�Ĵ���
auxIdleFunc(0);
}
void main(void)
{
myinit();
auxReshapeFunc(reshape);
auxIdleFunc(stepDisplay);
auxMouseFunc(AUX_LEFTBUTTON,AUX_MOUSEDOWN,startFunc);
auxMouseFunc(AUX_RIGHTBUTTON,AUX_MOUSEDOWN,stopIdleFunc);
auxKeyFunc(AUX_UP,Up);
auxKeyFunc(AUX_DOWN,Down);
auxKeyFunc(AUX_LEFT,Left);
auxKeyFunc(AUX_RIGHT,Right);
auxMainLoop(display);
}
//end of sample
////////////////////////////////////////////////////////////////////
�����õ�����CALLBACK����ֱ��?ͬ��Ϣ
�Ƚ�ǰ����ʾ�Ķ���Ч����˸���������Ը����֣���������������������
˫����ĵط��ijɵ����棺����AUX_SINGLE��ȥ��auxSwapBuffers()��������˸
�Ķ�ô�����������ڱ���Ļ�ͼ���ܵ���β����ֻ�ܹ��Լ����������֡�
д��������ڴ���OPENGL������ʵ�ֵ�������ġ�������ʶ�������롣
�����ʲô�������һ��ᾡ�����䣬���Ҳ�������ɲ��䡣
--
�� ��Դ:��BBS ˮľ�廪վ bbs.net.tsinghua.edu.cn��[FROM: 166.111.74.90]
BBSˮľ�廪վ�þ�����
�� ��Դ: �й�ƴ�BBSվ [bbs.ustc.edu.cn]
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads