🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: cn.bbs.comp.program
1 messages
1 total messages Started by ���� Tue, 05 May 1998 00:00
OPENGL(15)
#976
Author: ����
Date: Tue, 05 May 1998 00:00
299 lines
11074 bytes
BBSˮľ�廪վ�þ�����
������: yxy (��˿˿#С��ӥ���߲�����), ����: GAME_Designer 
��  ��: OPENGL(15) 
����վ: BBS ˮľ�廪վ (Tue Feb 17 21:40:18 1998) 
 
Ϊʲô3D��ͼ�����ܲ��������𾪵�Ч����Ϊ����3D��ͼ����������һЩ 
��ʵ���ѵ�ʵ�ֵ���ʵ�ĸ��ܡ��ر���һЩ����Ĺ�ӰЧ�� 
��ʵ��Դǰ���Ѿ����ĺ�ȫ���ˣ�ֻ��ȱ��һЩר�ŵ����ӡ�������������΢ 
����һ����ʶ�����ǽ��������п���һ���ط��Ĺ�Դ�Բ�ͬ���巢����ͬ�Ĺ� 
������ʵ�����ټ�İɣ� 
 
1.˫����գ� 
void glLightModeli(LIGHT_MODEL_TWO_SIDE,GL_TRUE); 
���ռ���ͨ���ǶԶ���ν��еġ�һ�����ù��յ��������Ƕ�����Ķ���Σ��� 
�����DZ��棬���������һ�����屻���Դ�ĸ����ֻ�Ӱ��ɼ��ԣ���ô 
�б�Ҫ�Զ����˫�涼���м��㣬��������溯��Ĺ��ܣ�ȡ����һ����ֻ��� 
����������ΪGL_FALSE�� 
 
2.�۹�Դ 
����۹�Դ�ĺ�����������glLightfv()����Ҫ�趨�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 initlights(void) 
{ 
//��������������Ե���ֵ 
        GLfloat mat_ambient[]={0.2,0.2,0.2,1.0}; 
        GLfloat mat_diffuse[]={0.8,0.8,0.8,1.0}; 
        GLfloat mat_specular[]={1.0,1.0,1.0,1.0}; 
        GLfloat mat_shininess[]={80.0}; 
 
//�����0����Դ�����ԣ�����ƽ�еĻ����⣬û�о۹�Ч��     
        GLfloat light0_diffuse[]={0.0,0.0,1.0,1.0}; 
        GLfloat light0_position[]={1.0,1.0,1.0,0.0}; 
//�����һ����Դ�����ԣ��۹��һ�� 
        GLfloat light1_ambient[]={0.2,0.2,0.2,1.0}; 
        GLfloat light1_diffuse[]={1.0,0.0,0.0,1.0}; 
        GLfloat light1_specular[]={1.0,0.6,0.6,1.0}; 
        GLfloat light1_position[]={-3.0,-3.0,3.0,1.0}; 
        GLfloat spot_direction[]={1.0,1.0,-1.0}; 
 
//����ڶ�����Դ�����ԣ��۹�ƶ��� 
        GLfloat light2_ambient[]={0.2,0.6,0.2,1.0}; 
        GLfloat light2_diffuse[]={0.0,1.0,0.0,1.0}; 
        GLfloat light2_specular[]={0.0,1.0,0.0,1.0}; 
        GLfloat light2_position[]={-3.0,-3.0,3.0,1.0}; 
        GLfloat spot2_direction[]={1.0,1.0,-1.0}; 
//���������ǿ�����һ�͵ڶ����۹�Դ��������ɫ�Ķ�����һ��ƫ�죬һ��ƫ�� 
//����û���κβ�ͬ��������������Ǻ������ģ���һ�����忪��һ����Դ���� 
//��һ�����忪����һ����Դ���ͻ����һ�����Դ�Բ�ͬ���巢����ͬ���Ч�� 
 
//��ǰ������Զ������Ӧ�� 
        glLightfv(GL_LIGHT0,GL_DIFFUSE,light0_diffuse); 
        glLightfv(GL_LIGHT0,GL_POSITION,light0_position); 
 
        glLightfv(GL_LIGHT1,GL_AMBIENT,light1_ambient); 
        glLightfv(GL_LIGHT1,GL_DIFFUSE,light1_diffuse); 
        glLightfv(GL_LIGHT1,GL_SPECULAR,light1_specular); 
        glLightfv(GL_LIGHT1,GL_POSITION,light1_position); 
//����۹�Ʒ�ɢ�� 
        glLightf(GL_LIGHT1,GL_SPOT_CUTOFF,30.0); 
//����۹�Ʒ��䷽������� 
        glLightfv(GL_LIGHT1,GL_SPOT_DIRECTION,spot_direction); 
 
        glLightfv(GL_LIGHT2,GL_AMBIENT,light2_ambient); 
        glLightfv(GL_LIGHT2,GL_DIFFUSE,light2_diffuse); 
        glLightfv(GL_LIGHT2,GL_SPECULAR,light2_specular); 
        glLightfv(GL_LIGHT2,GL_POSITION,light2_position); 
 
        glLightf(GL_LIGHT2,GL_SPOT_CUTOFF,30.0); 
        glLightfv(GL_LIGHT2,GL_SPOT_DIRECTION,spot2_direction); 
 
        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); 
 
        glEnable(GL_LIGHTING); 
        glEnable(GL_LIGHT0); 
        glEnable(GL_LIGHT1); 
        glEnable(GL_LIGHT2); 
 
} 
 
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); 
 
        glDepthFunc(GL_LESS); 
        glEnable(GL_DEPTH_TEST); 
        initlights(); 
//      glShadeModel(GL_FLAT); 
} 
 
