OpenGL ES 纹理上画点
我尝试在一张全屏的背景纹理上画N个红点,点上但是整个背景图都会被渲染成红色。求高手指点啊,弄了好久都没解决!!!
//绑定背景纹理,绘制背景纹理,代码略。。。。//开始绘制红点//gl.glClear(GL10.GL_COLOR_BUFFER_BIT);gl.glMatrixMode(GL10.GL_MODELVIEW);gl.glLoadIdentity();Dot myDot = new Dot();myDot.draw(gl);class Dot{ private FloatBuffer vertexBuffer; //点的坐标(x, y, z); private float vertices[] = { 100.0f,100.0f,0, 200.0f,200.0f,0, 300.0f,300.0f,0, 400.0f,400.0f,0 }; //准备顶点数据 private void init(){ ByteBuffer vertexByteBuffer = ByteBuffer.allocateDirect(vertices.length * 4); vertexByteBuffer.order(ByteOrder.nativeOrder()); vertexBuffer = vertexByteBuffer.asFloatBuffer(); vertexBuffer.put(vertices); vertexBuffer.position(0); } public Dot(){ init(); } public void draw(GL10 gl){ //开始数组功能 GL_VERTEX_ARRAY gl.glEnableClientState(GL10.GL_VERTEX_ARRAY); //设定颜色值 此处为红 (red, green, blue, alpha)~[0.0f-1.0f] gl.glColor4f(1.0f, 0.0f, 0.0f, 1.0f); // 指向数组数据 gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer); //设置点的大小 为 5 像素 gl.glPointSize(5); // 绘制点 GL_POINTS ; vertices.length/3 点的个数 gl.glDrawArrays(GL10.GL_POINTS, 0, vertices.length / 3); //关闭数组功能 GL_VERTEX_ARRAY gl.glDisableClientState(GL10.GL_VERTEX_ARRAY); }}