2014-07-08 5 views
0

저는 OpenGL을 사용하여 CAD/CAM 소프트웨어와 같은 것을 만들고 있습니다.
처음에는 간단히 glBegin과 glEnd를 사용했으나 잘 작동하지만 정점이 많으면 느려지므로 검색을 수행하여 vertexbuffer라는 것을 발견했습니다.
그래서는 C#으로 작성된 것 테스트 및왜 vertexbuffer를 사용할 때 그래디언트 컬러 선이 생깁니 까?

//create a new buffer 
gl.BindBuffer(OpenGL.GL_ARRAY_BUFFER, vertexId); 
gl.BufferData(OpenGL.GL_ARRAY_BUFFER, vertexSize + colorSize, new IntPtr(0),OpenGL.GL_STREAM_DRAW); 
gl.VertexPointer(2, OpenGL.GL_FLOAT, 0, new IntPtr(0)); 
gl.ColorPointer(3, OpenGL.GL_UNSIGNED_BYTE, 0, new IntPtr(vertexSize)); 
//update vertex buffer 
public int UpdateVertexAt(float[] segments,int offset) 
    { 
     int len = segments.Length * sizeof(float); 
     unsafe 
     { 
      fixed(float * p = segments) 
      { 
       IntPtr ptr = new IntPtr(p); 
       gl.BufferSubData(OpenGL.GL_ARRAY_BUFFER, offset, len, ptr); 
      } 
     } 
     c += segments.Length/2; 
     return len; 
    } 
//update color 
public int UpdateColorAt(byte[] rgb, int offset) 
    { 
     // gl.BindBuffer(OpenGL.GL_ARRAY_BUFFER, colorId); 
     unsafe 
     { 
      fixed (byte* p = rgb) 
      { 
       IntPtr ptr = new IntPtr(p); 
       gl.BufferSubData(OpenGL.GL_ARRAY_BUFFER, offset, rgb.Length, ptr); 
      } 
     } 
     return rgb.Length; 
    } 
//draw scene 
    public void Flush() 
    { 
     gl.EnableClientState(OpenGL.GL_VERTEX_ARRAY); 
     gl.EnableClientState(OpenGL.GL_COLOR_ARRAY); 
     gl.DrawArrays(OpenGL.GL_LINES, 0, 2 * c); 
     gl.DisableClientState(OpenGL.GL_COLOR_ARRAY); 
     gl.DisableClientState(OpenGL.GL_VERTEX_ARRAY); 
    } 

문제가 나는 그것이 werid보고하지 올바른 위치에 선을 그리기 시작하고, 내가 처음 선을 그릴 때 dosent을 sharpgl하는 간단한 프로그램을 만들어 쇼 그러나 나는

enter image description here

내가 gl.GetBufferSubData를 사용하여 정점과 색상을 확인하고 모든 일이 잘 보이지만, 같은 sconed 라인과 apperes을 그릴 때 때 사용 gl.ColorPointer (3, OpenGL.GL_UNSIGNED_BYTE , 0, 새로운 IntPtr (0)), 라인 의 자리에 그려진 모든 것은 색을 제외하고 잘, 그리고 나는 그것의 색상으로 정점을 읽고 있기 때문에

enter image description here

그래서 내가 잘못 여기서 뭐하는거야 생각?

답변

0

문제가 발견되었습니다. 선의 시작점과 끝점에 그라디언트 색상을 유발하는 원인이 1 색이었습니다.

관련 문제