Thread View: cn.bbs.comp.program
1 messages
1 total messages
Started by ����
Tue, 05 May 1998 00:00
OPENGL(4)
Author: ����
Date: Tue, 05 May 1998 00:00
Date: Tue, 05 May 1998 00:00
164 lines
5879 bytes
5879 bytes
BBSˮľ�廪վ�þ�����
������: yxy (��˿˿#���ߵ�С��ӥ), ����: GAME_Designer
�� ��: OPENGL(4)
����վ: BBS ˮľ�廪վ (Wed Jan 14 10:03:54 1998)
ǰ����ƪ�����Ѿ���OPENGL�ı�̻�ṹ������ϡ��Ժ�
�����������������������������ݡ���һƪ�ǽ���
���̲����Ͷ�����ʵ�ʻ����Զ�ģ���ֻ�Ǹ�����
���û����ƵĶ�����������ǰ���ƶ���������ת����������
���ĵ�һ��QUAKE����Ȼ����汾˭��˭�ϵ����Ǻǡ�
��ƪ����һ��Ŀ�ľ��Ǽ���ǰ�����CALLBACK�������ʶ��
�����ڱ任��ֱ�۽��ͣ��κα任�㶼���Դ���Ļ��ͨ����
���IJ�����������
��ֻ�Ѻ���ǰ�仯�IJ��ֱ�����Ľ���
////////////////////////////////////////////////////
//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);
//ע����������¼���4��CALLBACK����
//����display() reshape()��Ҳ���������������
//ʵ�ֶԼ����������Ӧ
void CALLBACK left(void);//�� LEFT
void CALLBACK right(void);//�� RIGHT
void CALLBACK up(void);//�� UP
void CALLBACK down(void);//�� DOWN
//����ȫ�ֱ�����z_motion������������Զ��
//rotate��������������ת
static int z_motion=0,rotate=0;
void myinit(void)
{
auxInitDisplayMode(AUX_SINGLE|AUX_RGBA);
auxInitPosition(0,0,500,500);
auxInitWindow("sample1");
glClearColor(0.0,0.0,0.0,0.0);
glClear(GL_COLOR_BUFFER_BIT);
}
void CALLBACK reshape(GLsizei w,GLsizei h)
{
if(w<=500&&h<=500)
glViewport(0,0,w,h);
if(w>500&&h<=500)
glViewport(0,0,500,h);
if(w<=500&&h>500)
glViewport(0,0,w,500);
if(w>500&&h>500)
glViewport(0,0,500,500);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
///*if(w<=h)
// glOrtho(-20.0,20.0,-20.0*(GLfloat)h/(GLfloat)w,
// 20.0*(GLfloat)h/(GLfloat)w,-50.0,50.0);
//else
// glOrtho(-20.0*(GLfloat)h/(GLfloat)w,
// 20.0*(GLfloat)h/(GLfloat)w,-20.0,20.0,-50.0,50.0);
//*/
/************************************************************/
//�������ǻ�һ��ͶӰ��������ͶӰ��������е�˵
//ȡ���ϴε�ƽ��ͶӰ��ǰ4�������ǿ��Ƶ�һ����ȡ���
//left right top bottom��Ȼ������������ƽ��ȡ���
//Z��꣬Զ��ȡ���Z���꣬�����������£�
//void glFrustum(GLdouble left,GLdouble right,
// GLdouble bottom,GLdouble top,
// GLdouble near,GLdouble far);
/************************************************************/
glFrustum(-20.0,20.0,-20.0,20.0,10.0,50.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void draw(void)
{
glBegin(GL_TRIANGLE_STRIP);
glColor3f(1.0,0.0,0.0);
glVertex3f(15.0,0.0,0.0);
glColor3f(0.0,1.0,0.0);
glVertex3f(-15.0,0.0,0.0);
glColor3f(0.0,0.0,1.0);
glVertex3f(0.0,15.0,15.0);
//
glColor3f(0.0,1.0,1.0);
glVertex3f(10.0,15.0,-15.0);
//
glColor3f(1.0,1.0,0.0);
glVertex3f(15.0,0.0,0.0);
//
glEnd();
}
void CALLBACK display(void)
{
glClearColor(0.0,0.0,0.0,1.0);
glClear(GL_COLOR_BUFFER_BIT);
//glPushMatrix();
glLoadIdentity();
//���z_motion rotate��������ȷ���任�ľ�����ֵ��
//z_motion�ı�ʱ�������ԭZ���-25��ƽ��z_motion����λ
glTranslatef(0.0,0.0,-25.0+z_motion);
//rotate�ı�ʱ��������Y�ᣨ���·�����ת5*rotate��
glRotatef(rotate*5.0,0.0,1.0,0.0);
draw();
//glPopMatrix();
glFlush();
}
void CALLBACK left(void)
{
//ÿ������LEFT��rotate��ֵ +1
//���º�������
rotate++;
}
void CALLBACK right(void)
{
rotate--;
}
void CALLBACK up(void)
{
z_motion++;
}
void CALLBACK down(void)
{
z_motion--;
}
void main(void)
{
myinit();
//�ø����ĺ�����ð�left() right() up() down()
//��Ϊ���������봦�?��
auxKeyFunc(AUX_LEFT,left);
auxKeyFunc(AUX_RIGHT,right);
auxKeyFunc(AUX_UP,up);
auxKeyFunc(AUX_DOWN,down);
auxReshapeFunc(reshape);
auxMainLoop(display);
}
//end of sample
////////////////////////////////////////////////////
��������������ᷢ���н����Ե���˸�У����ǵ�����ģʽ
��ɵ��Ժ�ὲ������Ӧ����˫����ģʽ��������Ա�����˸
--
�� ��Դ:��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