Thread View: cn.bbs.comp.program
1 messages
1 total messages
Started by ����
Tue, 05 May 1998 00:00
OPENGL(9)
Author: ����
Date: Tue, 05 May 1998 00:00
Date: Tue, 05 May 1998 00:00
251 lines
9287 bytes
9287 bytes
BBSˮľ�廪վ�þ�����
������: yxy (��˿˿#���ߵ�С��ӥ), ����: GAME_Designer
�� ��: OPENGL(9)
����վ: BBS ˮľ�廪վ (Tue Jan 20 16:29:11 1998)
OPENGL��λͼ��ͼ��
��һ���λͼ���岻ͬ��OPENGL�е�λͼ��ָ��ÿ������ֻ��һλ��Ϣ��
��ͼ��һ�����ؿ����������Ϣ��R��G��B��Alphaֵ����
����λͼ�����������룬���ڱ��ͼ��ͼ��������ĸ�����ǰ
�Ĵ��ڵ���ݻ�����֮�ںϡ�
��һ��λͼ��BITMAP�����ַ�FONT��
���������Դ�����Ӧ�������Σ����統ǰ��ɫΪ��ɫ�����ھ�����Ԫ��ֵΪ
1�ĵط��ú�ɫȡ��0�ĵط����ֲ��䡣λͼ�������ַ���ʾ��
��դλ�ã�
void glRasterPos{234}{sifd}[v](TYPE x,TYPE y,TYPE z,TYPE w);
���õ�ǰ��λͼ��ͼ���ԭ�㡣һ����ɫ������Ӧ�÷���glRasterPos*()
��ǰ�棬���������λͼ���̳е�ǰ���õ�������ɫ��
λͼ��ʾ��
void glBitmap(GLsizei width,GLsizei height,GLfloat xbo,GLflaot ybo,
GLfloat xbi,GLfloat ybi,const GLubyte *bitmap);
xbo,ybo����λͼ��ԭ�㣬��ϸ�ɲμ����ӣ�
//////////////////////////////////////////////////////////////////
//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);
//�����ַ�λͼ�����µ��ϣ�����һ���������ģ������һ�У��������ƣ���
// 11111111
// 11111111
// 11000011
// 11000011
// 11000011
// 11111111
// 11111111
// 11000011
// 11000011
// 11000011
// 11111111
// 11111111
//���һ�� 8 ��
GLubyte rasters[12]={0xff,0xff,0xc3,0xc3,0xc3,0xff,0xff,
0xc3,0xc3,0xc3,0xff,0xff};
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);
//����λͼ����ڼ�����ڴ��еĴ洢��ʽ�������
glPixelStorei(GL_UNPACK_ALIGNMENT,1);
}
void CALLBACK reshape(GLsizei w,GLsizei h)
{
glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0,w,0,h,-1.0,1.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void CALLBACK display(void)
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
//�ȶ����ɫ��䣺
glColor3f(1.0,0.0,1.0);
glRasterPos2i(100,200);
//��2����ͬλ�û��� 8 ����ɫ��
glBitmap(8,12,0.0,0.0,20.0,20.0,rasters);
glBitmap(8,12,0.0,0.0,20.0,20.0,rasters);
//������һ�� 8 ����ɫ��
glColor3f(1.0,1.0,0.0);
glRasterPos2i(150,200);
glBitmap(8,12,0.0,0.0,0.0,0.0,rasters);
glFlush();
}
void main(void)
{
myinit();
auxReshapeFunc(reshape);
auxMainLoop(display);
}
//end of sample
///////////////////////////////////////////////////////
������ͼ��
�ַ���ʾֻ�Ǹ�С���ݣ�������Ҳ�������ͼ�����ʾ
1.���ض�д
OPENGL�ṩ�����ض�д����
void glReadPixels( GLint x, GLint y, GLsizei width, GLsizei height,
GLenum format, GLenum type, GLvoid *pixels );
�������(x,y)����ͼ���������½���꣬width height����ͼ���ߡ�
pixel��ָ�룬ָ��ͼ��������顣formatָ�����Ԫ�ظ�ʽ�������
R��G��B��Aֵ����
format: ˵����
GL_INDEX ������ɫ����
GL_RGB ���� �졢�̡�������
GL_RED ������ɫ����
GL_GREEN ������ɫ����
GL_BLUE ������ɫ����
GL_ALPHA ����Alphaֵ
GL_LUMINANCE_ALPHA
GL_STENCIL_INDEX ���������
GL_DEPTH_COMPONENT ������ȷ���
��typeָ��Ԫ��������ͣ�
type:
GL_UNSIGNED_BYTE ���8���
GL_BYTE 8���
GL_BITMAP ���8λ���������е�����λ
GL_UNSIGNED_SHORT ���16���
GL_SHORT 16���
GL_UNSIGNED_INT ���32���
GL_INT 32���
GL_FLOAT �����ȸ�����
���Ƶ�д���غ���
void glDrawPixels( GLsizei width, GLsizei height, GLenum format,
GLenum type, const GLvoid *pixels );
2.���ؿ���
void glCopyPixels( GLint x, GLint y, GLsizei width,
GLsizei height, GLenum type );
����������������glReadPixels()Ȼ�����glDrawPixels()�����������
ϵͳ�ڴ棬ֻ�ǿ�����
type�����ǣ�GL_COLOR GL_STENCIL GL_DEPTH
�ڿ���ǰ��typeҪ�����·�ʽת����format:
1��typeΪGL_DEPTH GL_STENCIL ��ôformat ��ӦӦ����GL_DEPTH_COMPONENT
��GL_STENCIL_INDEX
2��typeΪGL_COLOR ��ôformat Ӧ����GL_RGB��GL_COLOR_INDEX��
3.ͼ������
void glPixelZoom(GLfloat zoomx,GLfloat zoomy);
zoomx zoomy��X Y������������ӡ�ȱʡ��1.0��
#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.0,0.0,0.0);
glClear(GL_COLOR_BUFFER_BIT);
// glPixelStorei(GL_UNPACK_ALIGNMENT,1);
}
void CALLBACK reshape(GLsizei w,GLsizei h)
{
glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if(w<=h)
gluOrtho2D(0.0,15.0,0.0,15.0*(GLfloat)h/(GLfloat)w);
else
gluOrtho2D(0.0,15.0*(GLfloat)w/(GLfloat)h,0.0,15.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void draw()
{
//����һ����ɫ����Σ�2D��
glBegin(GL_TRIANGLES);
glColor3f(1.0,0.0,0.0);
glVertex2f(2.0,3.0);
glColor3f(0.0,1.0,0.0);
glVertex2f(12.0,3.0);
glColor3f(0.0,0.0,1.0);
glVertex2f(7.0,12.0);
glEnd();
}
void CALLBACK display(void)
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
//����Ļ�Ϸ�����ԭʼͼ��
glPushMatrix();
glLoadIdentity();
glTranslatef(4.0,8.0,0.0);
glScalef(0.5,0.5,0.5);
draw();
glPopMatrix();
int i;
for(i=0;i<5;i++)
{
//ѭ��5�λ���5������
//�ȶ�����ʾ�������ӣ�������
glPixelZoom(1.0+0.1*i,1.0+0.1*i);
//�ٶ��忽��ԭ�㣨Խ��Խ�����ϣ�
glRasterPos2i(1+i*2,i);
//ͼ��
glCopyPixels(160,310,180,160,GL_COLOR);
}
glFlush();
}
void main(void)
{
myinit();
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