1

Recently, I've been trying to learn how to use OpenGL ES 2.0 and GLKit to create simple 2D games. I've been following this tutorial by Ray Wenderlich and it's been very helpful so far. However, upon profiling my project (and his) for leaks I found that GLKBaseEffect's prepareToDraw: (specifically, GLKShaderBlockNode's copyWithZone) is leaking everywhere - I'm using ARC, by the way. After searching around quite a bit it seems that this is a bug in GLKBaseEffect and that I can't do anything about it. Is this true? The only solution I've found suggested is scrapping GLKBaseEffect entirely.

If that's the case, I have to roll my own custom vertex and fragment shaders as a result. However, I have no idea how to do this. I would appreciate any resources or help on creating custom shaders and adapting the code in the above tutorial to use those instead.

Thank you very much for your time. :)

4

2 に答える 2

1

まあ、かなりの先延ばしの後、私は弾丸を噛んでそれをすることにしました。リークはなくなりましたが、動作させるのにしばらく時間がかかりました。OpenGL ES 2.0 for iPhoneの第4章を読み、頂点シェーダーとフラグメントシェーダー、およびそれらをコンパイルしてリンクする方法について学びました。それがどのように機能するかを理解した後、私はGLProgramすべての定型文を処理するために著者のヘルパークラスを私のプロジェクトに入れ、すぐに作業できるようになりました。次に、ここにあるものとほぼ同じ2つのシェーダーを作成しました。

私は彼の指示に従って属性と均一な場所を取得し、それらを構造体に格納し、初期化されたときにそれらをすべて一度にスプライトオブジェクトに渡しました。次に、レンダリングするときに、以前に使用していたときと同じように、属性のすべての情報を渡しましたGLKBaseEffect。唯一の違いは(テクスチャをテクスチャユニットに手動でバインドすることを除いて) 、プロパティを設定する代わりに、自分modelviewMatrixprojectionMatrixユニフォームを渡す必要があることでした。GLKBaseEffect

于 2013-01-17T22:39:11.063 に答える
1

For starters, in XCode do File->New Project and select "OpenGL Game".

Run it if you choose, you get 2 cubes going around each other.

Take a look at shader.fsh and shader.vsh. In viewcontroller.m, examine compilerShader, linkProgram and validateProgram (these compile the shader).

Examining that sample app should be enough to get you "in the door" on how to get a shader running, and from that point forward search for some OpenGL ES 2.0 shader tutorials or check out some of sample apps in the Apple code library.

Note: Going from Apple's built-in easy effects to shaders is a significantly wide "canyon".

于 2013-01-13T05:13:29.553 に答える