🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: cn.bbs.comp.program
Article #963

OPENGL(2)

#963
From: ����
Date: Tue, 05 May 1998 00:00
194 lines
7734 bytes
BBSˮľ�廪վ�þ�����
������: yxy (��˿˿#���ߵ�С��ӥ), ����: GAME_Designer 
��  ��: OPENGL(2) 
����վ: BBS ˮľ�廪վ (Thu Jan  8 18:28:19 1998) 
 
[�������] 
�����ҽ����һ��С�����ô����Ϥ�ø����ı�̽ṹ�� 
 
// GLOS.H 
////////////////////////////////////////////////////////// 
// This is an OS specific header file 
//�б����ϵͳ�Ļ�ͷ�ļ� 
 
#include <windows.h> 
 
// disable data conversion warnings 
 
#pragma warning(disable : 4244)     // MIPS 
#pragma warning(disable : 4136)     // X86 
#pragma warning(disable : 4051)     // ALPHA 
////////////////////////////////////////////////////////// 
//opengl.cpp 
//������ 
#include "glos.h" 
#include <GL/gl.h> 
#include <GL/glaux.h> 
#include "windows.h" 
 
void main(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���������õ���ɫ 
        //������ɫ 
 
        /*��ͼ*/ 
        glColor3f(1.0,0.0,0.0); 
        //ѡ��ɫ��R��G��B��������0<x<1��������Ǻ�ɫ 
        glRectf(-0.5,-0.5,0.5,0.5); 
        //�������� 
 
        glFlush(); 
        //ǿ�ƻ�ͼ����פ������ 
        _sleep(1000); 
        //windows������ʾ1�루��λ�Ǻ��룩 
} 
//end of sample 
���ע�ͣ�Ӧ�ÿ��������ܣ���ʾ��ɫ���飨2D��һ���ӡ� 
������ṹ������� 
 ��ʼ�� + ��ͼ + �����ܵ��� 
���ڲ��ù��׷������ϸ�ڣ�֪���Ǹ�ʲô�ľͿ����֣����� 
��������ǰ�ô��ʵ�ֵ�һ��3D�����ӣ��ܼ򵥶��Һÿ��ģ� 
�������DZ��뱻�Ȳ��ò���ѧЩ������ 
 
1.OPENGL�����������׼�� 
 
������ 
ǰ׺      ����                    ��ӦC���� 
b         8-bit int               signed char 
s         16-bit int              short 
i         32-bit int              long 
f         32-bit float            float 
d         64-bit float            double 
ub        8-bit unsigned int      unsigned char 
us        16-bit unsigned int     unsigned short 
ui        32-bit unsigned int     unsigned long 
����1.0fʵ�ʾ���1.0��һ��д��1.0f����ȥ�ñ���һЩ�� 
 
���� 
�������������Ϊ�����׺ 
���磺glVertex2i(2,4)������opengl����gl-�� 
                         �ǻ��ĺ���-Vertex-�� 
                         ���������Ͳ���-2i�� 
������һ��������ͷȥβ��֪�����Ǹ�ʲô���֡� 
 
2.CALLBACK���� 
��һЩ������ϵͳ���õĺ���ϵͳҪ�������ǣ�������ʾ�����ܼ�������... 
��ͺñ��޻�ľһ������������������ʼ����˳��һ���޹ؽ�Ҫ���� 
ϵͳ���Զ�ִ�����ǣ����磺 
void CALLBACK display(void)����д�����뻭ʲô������Ȼ����������ʹ�� 
auxMainLoop(display);�Ϳ������������һֱ��ʾ�֣�������VC�е�OnPaint() 
 
3.OPENGL���Ļ�ͼ���� 
 
glBegin(����); 
 glColor3f(...); 
 glVertex(...) 
 glColor3f(...); 
 glVertex(...); 
 ... 
glEnd(); 
 
���ɡ����͡�ָ����ʲôƽ�棺 
GL_POINTS �������㼯 
GL_LINES �����ߣ�2����һ���� 
GL_GL_POLYGON ���������͹����� 
GL_TRAINGLES ��������ͣ�3����һ����� 
...�õ���˵�ɣ��Լ�������VC HELP INDEX�в��ң� 
////////////////////////////////////////////////////// 
//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); 
//���ﲻ�ù�reshape()��ֻ��һ�����ڴ��ڸı��Сʱ�Ĵ��� 
//���ͼ�޹أ�����ὲ�� 
//������ص���display(),��ע���ͼ�ķ��� 
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) 
{ 
glViewport(0,0,w,h); 
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 CALLBACK display(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(); 
glFlush(); 
} 
 
void main(void) 
{ 
 
    myinit(); 
    auxReshapeFunc(reshape); 
    auxMainLoop(display); 
} 
//end of sample 
�����������1��2��3��������1 
                2��3��4��������2... 
����һ������3�������ӵIJ�ɫ��ǣ������һ���������ɫƽ�� 
Χ�ɵĿ������׵...enjoy it 
 
-- 
�� ��Դ:��BBS ˮľ�廪վ bbs.net.tsinghua.edu.cn��[FROM: 166.111.74.90] 

BBSˮľ�廪վ�þ�����

�� ��Դ: �й�ƴ�BBSվ [bbs.ustc.edu.cn]
Technical Details
Message-ID: <980505.yWbQP$PBBS@bbs.ustc.edu.cn>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: Chinese,GB
X-Google-Thread: fc86e,b8e4eb8963059737,start
X-Google-Attributes: gidfc86e,public
From: Ambi_A@bbs.ustc.edu.cn (����)
Subject: OPENGL(2)
Date: 1998/05/05
Message-ID: <980505.yWbQP$PBBS@bbs.ustc.edu.cn>
X-Deja-AN: 350401696
Organization: �й�ƴ�BBSվ
Newsgroups: cn.bbs.comp.program