- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
这可能是一个非常新手的问题,但我找不到答案。
使用来自 google 的简单教程 (http://developer.android.com/resources/tutorials/opengl/opengl-es20.html)
我试图画一个正方形(呃,用常识?),但得到了有趣的结果。如果有人能告诉我哪里出了问题,我将不胜感激。
private void initShapes(){
float triangleCoords[] = {
// X, Y, Z
-0.5f, -0.25f, 0,
0.5f, -0.25f, 0,
0.0f, 0.559016994f, 0,
0.0f, 0f, 0
};
// initialize vertex Buffer for triangle
ByteBuffer vbb = ByteBuffer.allocateDirect(
// (# of coordinate values * 4 bytes per float)
triangleCoords.length * 4);
vbb.order(ByteOrder.nativeOrder());// use the device hardware's native byte order
triangleVB = vbb.asFloatBuffer(); // create a floating point buffer from the ByteBuffer
triangleVB.put(triangleCoords); // add the coordinates to the FloatBuffer
triangleVB.position(0); // set the buffer to read the first coordinate
}
public void onDrawFrame(GL10 unused) {
// Redraw background color
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
// Add program to OpenGL environment
GLES20.glUseProgram(mProgram);
GLES20.glVertexAttribPointer(maPositionHandle, 4, GLES20.GL_FLOAT, false, 12, triangleVB);
GLES20.glEnableVertexAttribArray(maPositionHandle);
GLES20.glDrawArrays(GLES20.GL_LINE_LOOP, 0, 4);
}
教程中的其他所有内容。
private final String vertexShaderCode =
"attribute vec4 vPosition; \n" +
"void main(){ \n" +
" gl_Position = vPosition; \n" +
"} \n";
private final String fragmentShaderCode =
"precision mediump float; \n" +
"void main(){ \n" +
" gl_FragColor = vec4 (0.63671875, 0.76953125, 0.22265625, 1.0); \n" +
"} \n";
private int mProgram;
private int maPositionHandle;
private int loadShader(int type, String shaderCode){
// create a vertex shader type (GLES20.GL_VERTEX_SHADER)
// or a fragment shader type (GLES20.GL_FRAGMENT_SHADER)
int shader = GLES20.glCreateShader(type);
// add the source code to the shader and compile it
GLES20.glShaderSource(shader, shaderCode);
GLES20.glCompileShader(shader);
return shader;
}
public void onSurfaceCreated(GL10 unused, EGLConfig config) {
initShapes();
// Set the background frame color
GLES20.glClearColor(0f, 0f, 0f, 1.0f);
int vertexShader = loadShader(GLES20.GL_VERTEX_SHADER, vertexShaderCode);
int fragmentShader = loadShader(GLES20.GL_FRAGMENT_SHADER, fragmentShaderCode);
mProgram = GLES20.glCreateProgram(); // create empty OpenGL Program
GLES20.glAttachShader(mProgram, vertexShader); // add the vertex shader to program
GLES20.glAttachShader(mProgram, fragmentShader); // add the fragment shader to program
GLES20.glLinkProgram(mProgram); // creates OpenGL program executables
// get handle to the vertex shader's vPosition member
maPositionHandle = GLES20.glGetAttribLocation(mProgram, "vPosition");
}
谢谢!
最佳答案
正如我在上面的评论中所说:
您似乎希望将 glVertexAttribPointer 调用的大小参数从 4 更改为 3,因为您没有使用 4d 向量 (XYZW)。
干杯
关于Android GLES20.glDrawArrays(GLES20.GL_LINE_LOOP ...),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10178474/
关闭。这个问题需要debugging details .它目前不接受答案。 编辑问题以包含 desired behavior, a specific problem or error, and th
我正在使用 GL_LINE_LOOP 在 C 和 openGL 中绘制一个圆!我可以用颜色填充圆圈吗? 如果需要,这是我正在使用的代码: const int circle_points
我在使用这些代码在屏幕上渲染许多圆圈时遇到问题。 float degree = 0; unsigned int ctr = 0; for(int xi = -3200; xi -4800; yi-=
我在 GLFW 中使用 OpenGL 3.3。问题是 GL_LINE_STRIP 和 GL_LINE LOOP 给出了相同的结果。 这是二维坐标数组: GLfloat vertices[] =
这可能是一个非常新手的问题,但我找不到答案。 使用来自 google 的简单教程 (http://developer.android.com/resources/tutorials/opengl/op
我正在开发一个应该允许用户创建多边形的程序,然后为程序指定随机点以检查它们是否在多边形内。 GLint vert[100][2]; int width = 400, height = 600, n =
我正在使用 OpenGL ES 2.0 GL_LINE_LOOP 绘制圆圈,我想让它适本地加粗,但是当我使用 glLineWidth 时,我得到了不好的结果,圆圈的外侧被打破了,这里是屏幕截图: 如何
我是一名优秀的程序员,十分优秀!