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
a280c973
Commit
a280c973
authored
8 years ago
by
Camilla Löwy
Browse files
Options
Downloads
Patches
Plain Diff
Convert reopen test to GL2
parent
dfd1c859
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/reopen.c
+93
-48
93 additions, 48 deletions
tests/reopen.c
with
93 additions
and
48 deletions
tests/reopen.c
+
93
−
48
View file @
a280c973
...
...
@@ -40,16 +40,35 @@
#include
<stdio.h>
#include
<stdlib.h>
#include
"linmath.h"
static
const
char
*
vertex_shader_text
=
"uniform mat4 MVP;
\n
"
"attribute vec2 vPos;
\n
"
"void main()
\n
"
"{
\n
"
" gl_Position = MVP * vec4(vPos, 0.0, 1.0);
\n
"
"}
\n
"
;
static
const
char
*
fragment_shader_text
=
"void main()
\n
"
"{
\n
"
" gl_FragColor = vec4(1.0);
\n
"
"}
\n
"
;
static
const
vec2
vertices
[
4
]
=
{
{
-
0
.
5
f
,
-
0
.
5
f
},
{
0
.
5
f
,
-
0
.
5
f
},
{
0
.
5
f
,
0
.
5
f
},
{
-
0
.
5
f
,
0
.
5
f
}
};
static
void
error_callback
(
int
error
,
const
char
*
description
)
{
fprintf
(
stderr
,
"Error: %s
\n
"
,
description
);
}
static
void
framebuffer_size_callback
(
GLFWwindow
*
window
,
int
width
,
int
height
)
{
glViewport
(
0
,
0
,
width
,
height
);
}
static
void
window_close_callback
(
GLFWwindow
*
window
)
{
printf
(
"Close callback triggered
\n
"
);
...
...
@@ -69,40 +88,6 @@ static void key_callback(GLFWwindow* window, int key, int scancode, int action,
}
}
static
GLFWwindow
*
open_window
(
int
width
,
int
height
,
GLFWmonitor
*
monitor
)
{
double
base
;
GLFWwindow
*
window
;
base
=
glfwGetTime
();
window
=
glfwCreateWindow
(
width
,
height
,
"Window Re-opener"
,
monitor
,
NULL
);
if
(
!
window
)
return
NULL
;
glfwMakeContextCurrent
(
window
);
gladLoadGLLoader
((
GLADloadproc
)
glfwGetProcAddress
);
glfwSwapInterval
(
1
);
glfwSetFramebufferSizeCallback
(
window
,
framebuffer_size_callback
);
glfwSetWindowCloseCallback
(
window
,
window_close_callback
);
glfwSetKeyCallback
(
window
,
key_callback
);
if
(
monitor
)
{
printf
(
"Opening full screen window on monitor %s took %0.3f seconds
\n
"
,
glfwGetMonitorName
(
monitor
),
glfwGetTime
()
-
base
);
}
else
{
printf
(
"Opening regular window took %0.3f seconds
\n
"
,
glfwGetTime
()
-
base
);
}
return
window
;
}
static
void
close_window
(
GLFWwindow
*
window
)
{
double
base
=
glfwGetTime
();
...
...
@@ -113,6 +98,7 @@ static void close_window(GLFWwindow* window)
int
main
(
int
argc
,
char
**
argv
)
{
int
count
=
0
;
double
base
;
GLFWwindow
*
window
;
srand
((
unsigned
int
)
time
(
NULL
));
...
...
@@ -122,12 +108,17 @@ int main(int argc, char** argv)
if
(
!
glfwInit
())
exit
(
EXIT_FAILURE
);
glfwWindowHint
(
GLFW_CONTEXT_VERSION_MAJOR
,
2
);
glfwWindowHint
(
GLFW_CONTEXT_VERSION_MINOR
,
0
);
for
(;;)
{
int
width
,
height
;
GLFWmonitor
*
monitor
=
NULL
;
GLuint
vertex_shader
,
fragment_shader
,
program
,
vertex_buffer
;
GLint
mvp_location
,
vpos_location
;
if
(
count
%
2
==
0
)
if
(
count
&
1
)
{
int
monitorCount
;
GLFWmonitor
**
monitors
=
glfwGetMonitors
(
&
monitorCount
);
...
...
@@ -146,27 +137,81 @@ int main(int argc, char** argv)
height
=
480
;
}
window
=
open_window
(
width
,
height
,
monitor
);
base
=
glfwGetTime
();
window
=
glfwCreateWindow
(
width
,
height
,
"Window Re-opener"
,
monitor
,
NULL
);
if
(
!
window
)
{
glfwTerminate
();
exit
(
EXIT_FAILURE
);
}
glMatrixMode
(
GL_PROJECTION
);
glOrtho
(
-
1
.
f
,
1
.
f
,
-
1
.
f
,
1
.
f
,
1
.
f
,
-
1
.
f
);
glMatrixMode
(
GL_MODELVIEW
);
if
(
monitor
)
{
printf
(
"Opening full screen window on monitor %s took %0.3f seconds
\n
"
,
glfwGetMonitorName
(
monitor
),
glfwGetTime
()
-
base
);
}
else
{
printf
(
"Opening regular window took %0.3f seconds
\n
"
,
glfwGetTime
()
-
base
);
}
glfwSetWindowCloseCallback
(
window
,
window_close_callback
);
glfwSetKeyCallback
(
window
,
key_callback
);
glfwMakeContextCurrent
(
window
);
gladLoadGLLoader
((
GLADloadproc
)
glfwGetProcAddress
);
glfwSwapInterval
(
1
);
vertex_shader
=
glCreateShader
(
GL_VERTEX_SHADER
);
glShaderSource
(
vertex_shader
,
1
,
&
vertex_shader_text
,
NULL
);
glCompileShader
(
vertex_shader
);
fragment_shader
=
glCreateShader
(
GL_FRAGMENT_SHADER
);
glShaderSource
(
fragment_shader
,
1
,
&
fragment_shader_text
,
NULL
);
glCompileShader
(
fragment_shader
);
program
=
glCreateProgram
();
glAttachShader
(
program
,
vertex_shader
);
glAttachShader
(
program
,
fragment_shader
);
glLinkProgram
(
program
);
mvp_location
=
glGetUniformLocation
(
program
,
"MVP"
);
vpos_location
=
glGetAttribLocation
(
program
,
"vPos"
);
glGenBuffers
(
1
,
&
vertex_buffer
);
glBindBuffer
(
GL_ARRAY_BUFFER
,
vertex_buffer
);
glBufferData
(
GL_ARRAY_BUFFER
,
sizeof
(
vertices
),
vertices
,
GL_STATIC_DRAW
);
glEnableVertexAttribArray
(
vpos_location
);
glVertexAttribPointer
(
vpos_location
,
2
,
GL_FLOAT
,
GL_FALSE
,
sizeof
(
vertices
[
0
]),
(
void
*
)
0
);
glfwSetTime
(
0
.
0
);
while
(
glfwGetTime
()
<
5
.
0
)
{
float
ratio
;
int
width
,
height
;
mat4x4
m
,
p
,
mvp
;
glfwGetFramebufferSize
(
window
,
&
width
,
&
height
);
ratio
=
width
/
(
float
)
height
;
glViewport
(
0
,
0
,
width
,
height
);
glClear
(
GL_COLOR_BUFFER_BIT
);
glPushMatrix
();
glRotatef
((
GLfloat
)
glfwGetTime
()
*
100
.
f
,
0
.
f
,
0
.
f
,
1
.
f
);
glRectf
(
-
0
.
5
f
,
-
0
.
5
f
,
1
.
f
,
1
.
f
);
glPopMatrix
();
mat4x4_ortho
(
p
,
-
ratio
,
ratio
,
-
1
.
f
,
1
.
f
,
0
.
f
,
1
.
f
);
mat4x4_identity
(
m
);
mat4x4_rotate_Z
(
m
,
m
,
(
float
)
glfwGetTime
());
mat4x4_mul
(
mvp
,
p
,
m
);
glUseProgram
(
program
);
glUniformMatrix4fv
(
mvp_location
,
1
,
GL_FALSE
,
(
const
GLfloat
*
)
mvp
);
glDrawArrays
(
GL_TRIANGLE_FAN
,
0
,
4
);
glfwSwapBuffers
(
window
);
glfwPollEvents
();
...
...
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