void GLInstancingRenderer::drawLines(const float* positions, const float color[4], int numPoints, int pointStrideInBytes, const unsigned int* indices, int numIndices, float lineWidthIn) { float lineWidth = lineWidthIn; b3Clamp(lineWidth,(float)lineWidthRange[0],(float)lineWidthRange[1]); glLineWidth(lineWidth); glBindBuffer(GL_ARRAY_BUFFER, m_data->m_vbo); b3Assert(glGetError() ==GL_NO_ERROR); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D,0); b3Assert(glGetError() ==GL_NO_ERROR); glUseProgram(linesShader); glUniformMatrix4fv(lines_ProjectionMatrix, 1, false, &m_data->m_projectionMatrix[0]); glUniformMatrix4fv(lines_ModelViewMatrix, 1, false, &m_data->m_viewMatrix[0]); glUniform4f(lines_colour,color[0],color[1],color[2],color[3]); // glPointSize(pointDrawSize); glBindVertexArray(linesVertexArrayObject); b3Assert(glGetError() ==GL_NO_ERROR); glBindBuffer(GL_ARRAY_BUFFER, linesVertexBufferObject); { glBufferData(GL_ARRAY_BUFFER, numPoints*pointStrideInBytes, 0,GL_DYNAMIC_DRAW); glBufferSubData(GL_ARRAY_BUFFER, 0, numPoints*pointStrideInBytes, positions); b3Assert(glGetError() ==GL_NO_ERROR); glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBuffer(GL_ARRAY_BUFFER, linesVertexBufferObject); glEnableVertexAttribArray(0); b3Assert(glGetError() ==GL_NO_ERROR); int numFloats = 3; glVertexAttribPointer(0, numFloats, GL_FLOAT, GL_FALSE, pointStrideInBytes, 0); b3Assert(glGetError() ==GL_NO_ERROR); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, linesIndexVbo); int indexBufferSizeInBytes = numIndices*sizeof(int); glBufferData(GL_ELEMENT_ARRAY_BUFFER, indexBufferSizeInBytes, NULL, GL_DYNAMIC_DRAW); glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, indexBufferSizeInBytes, indices); glDrawElements(GL_LINES, numIndices, GL_UNSIGNED_INT, 0); } glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); glBindBuffer(GL_ARRAY_BUFFER, 0); // for (int i=0;i<numIndices;i++) // printf("indicec[i]=%d]\n",indices[i]); b3Assert(glGetError() ==GL_NO_ERROR); glBindVertexArray(0); b3Assert(glGetError() ==GL_NO_ERROR); glPointSize(1); b3Assert(glGetError() ==GL_NO_ERROR); glUseProgram(0); }
double convertSensor(int inputV, int minV, int maxV) { b3Clamp(inputV, minV, maxV); double outVal = (double)inputV; double b = (outVal - (double)minV) / float(maxV - minV); return (b); }
void GLInstancingRenderer::drawLine(const float from[4], const float to[4], const float color[4], float lineWidth) { b3Assert(glGetError() ==GL_NO_ERROR); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D,0); b3Assert(glGetError() ==GL_NO_ERROR); glUseProgram(linesShader); b3Assert(glGetError() ==GL_NO_ERROR); glUniformMatrix4fv(lines_ProjectionMatrix, 1, false, &m_data->m_projectionMatrix[0]); glUniformMatrix4fv(lines_ModelViewMatrix, 1, false, &m_data->m_viewMatrix[0]); glUniform4f(lines_colour,color[0],color[1],color[2],color[3]); b3Assert(glGetError() ==GL_NO_ERROR); const float vertexPositions[] = { from[0],from[1],from[2],1, to[0],to[1],to[2],1 }; int sz = sizeof(vertexPositions); b3Assert(glGetError() ==GL_NO_ERROR); b3Clamp(lineWidth,(float)lineWidthRange[0],(float)lineWidthRange[1]); glLineWidth(lineWidth); b3Assert(glGetError() ==GL_NO_ERROR); glBindVertexArray(lineVertexArrayObject); b3Assert(glGetError() ==GL_NO_ERROR); glBindBuffer(GL_ARRAY_BUFFER, lineVertexBufferObject); b3Assert(glGetError() ==GL_NO_ERROR); { glBufferSubData(GL_ARRAY_BUFFER, 0,sz, vertexPositions); } b3Assert(glGetError() ==GL_NO_ERROR); glBindBuffer(GL_ARRAY_BUFFER, 0); glBindBuffer(GL_ARRAY_BUFFER, lineVertexBufferObject); b3Assert(glGetError() ==GL_NO_ERROR); glEnableVertexAttribArray(0); glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, 0); b3Assert(glGetError() ==GL_NO_ERROR); glDrawArrays(GL_LINES, 0, 2); b3Assert(glGetError() ==GL_NO_ERROR); glBindVertexArray(0); glLineWidth(1); b3Assert(glGetError() ==GL_NO_ERROR); glUseProgram(0); }