void CALLBACK reshape(GLsizei w,GLsizei h) 
{ 
 
glViewport(0,0,w,h); 
glMatrixMode(GL_PROJECTION); 
glLoadIdentity(); 
 
if(w<=h) 
 glOrtho(-5.0,5.0,-5.0*(GLfloat)h/(GLfloat)w, 
         5.0*(GLfloat)h/(GLfloat)w,-5.0,5.0); 
else 
  glOrtho(-5.0*(GLfloat)h/(GLfloat)w, 
         5.0*(GLfloat)h/(GLfloat)w,-5.0,5.0,-5.0,5.0); 
glMatrixMode(GL_MODELVIEW); 
glLoadIdentity(); 
} 
 
 
void CALLBACK display(void) 
{ 
  glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); 
//���ȱ���۹�Դһ������λ�ã�ͬһλ�ã� 
  glPushMatrix(); 
  glTranslated(-3.0,-3.0,3.0); 
  glDisable(GL_LIGHTING); 
  glColor3f(1.0,0.0,0.0); 
  auxWireCube(0.1); 
  glEnable(GL_LIGHTING); 
  glPopMatrix(); 
 
//�ص��ڶ�����Դ��ֻ���õ�һ����Դ���죩����������һ 
  glPushMatrix(); 
  glDisable(GL_LIGHT2);  
  glTranslated(0.0,2.0,0.0); 
  auxSolidSphere(2.0); 
  glPopMatrix(); 
   
//�ص���һ����Դ��ֻ���õڶ�����Դ���̣������������ 
  glPushMatrix(); 
  glDisable(GL_LIGHT1); 
  glEnable(GL_LIGHT2); 
  glTranslated(0.0,-2.0,0.0); 
  auxSolidSphere(2.0); 
  glPopMatrix(); 
 
  glFlush(); 
} 
void main(void) 
{ 
    myinit(); 
     
    auxReshapeFunc(reshape); 
    auxMainLoop(display); 
} 
//end of sample 
/////////////////////////////////////////////////////////////// 
һ����ʵ�����Լ���龰�����ˡ����������ԣ� 
 
�����Դ֮ǰ���ٸ��һ����Դ�ƶ������ӣ������õ��������Ϣ����Ӧ��ʵ�� 
�dz��򵥣���OPENGL�ĸ�����ṩ�ķ�ʽ����һ��CALLBACK����ɣ�����ǰ�� 
����Ӧ��������ķ�����ȫһ�� 
////////////////////////////////////////////////////////////// 
//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); 
 
//���ƹ�Դ�ƶ��ı��� 
static int step=0; 
 
//�����Ӧ��CALLBACK���� 
void CALLBACK movelight(AUX_EVENTREC *event) 
{ 
step=(step+15)%360; 
} 
 
void initlights(void) 
{ 
        GLfloat mat_ambient[]={0.2,0.2,0.2,1.0}; 
        GLfloat mat_diffuse[]={0.8,0.8,0.8,1.0}; 
        GLfloat mat_specular[]={1.0,1.0,1.0,1.0}; 
        GLfloat mat_shininess[]={80.0}; 
     
        GLfloat light0_diffuse[]={0.0,0.0,1.0,1.0}; 
        GLfloat light0_ambient[]={0.2,0.5,0.5,1.0}; 
 
 
 
        glLightfv(GL_LIGHT0,GL_DIFFUSE,light0_diffuse); 
        glLightfv(GL_LIGHT0,GL_AMBIENT,light0_ambient); 
 
 
 
        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); 
 
        glEnable(GL_LIGHTING); 
        glEnable(GL_LIGHT0); 
 
} 
 
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); 
 
        glDepthFunc(GL_LESS); 
        glEnable(GL_DEPTH_TEST); 
        initlights(); 
//      glShadeModel(GL_FLAT); 
} 
 
void CALLBACK reshape(GLsizei w,GLsizei h) 
{ 
 
glViewport(0,0,w,h); 
glMatrixMode(GL_PROJECTION); 
glLoadIdentity(); 
 
if(w<=h) 
 glOrtho(-5.0,5.0,-5.0*(GLfloat)h/(GLfloat)w, 
         5.0*(GLfloat)h/(GLfloat)w,-5.0,5.0); 
else 
  glOrtho(-5.0*(GLfloat)h/(GLfloat)w, 
         5.0*(GLfloat)h/(GLfloat)w,-5.0,5.0,-5.0,5.0); 
glMatrixMode(GL_MODELVIEW); 
glLoadIdentity(); 
} 
 
 
void CALLBACK display(void) 
{ 
  GLfloat position[]={0.0,0.0,1.5,1.0}; 
 
  glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); 
   
  glPushMatrix(); 
  glTranslatef(0.0,0.0,-5.0); 
  glPushMatrix(); 
 
//��Դ��λ��ֻ����ת����step������ÿ����������һ�£�step��ֵ���ı� 
//���¹�Դλ�õĸı� 
  glRotated((GLdouble)step,-1.0,1.0,1.0); 
  glLightfv(GL_LIGHT0,GL_POSITION,position); 
  glTranslated(0.0,0.0,1.5); 
 
  glDisable(GL_LIGHTING); 
  glColor3f(1.0,1.0,0.0); 
  auxWireSphere(0.25); 
  glEnable(GL_LIGHTING); 
 
  glPopMatrix(); 
  auxSolidTorus(0.5,2.5); 
  glPopMatrix(); 
 
  glFlush(); 
 
 
} 
void main(void) 
{ 
    myinit(); 
     
    auxMouseFunc(AUX_LEFTBUTTON,AUX_MOUSEDOWN,movelight); 
    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