Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
glfw
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pirvi-public
glfw
Commits
450d0d69
Commit
450d0d69
authored
Sep 26, 2016
by
Camilla Löwy
Browse files
Options
Downloads
Patches
Plain Diff
Convert gamma test to Nuklear
parent
28889954
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
tests/CMakeLists.txt
+6
-4
6 additions, 4 deletions
tests/CMakeLists.txt
tests/gamma.c
+72
-95
72 additions, 95 deletions
tests/gamma.c
with
78 additions
and
99 deletions
tests/CMakeLists.txt
+
6
−
4
View file @
450d0d69
...
@@ -21,7 +21,6 @@ set(TINYCTHREAD "${GLFW_SOURCE_DIR}/deps/tinycthread.h"
...
@@ -21,7 +21,6 @@ set(TINYCTHREAD "${GLFW_SOURCE_DIR}/deps/tinycthread.h"
add_executable
(
clipboard clipboard.c
${
GETOPT
}
${
GLAD
}
)
add_executable
(
clipboard clipboard.c
${
GETOPT
}
${
GLAD
}
)
add_executable
(
events events.c
${
GETOPT
}
${
GLAD
}
)
add_executable
(
events events.c
${
GETOPT
}
${
GLAD
}
)
add_executable
(
msaa msaa.c
${
GETOPT
}
${
GLAD
}
)
add_executable
(
msaa msaa.c
${
GETOPT
}
${
GLAD
}
)
add_executable
(
gamma gamma.c
${
GETOPT
}
${
GLAD
}
)
add_executable
(
glfwinfo glfwinfo.c
${
GETOPT
}
${
GLAD
}
)
add_executable
(
glfwinfo glfwinfo.c
${
GETOPT
}
${
GLAD
}
)
add_executable
(
iconify iconify.c
${
GETOPT
}
${
GLAD
}
)
add_executable
(
iconify iconify.c
${
GETOPT
}
${
GLAD
}
)
add_executable
(
joysticks joysticks.c
${
GLAD
}
)
add_executable
(
joysticks joysticks.c
${
GLAD
}
)
...
@@ -30,6 +29,7 @@ add_executable(reopen reopen.c ${GLAD})
...
@@ -30,6 +29,7 @@ add_executable(reopen reopen.c ${GLAD})
add_executable
(
cursor cursor.c
${
GLAD
}
)
add_executable
(
cursor cursor.c
${
GLAD
}
)
add_executable
(
empty WIN32 MACOSX_BUNDLE empty.c
${
TINYCTHREAD
}
${
GLAD
}
)
add_executable
(
empty WIN32 MACOSX_BUNDLE empty.c
${
TINYCTHREAD
}
${
GLAD
}
)
add_executable
(
gamma WIN32 MACOSX_BUNDLE gamma.c
${
GLAD
}
)
add_executable
(
icon WIN32 MACOSX_BUNDLE icon.c
${
GLAD
}
)
add_executable
(
icon WIN32 MACOSX_BUNDLE icon.c
${
GLAD
}
)
add_executable
(
sharing WIN32 MACOSX_BUNDLE sharing.c
${
GETOPT
}
${
GLAD
}
)
add_executable
(
sharing WIN32 MACOSX_BUNDLE sharing.c
${
GETOPT
}
${
GLAD
}
)
add_executable
(
tearing WIN32 MACOSX_BUNDLE tearing.c
${
GETOPT
}
${
GLAD
}
)
add_executable
(
tearing WIN32 MACOSX_BUNDLE tearing.c
${
GETOPT
}
${
GLAD
}
)
...
@@ -41,9 +41,10 @@ add_executable(windows WIN32 MACOSX_BUNDLE windows.c ${GETOPT} ${GLAD})
...
@@ -41,9 +41,10 @@ add_executable(windows WIN32 MACOSX_BUNDLE windows.c ${GETOPT} ${GLAD})
target_link_libraries
(
empty
"
${
CMAKE_THREAD_LIBS_INIT
}
"
"
${
RT_LIBRARY
}
"
)
target_link_libraries
(
empty
"
${
CMAKE_THREAD_LIBS_INIT
}
"
"
${
RT_LIBRARY
}
"
)
target_link_libraries
(
threads
"
${
CMAKE_THREAD_LIBS_INIT
}
"
"
${
RT_LIBRARY
}
"
)
target_link_libraries
(
threads
"
${
CMAKE_THREAD_LIBS_INIT
}
"
"
${
RT_LIBRARY
}
"
)
set
(
WINDOWS_BINARIES empty icon sharing tearing threads timeout title windows
)
set
(
WINDOWS_BINARIES empty gamma icon sharing tearing threads timeout title
set
(
CONSOLE_BINARIES clipboard events msaa gamma glfwinfo
windows
)
iconify joysticks monitors reopen cursor
)
set
(
CONSOLE_BINARIES clipboard events msaa glfwinfo iconify joysticks monitors
reopen cursor
)
if
(
VULKAN_FOUND
)
if
(
VULKAN_FOUND
)
add_executable
(
vulkan WIN32 vulkan.c
${
ICON
}
)
add_executable
(
vulkan WIN32 vulkan.c
${
ICON
}
)
...
@@ -65,6 +66,7 @@ endif()
...
@@ -65,6 +66,7 @@ endif()
if
(
APPLE
)
if
(
APPLE
)
set_target_properties
(
empty PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME
"Empty Event"
)
set_target_properties
(
empty PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME
"Empty Event"
)
set_target_properties
(
gamma PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME
"Gamma"
)
set_target_properties
(
sharing PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME
"Sharing"
)
set_target_properties
(
sharing PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME
"Sharing"
)
set_target_properties
(
tearing PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME
"Tearing"
)
set_target_properties
(
tearing PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME
"Tearing"
)
set_target_properties
(
threads PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME
"Threads"
)
set_target_properties
(
threads PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME
"Threads"
)
...
...
This diff is collapsed.
Click to expand it.
tests/gamma.c
+
72
−
95
View file @
450d0d69
...
@@ -31,33 +31,22 @@
...
@@ -31,33 +31,22 @@
#include
<glad/glad.h>
#include
<glad/glad.h>
#include
<GLFW/glfw3.h>
#include
<GLFW/glfw3.h>
#define NK_IMPLEMENTATION
#define NK_INCLUDE_FIXED_TYPES
#define NK_INCLUDE_FONT_BAKING
#define NK_INCLUDE_DEFAULT_FONT
#define NK_INCLUDE_DEFAULT_ALLOCATOR
#define NK_INCLUDE_VERTEX_BUFFER_OUTPUT
#define NK_INCLUDE_STANDARD_VARARGS
#include
<nuklear.h>
#define NK_GLFW_GL2_IMPLEMENTATION
#include
<nuklear_glfw_gl2.h>
#include
<stdio.h>
#include
<stdio.h>
#include
<stdlib.h>
#include
<stdlib.h>
#include
"getopt.h"
static
int
windowed_xpos
,
windowed_ypos
,
windowed_width
,
windowed_height
;
#define STEP_SIZE 0.1f
static
GLfloat
gamma_value
=
1
.
0
f
;
static
void
usage
(
void
)
{
printf
(
"Usage: gamma [-h] [-f]
\n
"
);
printf
(
"Options:
\n
"
);
printf
(
" -f create full screen window
\n
"
);
printf
(
" -h show this help
\n
"
);
}
static
void
set_gamma
(
GLFWwindow
*
window
,
float
value
)
{
GLFWmonitor
*
monitor
=
glfwGetWindowMonitor
(
window
);
if
(
!
monitor
)
monitor
=
glfwGetPrimaryMonitor
();
gamma_value
=
value
;
printf
(
"Gamma: %f
\n
"
,
gamma_value
);
glfwSetGamma
(
monitor
,
gamma_value
);
}
static
void
error_callback
(
int
error
,
const
char
*
description
)
static
void
error_callback
(
int
error
,
const
char
*
description
)
{
{
...
@@ -66,115 +55,103 @@ static void error_callback(int error, const char* description)
...
@@ -66,115 +55,103 @@ static void error_callback(int error, const char* description)
static
void
key_callback
(
GLFWwindow
*
window
,
int
key
,
int
scancode
,
int
action
,
int
mods
)
static
void
key_callback
(
GLFWwindow
*
window
,
int
key
,
int
scancode
,
int
action
,
int
mods
)
{
{
if
(
action
!=
GLFW_PRESS
)
if
(
action
==
GLFW_PRESS
&&
key
==
GLFW_KEY_ESCAPE
)
return
;
switch
(
key
)
{
case
GLFW_KEY_ESCAPE
:
{
glfwSetWindowShouldClose
(
window
,
GLFW_TRUE
);
glfwSetWindowShouldClose
(
window
,
GLFW_TRUE
);
break
;
}
}
case
GLFW_KEY_KP_ADD
:
static
void
chart_ramp_array
(
struct
nk_context
*
nk
,
case
GLFW_KEY_UP
:
struct
nk_color
color
,
case
GLFW_KEY_Q
:
int
count
,
unsigned
short
int
*
values
)
{
{
set_gamma
(
window
,
gamma_value
+
STEP_SIZE
);
if
(
nk_chart_begin_colored
(
nk
,
NK_CHART_LINES
,
break
;
color
,
nk_rgb
(
255
,
255
,
255
),
}
count
,
0
,
65535
))
case
GLFW_KEY_KP_SUBTRACT
:
case
GLFW_KEY_DOWN
:
case
GLFW_KEY_W
:
{
{
if
(
gamma_value
-
STEP_SIZE
>
0
.
f
)
int
i
;
set_gamma
(
window
,
gamma_value
-
STEP_SIZE
);
for
(
i
=
0
;
i
<
count
;
i
++
)
{
break
;
char
buffer
[
1024
];
}
if
(
nk_chart_push
(
nk
,
values
[
i
]))
{
snprintf
(
buffer
,
sizeof
(
buffer
),
"#%u: %u (%0.5f) "
,
i
,
values
[
i
],
values
[
i
]
/
65535
.
f
);
nk_tooltip
(
nk
,
buffer
);
}
}
}
}
static
void
framebuffer_size_callback
(
GLFWwindow
*
window
,
int
width
,
int
height
)
nk_chart_end
(
nk
);
{
}
glViewport
(
0
,
0
,
width
,
height
);
}
}
int
main
(
int
argc
,
char
**
argv
)
int
main
(
int
argc
,
char
**
argv
)
{
{
int
width
,
height
,
ch
;
GLFWmonitor
*
monitor
=
NULL
;
GLFWmonitor
*
monitor
=
NULL
;
GLFWwindow
*
window
;
GLFWwindow
*
window
;
struct
nk_context
*
nk
;
struct
nk_font_atlas
*
atlas
;
float
gamma_value
=
1
.
f
;
glfwSetErrorCallback
(
error_callback
);
glfwSetErrorCallback
(
error_callback
);
if
(
!
glfwInit
())
if
(
!
glfwInit
())
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
while
((
ch
=
getopt
(
argc
,
argv
,
"fh"
))
!=
-
1
)
{
switch
(
ch
)
{
case
'h'
:
usage
();
exit
(
EXIT_SUCCESS
);
case
'f'
:
monitor
=
glfwGetPrimaryMonitor
();
monitor
=
glfwGetPrimaryMonitor
();
break
;
default:
usage
();
exit
(
EXIT_FAILURE
);
}
}
if
(
monitor
)
{
const
GLFWvidmode
*
mode
=
glfwGetVideoMode
(
monitor
);
glfwWindowHint
(
GLFW_REFRESH_RATE
,
mode
->
refreshRate
);
glfwWindowHint
(
GLFW_RED_BITS
,
mode
->
redBits
);
glfwWindowHint
(
GLFW_GREEN_BITS
,
mode
->
greenBits
);
glfwWindowHint
(
GLFW_BLUE_BITS
,
mode
->
blueBits
);
width
=
mode
->
width
;
height
=
mode
->
height
;
}
else
{
width
=
200
;
height
=
200
;
}
window
=
glfwCreateWindow
(
width
,
height
,
"Gamma Test"
,
monitor
,
NULL
);
window
=
glfwCreateWindow
(
800
,
400
,
"Gamma Test"
,
NULL
,
NULL
);
if
(
!
window
)
if
(
!
window
)
{
{
glfwTerminate
();
glfwTerminate
();
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
set_gamma
(
window
,
1
.
f
);
glfwMakeContextCurrent
(
window
);
glfwMakeContextCurrent
(
window
);
gladLoadGLLoader
((
GLADloadproc
)
glfwGetProcAddress
);
gladLoadGLLoader
((
GLADloadproc
)
glfwGetProcAddress
);
glfwSwapInterval
(
1
);
glfwSwapInterval
(
1
);
glfwSetKeyCallback
(
window
,
key_callback
);
nk
=
nk_glfw3_init
(
window
,
NK_GLFW3_INSTALL_CALLBACKS
);
glfwSetFramebufferSizeCallback
(
window
,
framebuffer_size_callback
);
nk_glfw3_font_stash_begin
(
&
atlas
);
nk_glfw3_font_stash_end
();
gl
ClearColor
(
0
.
5
f
,
0
.
5
f
,
0
.
5
f
,
0
);
gl
fwSetKeyCallback
(
window
,
key_callback
);
while
(
!
glfwWindowShouldClose
(
window
))
while
(
!
glfwWindowShouldClose
(
window
))
{
{
int
width
,
height
;
struct
nk_panel
layout
;
struct
nk_rect
area
;
glfwGetFramebufferSize
(
window
,
&
width
,
&
height
);
area
=
nk_rect
(
0
.
f
,
0
.
f
,
(
float
)
width
,
(
float
)
height
);
glClear
(
GL_COLOR_BUFFER_BIT
);
glClear
(
GL_COLOR_BUFFER_BIT
);
nk_glfw3_new_frame
();
if
(
nk_begin
(
nk
,
&
layout
,
""
,
area
,
0
))
{
const
GLFWgammaramp
*
ramp
=
glfwGetGammaRamp
(
monitor
);
nk_window_set_bounds
(
nk
,
area
);
nk_layout_row_dynamic
(
nk
,
30
,
2
);
if
(
nk_slider_float
(
nk
,
0
.
1
f
,
&
gamma_value
,
5
.
f
,
0
.
1
f
))
glfwSetGamma
(
monitor
,
gamma_value
);
nk_labelf
(
nk
,
NK_TEXT_LEFT
,
"%0.1f"
,
gamma_value
);
nk_layout_row_end
(
nk
);
nk_layout_row_dynamic
(
nk
,
height
-
60
.
f
,
3
);
chart_ramp_array
(
nk
,
nk_rgb
(
255
,
0
,
0
),
ramp
->
size
,
ramp
->
red
);
chart_ramp_array
(
nk
,
nk_rgb
(
0
,
255
,
0
),
ramp
->
size
,
ramp
->
green
);
chart_ramp_array
(
nk
,
nk_rgb
(
0
,
0
,
255
),
ramp
->
size
,
ramp
->
blue
);
nk_layout_row_end
(
nk
);
}
nk_end
(
nk
);
nk_glfw3_render
(
NK_ANTI_ALIASING_ON
,
10000
,
1000
);
glfwSwapBuffers
(
window
);
glfwSwapBuffers
(
window
);
glfwWaitEvents
(
);
glfwWaitEvents
Timeout
(
1
.
0
);
}
}
nk_glfw3_shutdown
();
glfwTerminate
();
glfwTerminate
();
exit
(
EXIT_SUCCESS
);
exit
(
EXIT_SUCCESS
);
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment