🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

OPENGL(8)

#969
From: ����
Date: Tue, 05 May 1998 00:00
138 lines
5343 bytes
BBSˮľ�廪վ�þ�����
������: yxy (��˿˿#���ߵ�С��ӥ), ����: GAME_Designer 
��  ��: OPENGL(8) 
����վ: BBS ˮľ�廪վ (Mon Jan 19 16:59:50 1998) 
 
��ΰѲ�����ȫ�㶨���Ǻ� 
�ϴ�12����ͬ�����������ij�������glMaterialfv()���ı���� 
������е�ϵͳ��ġ� 
 
����ͬ��Ĺ��ܿ���ʹ�ã� 
void glColorMaterial(GLenum face,GLenum mode)��ʵ�֡� 
face��ȡֵ: 
GL_FRONT GL_BACK GL_FRONT_AND_BACK 
mode��ȡֵ: 
GL_AMBIENT GL_DIFFUSE GL_AMBIENT_AND_DIFFUSE GL_SPECULAR GL_EMISSION 
 
����Ҫʹ���������ʱ��Ҫ����glEnable(GL_COLOR_MATERIAL)���Ǻ����� 
�ڻ�ͼʱʹ��glColor*()���ı������ɫ������glMaterial()���ı���ʳɷ� 
ʹ����ϣ�Ҫ��glDisable(GL_COLOR_MATERIAL)���ر����ֲ���ģʽ�� 
 
���磺 
glColorMaterial(GL_FRONT,GL_DIFFUSE); 
glEnable(GL_COLOR_MATERIAL); 
 
glColor3f(0.3,0.5,0.7); 
//��һЩ���壺 
... 
 
glColor3f(0.0,1.0,0.0); 
//�ٻ���һЩ���壺 
... 
 
glDisable(GL_COLOR_MATERIAL); 
 
˵���� 
����Ҫ�ı䳡���д󲿷ַ���ĵ�������ʱ����õ���glColorMaterial() 
���޸IJ�ֻһ�����ʲ�����õ���glMaterial*()������Ŀǰ����ᵽ 
Ψһ��ʹ�ù����ϵ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); 
 
void myinit(void) 
{ 
        auxInitDisplayMode(AUX_SINGLE|AUX_RGBA); 
        auxInitPosition(0,0,500,500); 
        auxInitWindow("sample1"); 
        glClearColor(0.0,0.1,0.1,0.0); 
        glClear(GL_COLOR_BUFFER_BIT); 
//      glShadeModel(GL_FLAT); 
 
//����һ����ɫ�򵥹�Դ 
        GLfloat light_position[]={0.0,3.0,2.0,0.0}; 
        glLightfv(GL_LIGHT0,GL_POSITION,light_position); 
        glEnable(GL_LIGHTING); 
        glEnable(GL_LIGHT0); 
 
//�������� 
        glDepthFunc(GL_LESS); 
        glEnable(GL_DEPTH_TEST); 
    
//������ɫ����ģʽ 
        glColorMaterial(GL_FRONT,GL_DIFFUSE); 
        glEnable(GL_COLOR_MATERIAL); 
} 
 
void CALLBACK reshape(GLsizei w,GLsizei h) 
{ 
glViewport(0,0,w,h); 
glMatrixMode(GL_PROJECTION); 
glLoadIdentity(); 
if(w<=h) 
 glOrtho(-6.0,6.0,-6.0*(GLfloat)h/(GLfloat)w, 
         6.0*(GLfloat)h/(GLfloat)w,-10.0,10.0); 
else 
  glOrtho(-6.0*(GLfloat)h/(GLfloat)w, 
         6.0*(GLfloat)h/(GLfloat)w,-6.0,6.0,-10.0,10.0); 
 
glMatrixMode(GL_MODELVIEW); 
glLoadIdentity(); 
} 
 
void CALLBACK display(void) 
{ 
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); 
 
//�Ȼ�һ����ɫ���ʵ��� 
        glLoadIdentity(); 
        glTranslatef(-0.7,0.0,0.0); 
        glColor3f(1.0,1.0,0.0); 
        auxSolidSphere(1.0); 
 
//���ڻ�����ұ�2.7����һ����ɫ���� 
        glLoadIdentity(); 
        glRotatef(-60.0,1.0,0.0,0.0); 
        glTranslatef(2.7,0.0,0.0); 
        glColor3f(1.0,0.0,0.0); 
        auxSolidSphere(1.0); 
 
//���ٻ�����ߣ�����֮�䣩�����λ�û�һ����ɫ���׶ 
        glLoadIdentity(); 
        glTranslatef(-1.0,-1.0,-5.0); 
        glRotatef(30.0,1.0,0.0,0.0); 
        glColor3f(0.0,1.0,1.0); 
        auxSolidCone(2.0,2.0); 
 
    glFlush(); 
} 
void main(void) 
{ 
    myinit(); 
     
    auxReshapeFunc(reshape); 
    auxMainLoop(display); 
} 
//end of sample 
//////////////////////////////////////////////////////////// 
ͨ��������ӣ����dz��˿�����ϤglColorMaterial()��ʹ�ã������� 
��ᵽOPENGL����������Ϊ�������Ĺ������ǵ�����ǰ����ò�ɫƽ�� 
�������׶����������������ĸ�ƽ��󻭣��ĸ�ƽ���ڵ���ǰ��ƽ�档 
�������ǿ�����Ȼ���׶��Ȼ��󻭳�������OPENGL�����������Ѿ���֤ 
����ʵ��Ӧ�ñ����������������ȡ��myinit()�����������������ô 
���׶���ܵ�ǰ�����֣��Ǻǡ� 
 
-- 
�� ��Դ:��BBS ˮľ�廪վ bbs.net.tsinghua.edu.cn��[FROM: 166.111.74.90] 

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

�� ��Դ: �й�ƴ�BBSվ [bbs.ustc.edu.cn]
Technical Details
Message-ID: <980505.yWbTA$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,3dd6bd98c6769cc4,start
X-Google-Attributes: gidfc86e,public
From: Ambi_A@bbs.ustc.edu.cn (����)
Subject: OPENGL(8)
Date: 1998/05/05
Message-ID: <980505.yWbTA$PBBS@bbs.ustc.edu.cn>
X-Deja-AN: 350416395
Organization: �й�ƴ�BBSվ
Newsgroups: cn.bbs.comp.program