Skip to content

Instantly share code, notes, and snippets.

@sp00ck
Created February 11, 2019 13:38
Show Gist options
  • Save sp00ck/b96cd160b12443ae23365cf4d759de63 to your computer and use it in GitHub Desktop.
Save sp00ck/b96cd160b12443ae23365cf4d759de63 to your computer and use it in GitHub Desktop.
nk_layout_row_dynamic(ctx, 20, 1);
nk_label(ctx, "background:", NK_TEXT_LEFT);
nk_layout_row_dynamic(ctx, 25, 1);
if (nk_combo_begin_color(ctx, nk_rgb_cf(bg), nk_vec2(nk_widget_width(ctx),400)))
{
nk_layout_row_dynamic(ctx, 120, 1);
bg = nk_color_picker(ctx, bg, NK_RGBA);
nk_layout_row_dynamic(ctx, 25, 1);
bg.r = nk_propertyf(ctx, "#R:", 0, bg.r, 1.0f, 0.01f,0.005f);
bg.g = nk_propertyf(ctx, "#G:", 0, bg.g, 1.0f, 0.01f,0.005f);
bg.b = nk_propertyf(ctx, "#B:", 0, bg.b, 1.0f, 0.01f,0.005f);
bg.a = nk_propertyf(ctx, "#A:", 0, bg.a, 1.0f, 0.01f,0.005f);
nk_combo_end(ctx);
}
}
nk_end(ctx);
/* Draw */
SDL_GetWindowSize(win, &win_width, &win_height);
glViewport(0, 0, win_width, win_height);
glClear(GL_COLOR_BUFFER_BIT);
glClearColor(bg.r, bg.g, bg.b, bg.a);
glLineWidth(2);
glBegin(GL_LINES);
glVertex2f(30, 30);
glVertex2f(20, 20);
glEnd();
glColor3f(0.80, 0.0, 0.0);
glBegin(GL_LINES);
glVertex2i(10,10);
glVertex2i(200,320);
glEnd();
glColor3f(0.0, 0.0, 0.0);
glBegin(GL_POINTS);
glVertex2i(50, 50);
glEnd();
glFlush();
/* IMPORTANT: `nk_sdl_render` modifies some global OpenGL state
* with blending, scissor, face culling, depth test and viewport and
* defaults everything back into a default state.
* Make sure to either a.) save and restore or b.) reset your own state after
* rendering the UI. */
nk_sdl_render(NK_ANTI_ALIASING_ON, MAX_VERTEX_MEMORY, MAX_ELEMENT_MEMORY);
SDL_GL_SwapWindow(win);
}
cleanup:
nk_sdl_shutdown();
SDL_GL_DeleteContext(glContext);
SDL_DestroyWindow(win);
SDL_Quit();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment