Article View: cn.bbs.comp.program
Article #964OPENGL(3)
From: ����
Date: Tue, 05 May 1998 00:00
Date: Tue, 05 May 1998 00:00
231 lines
9242 bytes
9242 bytes
BBSˮľ�廪վ�þ�����
������: yxy (��˿˿#���ߵ�С��ӥ), ����: GAME_Designer
�� ��: OPENGL(3)
����վ: BBS ˮľ�廪վ (Tue Jan 13 08:39:45 1998)
�ϻ���˵���и�reshape��Ҫ��һ������
����������Ƕ��û��ı䴰�ڴ�С�IJ�������һЩ�ػ�
�Ķ���������VC�е�OnResize���������õ���һЩ�任�ĸ���
��ϣ�����Ѿ��߱������ļ����ͼ��ѧ��֪ʶ���⽫������
�ⲿ�ֵ���⡣���û�У�Ҳû��ϵ���Ҿ��������ͨ��һЩ
����3D��ͼ��������3D���д��������ϵ����4*4�ľ�����ʽ����ϸ
��������������������������������������������
���Բ���������ף�����Ҳ�ὲ�������κ�ͶӰ����ת...���������Կ�
���Ǿ�����˵IJ������������----�������һ��Ҫ�γɣ���
������2D����ͨ����ת�任������д�ɣ�
|cos�� sin�� 0 |
[x' y' 1]=[x y 1] |-sin�� cos�� 0 |
|0 0 1 |
3D�е�����ȫһ��һ��3Dͼ�ε���ʾ�������沽�裺
1.�ӵ�任���������ں��ʵĵط���3D���
2.ģ�ͱ任����3D������ں��ʵĵط���
3.ͶӰ�任�������ͷ����ʹ3D����ͶӰ��2D��Ƭ�ϣ�
4.�ӿڱ任��������Ƭ��С��
����1��2��û�б������
�����м����ؼ��Ժ���
һ ���α任
1.
void glTranslated(
GLdouble x,
GLdouble y,
GLdouble z
);
void glTranslatef(
GLfloat x,
GLfloat y,
GLfloat z
);
Ŀ����X Y Z��ƽ�� x y z
2.
void glRotated(
GLdouble angle,
GLdouble x,
GLdouble y,
GLdouble z
);
void glRotatef(
GLfloat angle,
GLfloat x,
GLfloat y,
GLfloat z
);
Ŀ��ֱ���X Y Z��Ϊ����ʱ����ת x y z
3.
void glScaled(
GLdouble x,
GLdouble y,
GLdouble z
);
void glScalef(
GLfloat x,
GLfloat y,
GLfloat z
);
Ŀ����X Y Z ��������,��������Ϊ x y z
�� ͶӰ�任
1.����ͶӰ����û�С����ԶС����
void glOrtho(GLdouble left,GLdouble right,GLdouble bottom,GLdouble top,
GLdouble near,GLdouble far)
����һ��ƽ���Ӿ��壨�ľ�����Ͷ������ƽ���ߣ��ѵ�һ������
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
�Ӿ�ͶӰ���ڶ��������Ӿ��ϡ��������������Ե�ǰ��������ɱ任��
���һ�����ε����Ͻ���ά�ռ����(left,bottom,-near)�����½ǵ���ά
�ռ����(right,top,-near)��
Զ���ڶ����������Ͻ���ά�ռ����(left,bottom,-far),���½ǵ���ά�ռ�
���(right,top,-far);
2.��ͶӰ�������ԶС����
void glFrustum(
GLdouble left,
GLdouble right,
GLdouble bottom,
GLdouble top,
GLdouble znear,
GLdouble zfar
);
����һ��������̨���Ӿ��壬����ȡ����left right bottom top znear
ȷ����Զ��ȡ���ɴ��ӵ�ͶӰ���ȡ�浽Z��zfarλ�þ���
�� �ӿڱ任
void glViewport(GLint x,GLint y,GLsize width,GLsize height);
���������һ���ӿڣ�x��y���ӿ�����Ļ�������ϵ���������
ȱʡ�ǣ�0��0����width height�ǿ�ߡ�
ע��ʹ�����ӿڳ������ĵ���ᵼ��ͼ����Ρ����reshape()��
Ҫ��ⴰ�ڳߴ磬�����ӿڴ�С����֤ͼ���Ρ�
����
void glMatrixMode(GLenum mode );
�ѵ�ǰ����ת��Ϊָ���ľ�������
�������������ü������е�����˵����
////////////////////////////////////////////////////////////
//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 myinit(void)
{
/*��ʼ����*/
auxInitDisplayMode(AUX_SINGLE|AUX_RGBA);
//������ʾ�������RGB����ɫ��ģʽ
auxInitPosition(0,0,500,500);
//��Сx=500 y=500 ��0��0������Ļ���ϵ�
auxInitWindow("sample1");
//���ڳ�ʼ���������DZ���
glClearColor(0.0,0.0,0.0,0.0);
//��������Ϊ��ɫ
glClear(GL_COLOR_BUFFER_BIT);
//����ɫ������ΪglClearColor���������õ���ɫ
//������ɫ
}
//////////////////////////////////////////////////
void CALLBACK reshape(GLsizei w,GLsizei h)
{
//�趨�ӿ�X Y����Ҫ����500��λ
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);
//�����������ϵ�����任
//��Ҫ�IJ��裬��ʼ���任�����裺 1ȷ������ 2��ɵ�λ��
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);
//�ѱ任�����ӵ����ϵ
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);
glLoadIdentity();
glTranslatef(0.0,0.0,-25.0);
draw();
//��ʼ���ڶ�������
//�任��ʼ����任����Ϊ��λ��
glLoadIdentity();
//����X Y Zƽ��-5 -10 -4����Ļ�Ͽ������������ƶ�
//Z����������ƽ��ͶӰ��û�С����ԶС�����Կ�����Ч��
glTranslatef(-5.0,-10.0,-4.0);
//����Z��ת90��
glRotatef(90,0.0,0.0,1.0);
draw();
//��ͼ������ɣ�ǿ�ƻ�ͼ����
glFlush();
}
void main(void)
{
myinit();
auxReshapeFunc(reshape);
auxMainLoop(display);
}
//sample ends here
/////////////////////
���������һ�¾�֪��������������ã����ǰ������ƶ���ת��������
����...
��������ǰ3����OPENGL�Ļ�ԭ���Ѿ������
������ṩ��һ�����ļ����ͼ��ѧ��ʹ�õ���ѧģ�͵���ʾ�Ľӿڣ�
ֻҪ�߱�ͼ��ѧ֪ʶ������OPENGL API����ʹ�ã���ͼ��EASY��
�����Ѿ���ϣ���������̸��һЩ�Ļ�ͼ�����磺
���?��Դ������...
���ϣ�������������� :)
--
�� ��Դ:��BBS ˮľ�廪վ bbs.net.tsinghua.edu.cn��[FROM: 166.111.74.90]
BBSˮľ�廪վ�þ�����
�� ��Դ: �й�ƴ�BBSվ [bbs.ustc.edu.cn]
Technical Details
Message-ID:
<980505.yWbQw$PBBS@bbs.ustc.edu.cn>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: Chinese,GB X-Google-Thread: fc86e,9a626efd0d8a5683,start X-Google-Attributes: gidfc86e,public From: Ambi_A@bbs.ustc.edu.cn (����) Subject: OPENGL(3) Date: 1998/05/05 Message-ID: <980505.yWbQw$PBBS@bbs.ustc.edu.cn> X-Deja-AN: 350408750 Organization: �й�ƴ�BBSվ Newsgroups: cn.bbs.comp.program