Opengl ES 学习笔记 3:纹理贴图
来源:互联网 发布:pscc2017 for mac破解 编辑:程序博客网 时间:2024/04/27 07:25
#include <stdlib.h>
#include <math.h>
#include <float.h>
#include <assert.h>
#include "importgl.h"
#include "app.h"
#include "shapes.h"
#include "cams.h"
#include <android/log.h>
#define PRECISION 16
inline GLfixed FixedFromInt(int value){ return value<<PRECISION; }
// Capped conversion from float to fixed.
static long Float2Fixed(float value)
{
if (value < -32768) value = -32768;
if (value > 32767) value = 32767;
return (long)(value * 65536);
}
#define FIXED(value) Float2Fixed(value)
// Called from the app framework.
void appInit()
{
glEnable(GL_BLEND);
glEnable(GL_TEXTURE_2D);
glClearColorx(0,0,0,0);
glShadeModel(GL_SMOOTH);
// glMatrixMode(GL_PROJECTION);
// glLoadIdentity();
//
// glOrthox(FixedFromInt(-50),FixedFromInt(50),
// FixedFromInt(-50),FixedFromInt(50),
// FixedFromInt(-50),FixedFromInt(50));
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
// Called from the app framework.
void appDeinit()
{
int a;
}
// Called from the app framework.
/* The tick is current time in milliseconds, width and height
* are the image dimensions to be rendered.
*/
void testTexture(GLushort *buffer) ;
void appRender(long tick, int width, int height)
{
static int rotation=0;
GLenum err = 0;
int i = 0;
int j = 0;
GLshort vertexArray[9]={-25,-25,20, 25,-25,-20, 0,25,20 };
GLubyte colorArray[12]={255,0,0,0, 0,255,0,255, 0,0,255,0 };
GLushort *buffer = (GLushort *) malloc(128*128*2);
glViewport(0, 0, width, height);//设置视口的大小以及位置,视口:也就是图形最终显示到屏幕的区域,前两个参数是视口的位置,后两个参数是视口的宽和长。
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
//glTranslatex(0,0,FixedFromInt(-10));
//glRotatex(FixedFromInt(rotation++),0,ONE,0);
/*
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3,GL_SHORT,0,vertexArray);
glEnableClientState(GL_COLOR_ARRAY);
glColorPointer(4,GL_UNSIGNED_BYTE,0,colorArray);
//glDrawArrays(GL_TRIANGLES,0,3);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
*/
//glEnable(GL_DEPTH_TEST);
//glDepthFunc(GL_LEQUAL);
//glPushMatrix();
testTexture(buffer);
//glPopMatrix();
free(buffer);
}
void testTexture(GLushort *buffer)
{
GLfixed rect[] = {
Float2Fixed(-1.0f), Float2Fixed(-1.0),0,
Float2Fixed(1.0f), Float2Fixed(-1.0), 0,
Float2Fixed(1.0f), Float2Fixed(1.0), 0,
Float2Fixed(-1.0f), Float2Fixed(-1.0),0,
Float2Fixed(1.0f), Float2Fixed(1.0), 0,
Float2Fixed(-1.0f), Float2Fixed(1.0f) , 0
};
GLfloat rect2[] = {
-1.0f, -1.0,0,
1.0f, -1.0, 0,
1.0f, 1.0, 0,
-1.0f,-1.0,0,
1.0f, 1.0, 0,
-1.0f, 1.0f , 0
};
GLfixed rnormal[] = {
0, Float2Fixed(1.0f), 0,
0, Float2Fixed(1.0f), 0,
0, Float2Fixed(1.0f), 0,
0, Float2Fixed(1.0f), 0,
0, Float2Fixed(1.0f), 0,
0, Float2Fixed(1.0f), 0
};
GLfixed rectuv[] = {
Float2Fixed(0.0f), Float2Fixed(0.0),
Float2Fixed(1.0f), Float2Fixed(0.0),
Float2Fixed(1.0f), Float2Fixed(1.0),
Float2Fixed(0.0f), Float2Fixed(0.0),
Float2Fixed(1.0f), Float2Fixed(1.0),
Float2Fixed(0.0f), Float2Fixed(1.0f)
};
unsigned short color[4]={ 0xF800, 0x7E0, 0x1F, 0xffff };
int i;
int j;
for ( i = 0; i < 128; ++i )
{
for ( j = 0; j < 128; ++j )
{
buffer[i*128+j] = color[(i/32 + j/32)%4];
}
}
glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, 128, 128 , 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, buffer);
glEnableClientState( GL_VERTEX_ARRAY );
glEnableClientState( GL_NORMAL_ARRAY );
glEnableClientState( GL_TEXTURE_COORD_ARRAY );
glVertexPointer( 3, GL_FIXED, 0, rect );
glNormalPointer( GL_FIXED, 0, rnormal);
glTexCoordPointer( 2, GL_FIXED, 0, rectuv );
glDrawArrays( GL_TRIANGLES, 0, 6);
glDisableClientState( GL_VERTEX_ARRAY );
glDisableClientState( GL_NORMAL_ARRAY );
glDisableClientState( GL_TEXTURE_COORD_ARRAY );
}
- Opengl ES 学习笔记 3:纹理贴图
- OpenGL ES纹理贴图
- OpenGL ES纹理贴图
- OpenGL ES纹理贴图
- OpenGL ES 纹理贴图
- OpenGL ES绘制3D纹理贴图
- OpenGL学习笔记之纹理贴图
- OpenGL学习笔记——纹理贴图
- OpenGL学习笔记——纹理贴图
- Android OpenGL es 3D Rubik Cube 多纹理贴图
- android opengl es 纹理贴图资料
- opengl es纹理贴图效果实例
- Android Opengl ES 2.0 纹理贴图
- OpenGL ES二维纹理坐标贴图规则
- openGL之纹理贴图---openGL学习笔记(十三)
- OpenGL ES入门05-OpenGL ES 纹理贴图
- OpenGL学习十七:纹理贴图
- openGL学习笔记6 bmp 2D纹理贴图
- 实战Jetty
- 关于表单中文本框和密码框长度不一致的解决方法
- Opengl ES 学习笔记 2:绘制一个旋转的三角形
- 填问卷,赢华章精美图书
- (转)在android的状态栏(statusbar)中增加menu,home和back快捷键的方法
- Opengl ES 学习笔记 3:纹理贴图
- 关于ubuntu的“没有为此类型文件注册相应的处理程序”
- By 2010, mature, don't childish
- 地铁PIS系统SDI接口和HDMI接口应用专题研究报告
- 独立博客
- 精益求精--卓越的互联网产品设计与管理
- 菜鸟入门 认识C#中的委托和事件
- 什么是值传递、引用传递、指针传递
- 什么时候用表达式方法声明函数