Bläddra i källkod

Add draw_lines() method

Daniele Bartolini 12 år sedan
förälder
incheckning
85e1751be7
3 ändrade filer med 20 tillägg och 0 borttagningar
  1. 1 0
      src/renderers/Renderer.h
  2. 18 0
      src/renderers/gl/GLRenderer.cpp
  3. 1 0
      src/renderers/gl/GLRenderer.h

+ 1 - 0
src/renderers/Renderer.h

@@ -190,6 +190,7 @@ public:
 
 	virtual void render_point_buffer(const VertexBuffer* buffer) = 0;
 
+	virtual void draw_lines(const float* vertices, const float* colors, uint32_t count) = 0;
 	virtual void render_triangles(const float* vertices, const float* normals, const float* uvs, const uint16_t* indices, uint32_t count) = 0;
 
 	// FIXME

+ 18 - 0
src/renderers/gl/GLRenderer.cpp

@@ -744,6 +744,24 @@ void GLRenderer::set_light_attenuation(uint32_t light, float constant, float lin
 	glLightf(GL_LIGHT0 + light, GL_QUADRATIC_ATTENUATION, quadratic);
 }
 
+//-----------------------------------------------------------------------------
+void GLRenderer::draw_lines(const float* vertices, const float* colors, uint32_t count)
+{
+	glBindBuffer(GL_ARRAY_BUFFER, 0);
+	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
+
+	glEnableClientState(GL_VERTEX_ARRAY);
+	glEnableClientState(GL_COLOR_ARRAY);
+
+	glVertexPointer(3, GL_FLOAT, 0, vertices);
+	glColorPointer(4, GL_FLOAT, 0, colors);
+
+	glDrawArrays(GL_LINES, 0, count);
+
+	glDisableClientState(GL_COLOR_ARRAY);
+	glDisableClientState(GL_VERTEX_ARRAY);
+}
+
 //-----------------------------------------------------------------------------
 void GLRenderer::render_triangles(const float* vertices, const float* normals, const float* uvs, const uint16_t* indices, uint32_t count)
 {

+ 1 - 0
src/renderers/gl/GLRenderer.h

@@ -116,6 +116,7 @@ public:
 	void				render_vertex_index_buffer(const VertexBuffer* vertices, const IndexBuffer* indices);
 	void				render_point_buffer(const VertexBuffer* buffer);
 
+	void				draw_lines(const float* vertices, const float* colors, uint32_t count);
 	void				render_triangles(const float* vertices, const float* normals, const float* uvs, const uint16_t* indices, uint32_t count);
 
 	TextureId			load_texture(TextureResource* texture);