2017-05-17 3 views
1

私はLWJGLといくつかのグラフィックカード(AMD Radeonシリーズ)でアプリケーションを作成しています。何か問題が起き、大きな三角形しか画面に表示されないため、頂点シェーダでノーマルの名前を変更できません。LWJGLシェーダノーマルのエイリアス

#version 150 

//our attributes 
in vec3 a_position; 
in vec2 a_textureCoords; 
in vec3 normal; 

//send the color out to the fragment shader 
out vec2 vTextureCoords; 

void main(void) 
{ 
    normal; 
    gl_Position = vec4(a_position, 1.0); 
    vTextureCoords = a_textureCoords; 
} 

すべてが正常に動作し、それがあるべきようメッシュが表示されます。私はこれにシェーダを変更した場合

#version 150 

//our attributes 
in vec3 a_position; 
in vec2 a_textureCoords; 
in vec3 a_normal; //Here is an error 

//send the color out to the fragment shader 
out vec2 vTextureCoords; 

void main(void) 
{ 
    a_normal; 
    gl_Position = vec4(a_position, 1.0); 
    vTextureCoords = a_textureCoords; 
} 

:ここに私のコードです。それは普通ですか? そして、私のbind属性機能:

//Before 
GL20.glBindAttribLocation(s_programID, 2, "a_normal"); 

//After 
GL20.glBindAttribLocation(s_programID, 2, "normal"); 

編集

は、シェーダ内の場所を属性:

//Before 
a_normal 0 
a_position 1 
a_textureCoords 2 

//After 
a_position 0 
a_textureCoords 1 
normal 2 
+0

which opengl vあなたは少なくとも目標を設定していますか? – elect

+0

私の最小はOpenGL 3.2です – Dragomirus2

答えて

1

私はこのような何かを書くためにあなたをお勧めしたい:

#version 150 

#define POSITION 0 
#define TEX_COORD 1 
#define NORMAL 2 

//our attributes 
layout (location = POSITION) in vec3 a_position; 
layout (location = TEX_COORD) in vec2 a_textureCoords; 
layout (location = NORMAL) in vec3 a_normal; 

//send the color out to the fragment shader 
out vec2 vTextureCoords; 

void main(void) 
{ 
    a_normal; 
    gl_Position = vec4(a_position, 1.0); 
    vTextureCoords = a_textureCoords; 
} 

そして、 javaの場合、次のようなものがあります。

あなたがプログラム

Psとを結ぶ後またはglGetAttribLocationglBindAttribLocationに覚えて、あなたのglVertexAttribPointerglEnableVertexAttribute機能それ以外の場合は

で使用する

interface Semantic { 

    interface Attr { 

     int POSITION = 0; 
     int TEX_COORD = 1; 
     int NORMAL = 2; 
    } 
} 

:それで有用な何かをすることを忘れないでくださいa_normalさもなければ、glslコンパイラはそれを完全に取り除くことによって最適化します