Thread View: cn.bbs.comp.program
1 messages
1 total messages
Started by ����
Tue, 05 May 1998 00:00
OPENGL(8)
Author: ����
Date: Tue, 05 May 1998 00:00
Date: Tue, 05 May 1998 00:00
138 lines
5343 bytes
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]
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