|
|
|
@ -10,6 +10,9 @@ |
|
|
|
|
|
|
|
|
|
static GLFWwindow* window; |
|
|
|
|
static GLuint fontTex; |
|
|
|
|
static bool mousePressed[2] = { false, false }; |
|
|
|
|
static ImVec2 mousePosScale(1.0f, 1.0f); |
|
|
|
|
|
|
|
|
|
//Shader variables
|
|
|
|
|
static int shader_handle, vert_handle, frag_handle; |
|
|
|
|
|
|
|
|
@ -23,30 +26,6 @@ static size_t vbo_max_size = 1000000; |
|
|
|
|
static unsigned int vbo_handle, vao_handle; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<typename T> |
|
|
|
|
unsigned int stream(GLenum target, unsigned int vbo, unsigned int *vbo_cursor, unsigned int *vbo_size, T *start, int elementCount) |
|
|
|
|
{ |
|
|
|
|
unsigned int bytes = sizeof(T) *elementCount; |
|
|
|
|
unsigned int aligned = bytes + bytes % 64; //align memory
|
|
|
|
|
|
|
|
|
|
glBindBuffer(target, vbo); |
|
|
|
|
//If there's not enough space left, orphan the buffer object, create a new one and start writing
|
|
|
|
|
if (vbo_cursor[0] + aligned > vbo_size[0]) |
|
|
|
|
{ |
|
|
|
|
assert(aligned < vbo_size[0]); |
|
|
|
|
glBufferData(target, vbo_size[0], NULL, GL_DYNAMIC_DRAW); |
|
|
|
|
vbo_cursor[0] = 0; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void* mapped = glMapBufferRange(target, vbo_cursor[0], aligned, GL_MAP_WRITE_BIT | GL_MAP_UNSYNCHRONIZED_BIT); |
|
|
|
|
|
|
|
|
|
memcpy(mapped, start, bytes); |
|
|
|
|
vbo_cursor[0] += aligned; |
|
|
|
|
|
|
|
|
|
glUnmapBuffer(target); |
|
|
|
|
return vbo_cursor[0] - aligned; //return the offset we use for glVertexAttribPointer call
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// This is the main rendering function that you have to implement and provide to ImGui (via setting up 'RenderDrawListsFn' in the ImGuiIO structure)
|
|
|
|
|
// If text or lines are blurry when integrating ImGui in your engine:
|
|
|
|
|
// - try adjusting ImGui::GetIO().PixelCenterOffset to 0.0f or 0.5f
|
|
|
|
@ -147,10 +126,16 @@ static void glfw_error_callback(int error, const char* description) |
|
|
|
|
fputs(description, stderr); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void glfw_mouse_button_callback(GLFWwindow* window, int button, int action, int mods) |
|
|
|
|
{ |
|
|
|
|
if (action == GLFW_PRESS && button >= 0 && button < 2) |
|
|
|
|
mousePressed[button] = true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void glfw_scroll_callback(GLFWwindow* window, double xoffset, double yoffset) |
|
|
|
|
{ |
|
|
|
|
ImGuiIO& io = ImGui::GetIO(); |
|
|
|
|
io.MouseWheel = (yoffset != 0.0f) ? yoffset > 0.0f ? 1.0f : -1.0f : 0.0f; // Mouse wheel: -1,0,+1
|
|
|
|
|
io.MouseWheel += (float)yoffset; // Use fractional mouse wheel, 1.0 unit 5 lines.
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void glfw_key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) |
|
|
|
@ -166,8 +151,8 @@ static void glfw_key_callback(GLFWwindow* window, int key, int scancode, int act |
|
|
|
|
|
|
|
|
|
static void glfw_char_callback(GLFWwindow* window, unsigned int c) |
|
|
|
|
{ |
|
|
|
|
if (c > 0 && c <= 255) |
|
|
|
|
ImGui::GetIO().AddInputCharacter((char)c); |
|
|
|
|
if (c > 0 && c < 0x10000) |
|
|
|
|
ImGui::GetIO().AddInputCharacter((unsigned short)c); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -201,31 +186,24 @@ void InitGL() |
|
|
|
|
const GLchar *vertex_shader = \
|
|
|
|
|
"#version 330\n" |
|
|
|
|
"uniform mat4 ortho;\n" |
|
|
|
|
|
|
|
|
|
"in vec2 Position;\n" |
|
|
|
|
"in vec2 UV;\n" |
|
|
|
|
"in vec4 Colour;\n" |
|
|
|
|
|
|
|
|
|
"out vec2 Frag_UV;\n" |
|
|
|
|
"out vec4 Frag_Colour;\n" |
|
|
|
|
|
|
|
|
|
"void main()\n" |
|
|
|
|
"{\n" |
|
|
|
|
" Frag_UV = UV;\n" |
|
|
|
|
" Frag_Colour = Colour;\n" |
|
|
|
|
"\n" |
|
|
|
|
" gl_Position = ortho*vec4(Position.xy,0,1);\n" |
|
|
|
|
"}\n"; |
|
|
|
|
|
|
|
|
|
const GLchar* fragment_shader = \
|
|
|
|
|
"#version 330\n" |
|
|
|
|
"uniform sampler2D Texture;\n" |
|
|
|
|
|
|
|
|
|
"in vec2 Frag_UV;\n" |
|
|
|
|
"in vec4 Frag_Colour;\n" |
|
|
|
|
|
|
|
|
|
"out vec4 FragColor;\n" |
|
|
|
|
|
|
|
|
|
"void main()\n" |
|
|
|
|
"{\n" |
|
|
|
|
" FragColor = Frag_Colour * texture( Texture, Frag_UV.st);\n" |
|
|
|
|