- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我今天刚刚开始学习 OpenGL ES(我已经了解 WebGL 和 OpenGL),以便我可以继续我在 reddit 上发布的游戏项目 (reddit.com/r/gameideas/comments/3dsy8m/revolt/),并尝试移植我的 OBJLoader,但遇到了一个我无法解决的问题,想知道是否有人知道出了什么问题。我猜测它通常在 OpenGL 中默认启用,但在 OpenGL ES 中则不然。
这是扭曲的图像:
这是重要的代码: http://pastebin.com/1CgsJv21
public class GLMesh{
public static Activity activity;
private FloatBuffer verticesBuffer;
private FloatBuffer texcoordsBuffer;
private FloatBuffer normalsBuffer;
private float[] vertices;
private float[] texcoords;
private float[] normals;
private int numOfVertices;
public GLMesh(){
numOfVertices = 0;
}
public void setVertices(float[] vertices) {
this.vertices = vertices;
}
public void setTexcoords(float[] texcoords) {
this.texcoords = texcoords;
}
public void setNormals(float[] normals) {
this.normals = normals;
}
private static FloatBuffer asBuffer(float[] data){
ByteBuffer vbb = ByteBuffer.allocateDirect(data.length * 4);
vbb.order(ByteOrder.nativeOrder());
FloatBuffer outBuffer = vbb.asFloatBuffer();
outBuffer.put(data);
outBuffer.position(0);
return outBuffer;
}
public void load(String path){
// Define List of Vertices
ArrayList<GLVec3f> rVerts = new ArrayList<>();
ArrayList<GLVec2f> rTexs = new ArrayList<>();
ArrayList<GLVec3f> rNorms = new ArrayList<>();
ArrayList<GLVec3f> rTris = new ArrayList<>();
// Add Null Vertex
rVerts.add(null);
rTexs.add(null);
rNorms.add(null);
try{
InputStream in = activity.getAssets().open(path);
InputStreamReader isr = new InputStreamReader(in, "UTF-8");
BufferedReader br = new BufferedReader(isr);
String line;
while((line = br.readLine()) != null){
String[] splitLine = line.split(" ");
switch(splitLine[0]){
case "v":
float vX = Float.parseFloat(splitLine[1]);
float vY = Float.parseFloat(splitLine[2]);
float vZ = Float.parseFloat(splitLine[3]);
GLVec3f vertex = new GLVec3f(vX, vY, vZ);
rVerts.add(vertex);
break;
case "vt":
float tS = Float.parseFloat(splitLine[1]);
float tT = Float.parseFloat(splitLine[2]);
GLVec2f texcoord = new GLVec2f(tS, tT);
rTexs.add(texcoord);
break;
case "vn":
float nX = Float.parseFloat(splitLine[1]);
float nY = Float.parseFloat(splitLine[2]);
float nZ = Float.parseFloat(splitLine[3]);
GLVec3f normal = new GLVec3f(nX, nY, nZ);
rNorms.add(normal);
break;
case "f":
String[] vtn1 = splitLine[1].split("/");
String[] vtn2 = splitLine[2].split("/");
String[] vtn3 = splitLine[3].split("/");
float vIA = Float.parseFloat(vtn1[0]);
float vIB = Float.parseFloat(vtn2[0]);
float vIC = Float.parseFloat(vtn3[0]);
float tIA = Float.parseFloat(vtn1[1]);
float tIB = Float.parseFloat(vtn2[1]);
float tIC = Float.parseFloat(vtn3[1]);
float nIA = Float.parseFloat(vtn1[2]);
float nIB = Float.parseFloat(vtn2[2]);
float nIC = Float.parseFloat(vtn3[2]);
GLVec3f indexA = new GLVec3f(vIA, tIA, nIA);
GLVec3f indexB = new GLVec3f(vIB, tIB, nIB);
GLVec3f indexC = new GLVec3f(vIC, tIC, nIC);
rTris.add(indexA);
rTris.add(indexB);
rTris.add(indexC);
break;
}
}
}
catch(IOException e){
System.err.printf("Failed to fetch mesh @ %s", path);
return;
}
// Put Data into useful format
float[] verts = new float[rTris.size() * 3];
float[] texs = new float[rTris.size() * 2];
float[] norms = new float[rTris.size() * 3];
int i = 0;
// Get rid of need for indices
for(GLVec3f index: rTris){
// Collect Vertex Indices
int vI = (int) index.x;
int tI = (int) index.y;
int nI = (int) index.z;
// Collect Vertex Info
GLVec3f v = rVerts.get(vI);
GLVec2f t = rTexs.get(tI);
GLVec3f n = rNorms.get(nI);
// Populate arrays
verts[i * 3 + 0] = v.x;
verts[i * 3 + 1] = v.y;
verts[i * 3 + 2] = v.z;
texs[i * 2 + 0] = t.x;
texs[i * 2 + 1] = t.y;
norms[i * 3 + 0] = n.x;
norms[i * 3 + 1] = n.y;
norms[i * 3 + 2] = n.z;
// Increment Counter
i++;
}
numOfVertices = verts.length;
// Populate Mesh
setVertices(verts);
setTexcoords(texs);
setNormals(norms);
compile();
}
public void compile(){
verticesBuffer = asBuffer(vertices);
texcoordsBuffer = asBuffer(texcoords);
normalsBuffer = asBuffer(normals);
}
public void draw(GL10 gl){
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
gl.glEnableClientState(GL10.GL_NORMAL_ARRAY);
gl.glVertexPointer(3, GL10.GL_FLOAT, 0, verticesBuffer);
gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, texcoordsBuffer);
gl.glNormalPointer(GL10.GL_FLOAT, 0, normalsBuffer);
gl.glDrawArrays(GL10.GL_TRIANGLES, 0, numOfVertices);
gl.glDisableClientState(GL10.GL_NORMAL_ARRAY);
gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
}
}
最佳答案
第三个参数传递给glDrawArrays是要渲染的索引(例如顶点)的数量。因此 numOfVertices 应该设置为已写入 verts 的顶点数,而不是 verts 中的 float :
numOfVertices = i;
关于java - Opengl es 与 obj 加载器失真,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31508331/
我正在尝试更改通过AVAudioPlayer播放的声音文件的速率。它可以工作,但是有很多伪像,尤其是当我放慢速度时。我很高兴速率变化保持相同的音调,但是似乎有麻烦,尤其是持续的音符。 直到我用均衡,压
我正在开发一个需要同步声音的安卓音频应用。 我正在尝试合并两个声音缓冲器,但在大幅度时出现失真。这就是我正在做的: for(int i=0;i>8); } 缓冲区使用:
我正在尝试使用 MediaRecorder 从相机录制视频。这是一个代码 fragment 剪断.. mr.setAudioSource( MediaRecorder.AudioSource.MI
我想找点乐子看看 Canvas 。画一个盒子似乎很容易,所以我几乎从 mozilla 开发者网站上复制了一个例子。你可以在这里看到它:http://jsfiddle.net/Wolfy87/DZBwp
我有一个程序,可以简单地绘制一个立方体。当应用旋转缩放等变换时,程序可以工作。当我尝试应用任何透视矩阵(例如透视、平截头体或正交)时,立方体会以未定义的方式变得非常扭曲。我感到困惑的是为什么该程序在使
在 CSS 和 HTML 中,向下滚动时如何避免背景图像失真? 我的代码大纲如下:HTML * { margin : 0; background-image : url("im
我在 Qt 中旋转图像时遇到了一些问题。每次我用 QPainter 旋转我的图像它变得越来越扭曲。这是初始图像: 经过一些迭代后它变成: 这是我的代码: void Ship::Move(int x,
我正在尝试将 UILabel 旋转 45 度。我将 transform 属性设置为 CGAffineTransformMakeRotation(M_PI * 0.25) 但是当我这样做时,UILabe
当我添加一堆 (20-40) 个样本同时播放和重叠时,有时它会开始失真,然后开始出现一些波动、振荡和咔哒声。当样本正在播放时应用程序崩溃时会发出类似的声音 - 听起来像是突然、嘎吱作响的停止。 请注意
我想使用 amCharts Javascript 库显示我的用户排名。用户排名是这样的(很好,没问题): 问题是如果我有两个相同的配置文件名称(例如,如果我有两个 Sara 名称作为配置文件名称或什至
在 TornadoFX 中使用 SVG 时遇到奇怪的问题。我有一些 SVG 字符串存储在一个枚举中,我在程序中用作背景图像。当我在在线查看器中查看完全相同的 SVG 路径时,没有失真并且显示正确: 但
我使用录音机(Google Play 上的 AudioRec)。 我可以选择adjust the gain with [-20dB, + 20dB]范围。 它在我的手机上运行得很好,但用户使用连接到其
Logo 、搜索栏、购物车、登录和注册未在同一行对齐。 当我尝试查看移动 View 时,出现失真 搜索栏和其他东西搞砸了 在移动 View 中,点击菜单折叠按钮没有任何反应。 这是我的代码:
我仍然是 OpenGL 的初学者。我正在尝试使用着色器在 1280 x 720 的屏幕上绘制一个完美的正方形。 我使用的是 OpenGL 核心配置文件 3.3 版。当我试图在 1280 x 720 中
我的应用程序生成的电子邮件在浏览器(示例 chrome)中打开时可以完美打开。但是当在 Microsoft Outlook 中打开同一封电子邮件时,它会严重变形(例如文本不可见,按钮文本被换行)。任何
我对使用 OpenGL ES 2.0 还很陌生。我也在使用 iPhone 和 GLM 数学库。正如我所提到的,我经常使用本教程:http://tomdalling.com/blog/modern-op
我最初是在考虑 CoreImage 的情况下解决这个问题的(因为我还需要进行面部识别),但我意识到,不幸的是,CI 失真滤镜尚未包含在 iPhone 中。 我试图深入研究 GLImageProcess
我已经使用 twitter-bootstrap gem 来制作商店应用程序。在我添加 activeadmin gem 之前它工作正常。 admin主页的 View 有一行: 店铺名称 和 "trans
我拍了一张照片,然后用这张照片初始化了一个 UIImageView 对象。唯一的问题是,当我拍照时,照片是使用完整的 iPhone 屏幕(纵向)拍摄的。 使用这张照片初始化的 UIImageView
我正在使用 AVAssetWriter 将一系列图像编码为电影文件,遵循 Zoul 在这里的回答:How do I export UIImage array as a movie? . 简而言之我的流
我是一名优秀的程序员,十分优秀!