这可能是一个noob问题,但是,我还没有找到合适的答案:
我在OpenGL ES中有一个对象(实际上是Blender的UV映射导出),我想对它应用两个纹理.确切地说,我有一个像地球一样的球体,我想在它上面添加两种纹理(白天和夜晚).
我曾想过通过alpha映射,应该可以在运行时以编程方式淡化一个纹理并显示另一个纹理,这样我的地球就可以成为地球的真实模拟.我有它背后的数学,即为对象的每个面创建alpha映射不是问题.
任何提示/指示如何实现这一目标?
谢谢
我正在寻找一些示例代码或教程,以设置最基本的opengl es应用程序.
例如,只需在renderloop中执行glClear().
我已经在网上搜索,但我找到的所有内容都已过时或太多太复杂.
谢谢!
我是一名自学成才的程序员,拥有绝对零3D编程经验.
我的一个客户与我有关的想法是一个需要OpenGL ES 2.0的iPhone应用程序,因为它本身就是复杂的3D结构和动画.
我从哪里开始(虽然很长)的OpenGL ES能力之旅?
我愿意投入大量的时间和精力去学习,如果我能够得到一些指示,我应该从哪里开始和期待什么,这将是非常棒的!
嘿 - 刚刚开始尝试将一些openGL放入我的iphone应用程序中,并为这段代码遇到了这个错误:
static const GLfloat pyramidVertices[] = {
0.0f, 1.0f, 0.0f,
-1.0f, -1.0f, 1.0f,
1.0f, -1.0f, 1.0f,
1.0f, -1.0f, -1.0f,
-1.0f, -1.0f, -1.0f
};
Run Code Online (Sandbox Code Playgroud)
我不包括我应该做的事情吗?没有这一切,一切都很好.
干杯!
根据c ++中的例子,我曾经尝试使用opengl es在android中构建3d立方体,但是经过几次,结果很失望!所以我想知道,谁曾经做过它?你能给我一些建议吗?提前致谢!
我试图将 GLSurfaceView 与其他 UI 元素一起设置在 xml 布局上,但在 LogCat 中不断出现错误,导致类 com.vi.cubo01.MyGLSurfaceView 膨胀。
这是java代码:
super.onCreate(savedInstanceState);
mGLSurfaceView = (MyGLSurfaceView) findViewById(R.id.vistaGLSuperficie)
setContentView(R.layout.activity_main);
}
@Override
protected void onResume()
{
super.onResume();
mGLSurfaceView = (MyGLSurfaceView) findViewById(R.id.vistaGLSuperficie);
mGLSurfaceView.onResume();
}
@Override
protected void onPause()
{
super.onPause();
mGLSurfaceView = (MyGLSurfaceView) findViewById(R.id.vistaGLSuperficie);
mGLSurfaceView.onPause();
}
class MyGLSurfaceView extends GLSurfaceView {
public MyGLSurfaceView(Context context) {
super(context);
setEGLContextClientVersion(2);
setRenderer(new CustomRenderer());
}
}
Run Code Online (Sandbox Code Playgroud)
和 XML:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" >
<requestFocus />
</EditText>
<EditText
android:id="@+id/editText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" …Run Code Online (Sandbox Code Playgroud) 尝试让 2 个纹理单元工作。
@Override
public void onDrawFrame(GL10 gl) {
//Clear the Rendering Surface
glClear(GL_COLOR_BUFFER_BIT);
multiplyMM(viewProjectionMatrix, 0, projectionMatrix, 0, viewMatrix, 0);
positionTableInScene();
textureProgram.useProgram();
textureProgram.setUniforms(modelViewProjectionMatrix, texture_b, texture_r);
table.bindData(textureProgram);
table.draw();
...
}
Run Code Online (Sandbox Code Playgroud)
纹理程序:
public class TextureShaderProgram extends ShaderProgram {
//Uniform locations
private final int uMatrixLocation;
private final int uTextureUnit0Location;
private final int uTextureUnit1Location;
//Attribute locations
private final int aPositionLocation;
private final int aTextureCoordinatesLocation;
public TextureShaderProgram(Context context){
super(context, R.raw.texture_vertex_shader, R.raw.texture_fragment_shader);
//Retrieve uniform locations for the shader program.
uMatrixLocation = glGetUniformLocation(program, U_MATRIX);
uTextureUnit0Location = glGetUniformLocation(program, …Run Code Online (Sandbox Code Playgroud) 我的 OpenGL ES 应用程序无法运行。我使用 SDL 进行窗口管理,它保存上下文。环顾四周后,我注意到顶点着色器和片段着色器在调试器上显示为 0。连程序都是0。这会是一个原因吗?我按照着色器编译代码并将代码链接到之前制作的模板。
如果是的话,有什么问题吗?这是代码:
GLuint ShaderHelper::compileShader(GLenum type, std::string fileName) {
std::string fileContents;
std::ifstream fin;
std::string path;
// Getting the necessary path...
// These are abstractions for getting file contents
// from the main bundle.
if (type == GL_VERTEX_SHADER) {
FileOpener opener;
path = opener.retriveFileFromBundle(fileName, "vsh");
} else if (type == GL_FRAGMENT_SHADER) {
FileOpener opener;
path = opener.retriveFileFromBundle(fileName, "fsh");
} else {
std::cout << "ERROR: Invalid shader type at filename " << fileName << std::endl;
exit(1);
} …Run Code Online (Sandbox Code Playgroud) 如何使用 OES_texture_float 扩展?我不明白有必要指定函数 texImage2D 的参数。
var fb=gl.createFramebuffer();
gl.bindFramebuffer(gl.FRAMEBUFFER, fb);
var rb=gl.createRenderbuffer();
gl.bindRenderbuffer(gl.RENDERBUFFER, rb);
gl.renderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_COMPONENT16,size[0],size[1]);
gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT,gl.RENDERBUFFER, rb);
var texture=gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, texture);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, size[0], size[1],0, gl.RGBA, ???, ???);
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0,gl.TEXTURE_2D, texture, 0);
Run Code Online (Sandbox Code Playgroud)
你需要写什么而不是“???”
我正在尝试深入研究着色器语言,为我的 iOS 9+ / Sprite-Kit 应用程序编写一些简单的片段着色器。但我已经坚持尝试调用一个简单的函数。这是我的着色器代码,我使用 Sprite-Kit 中的 SKShader 对象将其绑定到 Swift 2.2 应用程序中:
void main(void) {
gl_FragColor = getColor();
}
float getColor() {
return vec4(1.0, 1.0, 1.0, 1.0);
}
Run Code Online (Sandbox Code Playgroud)
当尝试编译时,我收到以下错误:
2016-06-22 12:53:35.606 ShaderTestGLSL[8425:2478215] Jet: Error Domain=MTLLibraryErrorDomain Code=3 "Compilation failed:
program_source:8:12: error: use of undeclared identifier 'getColor'
return getColor();
^
program_source:12:7: warning: no previous prototype for function 'getColor'
float getColor() {
^
program_source:13:16: error: excess elements in scalar initializer
return vec4(1.0, 1.0, 1.0, 1.0);
^ ~~~~~~~~~~~~~~~~
" UserInfo={NSLocalizedDescription=Compilation failed:
program_source:8:12: error: …Run Code Online (Sandbox Code Playgroud)