求助,opengl-es画图为什么显示不出来??
下面是我的程序,大家能不能帮我看看哪里出了问题,为什么我画的矩形显示不出来??
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "egl/gl.h"
#include "egl/glesext.h"
#include "egl/egltypes.h"
#include "egl/egl.h"
#define Float2Fixed(fl) ((GLfixed)((fl)*65536.0f))//((GLfixed)((fl)*65536.0f))
EGLDisplay display;
EGLSurface surface;
EGLContext context;
NativeWindowType win;
GLubyte embTex[128*128];
int initd();
void testTexture();
GLubyte embTex[128*128];
int main()
{
int i;
initd();
glClear( GL_COLOR_BUFFER_BIT );
testTexture();
for(i=0;i<500000000;i++);
return 0;
}
int initd()
{
EGLint major, minor;
EGLConfig configs[8];
EGLint config_count;
EGLint cfg_attribs[] = { EGL_BUFFER_SIZE, 32, EGL_NONE};
EGLBoolean flag;
//获取display get display
display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
//初始化egl init egl
eglInitialize(display, &major, &minor);
//get config
//把它们放到config数组里面 put them into array(config[X])
eglGetConfigs(display, configs, 8, &config_count);
//看看config数组里面的东西是否与cfg_attribs里的东西相匹配
eglChooseConfig(display, cfg_attribs, configs, 8, &config_count);
//构造surface
surface = eglCreateWindowSurface(display, configs[0], (NativeWindowType)win, NULL);
//创建context
context = eglCreateContext(display, configs[0], EGL_NO_CONTEXT, NULL);
//绑定context与画图 bink the context and drawing
flag=eglMakeCurrent(display, surface, surface, context);
if(flag!=EGL_TRUE)
{
printf("eglMakeCurrent error!");
}
// else printf("eglMakeCurrent success!");
eglSwapBuffers(display, surface);
return 0;
}
void testTexture()
{
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
};
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,j;
for ( i = 0; i < 128; ++i )
{
for ( j = 0; j < 128; ++j )
{
embTex[i*128+j] = color[(i/32 + j/32)%4];
}
}
glClearColor(0.5, 0.5, 0.5, 0.0); //设置刷新背景色
eglMakeCurrent(display, surface, surface, context);
glClear(GL_COLOR_BUFFER_BIT); //刷新背景
glLoadIdentity();
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_S, GL_CLAMP_TO_EDGE);
glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, 128, 128 , 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, embTex);
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);
eglSwapBuffers(display, surface);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论