2014-02-12 3 views
1

glLineWidth 대신 ANGLE을 1.0 이상 사용하지 않는 선을 그릴 선을 작성하고 있는데, 내 선을 원합니다 Windows에서 동일한 두께를 유지해야합니다. 지금 데스크톱 OpenGL에서 실행 중입니다.GLSL 버텍스 쉐이더는 gl_Vertex에 대해 언급하지 않으면 잘못된 결과를 나타냅니다.

attribute vec3 a_startPosition; 
attribute vec3 a_endPosition; 
attribute float a_choice; 
attribute float a_dir; 
uniform mat4 u_mvpMatrix; 
uniform float u_width; 
uniform vec2 u_viewDims; 

void main() 
{ 
    vec4 start = u_mvpMatrix*vec4(a_startPosition, 1.0); 
    vec4 end = u_mvpMatrix*vec4(a_endPosition, 1.0); 

    //gl_Vertex; 

    vec2 slope = normalize(end.xy - start.xy); 
    slope = vec2(slope.y, -slope.x); 
    vec2 scale = u_width/u_viewDims; 

    if (a_choice == 0.0) 
     gl_Position = vec4(start.xy + a_dir*scale*slope.xy*start.w, start.zw); 
    else 
     gl_Position = vec4(end.xy + a_dir*scale*slope.xy*end.w, end.zw); 
} 

내가 gl_Vertex가 사용되지 않는이, 주석있는 것으로 확인 다음과 같이

버텍스 쉐이더 소스입니다.

int width, height; 
glfwGetFramebufferSize(m_window, &width, &height); 

glUseProgram(m_shaders[Shader_WideLine]->id()); 
GLint shaderid = m_shaders[Shader_WideLine]->id(); 

GLint coloc = glGetUniformLocation(shaderid, "Color"); 
GLint dimloc = glGetUniformLocation(shaderid, "u_viewDims"); 
GLint widthloc = glGetUniformLocation(shaderid, "u_width"); 
GLint mvploc = glGetUniformLocation(shaderid, "u_mvpMatrix"); 
GLint modelviewloc = glGetUniformLocation(shaderid, "u_modelview"); 
GLint projloc = glGetUniformLocation(shaderid, "u_projection"); 

GLint dirloc = glGetAttribLocation(shaderid, "a_dir"); 
GLint startloc = glGetAttribLocation(shaderid, "a_startPosition"); 
GLint endloc = glGetAttribLocation(shaderid, "a_endPosition"); 
GLint chloc = glGetAttribLocation(shaderid, "a_choice"); 

////////// 
//Set Uniforms 
////////// 
glUniform1f(widthloc, 10); 
glUniform2f(dimloc, width, height); 
glUniform4f(coloc, 0.101f, 0.558f, 0.109f, 1.f); 

glm::mat4 modelview; 
glm::mat4 projection; 
glGetFloatv(GL_MODELVIEW_MATRIX, glm::value_ptr(modelview)); 
glGetFloatv(GL_PROJECTION_MATRIX, glm::value_ptr(projection)); 

glm::mat4 mvp = projection * modelview; 
glUniformMatrix4fv(mvploc, 1, GL_FALSE, glm::value_ptr(mvp)); 

int numpts = 4; 
GLfloat v[4][3] = { 
    {0,1,0}, 
    {0,0,0}, 
    {1,0,0}, 
    {1,1,0} 
}; 
////////// 
// Draw (attributes) 
////////// 
glBegin(GL_TRIANGLE_STRIP); 

glNormal3d(0.0, 0.0, 1.0); 

for(int i=0; i<numpts-1; i++) 
{ 
    glVertexAttrib3fv(startloc, v[i]); 
    glVertexAttrib3fv(endloc, v[i+1]); 

    glVertexAttrib1f(chloc, 0); 

    glVertexAttrib1f(dirloc, -1.0f); 
    glVertex3d(0,0,0); 

    glVertexAttrib1f(dirloc, 1.0f); 
    glVertex3d(0,0,0); 

    glVertexAttrib1f(chloc, -1); 
    glVertexAttrib1f(dirloc, -1.0f); 
    glVertex3d(0,0,0); 
    glVertexAttrib1f(dirloc, 1.0f); 
    glVertex3d(0,0,0); 

} 

glEnd(); 
glUseProgram(0); 

그래서 나는의 폭 (1,1,0)에서 (1,0,0)에서 (0,0,0)에서 (0,1,0)에서 선을 그리는 것을 시도하고있다 10 픽셀. 다음 이미지에서 참조 용으로 원점을 중심으로 2x2x2 와이어 큐브입니다. 내가 gl_Vertex 주석을 제거하면이 Incorrect lines

의 예상치 못한 결과를 얻을 발표로 불리는

; 셰이더에서 사용되지 않지만 참조 될 수 있도록이 예상 결과를 얻습니다. Correct lines

왜 이런 일이 발생할 수 있습니까?

답변

2

gl_ModelViewProjectionMatrix은 유효한 ES 2.0 버텍스 쉐이더 내장 변수가 아닙니다.

유니폼을 통해 MVP를 통과해야합니다.

+0

좋아, 유니폼을 통해 MVP로 전달하고 잘못된 코드를 설명하는 그림을 추가했습니다. – CandleEnds

관련 문제