Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
Autumn2020
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
Sindre Eiklid
Autumn2020
Commits
d9b107c9
Commit
d9b107c9
authored
4 years ago
by
Sindre Eiklid
Browse files
Options
Downloads
Patches
Plain Diff
Added window resize callback
parent
104513fd
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
functionality.cpp
+32
-0
32 additions, 0 deletions
functionality.cpp
header/functionality.h
+1
-0
1 addition, 0 deletions
header/functionality.h
main.cpp
+5
-0
5 additions, 0 deletions
main.cpp
with
38 additions
and
0 deletions
functionality.cpp
+
32
−
0
View file @
d9b107c9
...
...
@@ -278,6 +278,38 @@ void destroyVAO(GLuint &VAO) {
//delete VAO
glDeleteVertexArrays
(
1
,
&
VAO
);
}
/**
* @brief Resize frame to keep aspect ratio.
*
* @param window
* @param width
* @param height
*/
void
framebuffer_size_callback
(
GLFWwindow
*
window
,
int
width
,
int
height
)
{
//set difference values
int
widthDifference
=
width
-
1024
;
int
heightDifference
=
height
-
1024
;
//set scene size and position according to width and height difference
if
(
widthDifference
>
0
&&
heightDifference
>
0
)
{
glViewport
((
widthDifference
/
2
)
-
(
heightDifference
/
2
),
0
,
(
width
-
widthDifference
)
+
heightDifference
,
height
);
}
else
if
(
widthDifference
<
0
&&
heightDifference
<
0
)
{
glViewport
(
-
(
heightDifference
/
2
),
-
(
widthDifference
/
2
),
(
width
+
heightDifference
),
(
height
+
widthDifference
));
//wrong
}
else
if
(
widthDifference
>
0
&&
heightDifference
<
0
)
{
glViewport
((
widthDifference
/
2
)
-
(
heightDifference
/
2
),
0
,
(
width
-
widthDifference
)
+
heightDifference
,
height
);
}
else
if
(
widthDifference
<
0
&&
heightDifference
>
0
)
{
glViewport
(
0
,
-
(
widthDifference
/
2
)
+
(
heightDifference
/
2
),
width
,
(
height
+
widthDifference
)
-
heightDifference
);
}
else
{
if
(
widthDifference
>
0
)
{
glViewport
((
widthDifference
/
2
),
0
,
(
width
-
widthDifference
),
height
);
}
else
if
(
widthDifference
<
0
)
{
glViewport
(
0
,
-
(
widthDifference
/
2
),
width
,
(
height
+
widthDifference
));
}
else
if
(
heightDifference
>
0
)
{
glViewport
(
0
,
(
heightDifference
/
2
),
width
,
(
height
-
heightDifference
));
}
else
if
(
heightDifference
<
0
)
{
glViewport
(
-
(
heightDifference
/
2
),
0
,
(
width
+
heightDifference
),
height
);
}
}
}
/**
* @brief Eanable capture of debug output.
*
...
...
This diff is collapsed.
Click to expand it.
header/functionality.h
+
1
−
0
View file @
d9b107c9
...
...
@@ -15,6 +15,7 @@ GLuint loadModel(const std::string path, const std::string file, int &size);
GLuint
loadTexture
(
const
std
::
string
&
filepath
,
const
GLuint
slot
);
GLuint
createVAO
(
const
std
::
vector
<
GLfloat
>
&
arr
,
const
std
::
vector
<
GLuint
>
&
arr_indices
);
void
destroyVAO
(
GLuint
&
VAO
);
void
framebuffer_size_callback
(
GLFWwindow
*
window
,
int
width
,
int
height
);
void
enableDebug
();
void
GLAPIENTRY
messageCallback
(
GLenum
source
,
GLenum
type
,
GLuint
id
,
GLenum
severity
,
GLsizei
length
,
const
GLchar
*
message
,
const
void
*
userParam
);
#endif
This diff is collapsed.
Click to expand it.
main.cpp
+
5
−
0
View file @
d9b107c9
...
...
@@ -37,6 +37,11 @@ int main() {
glfwWindowHint
(
GLFW_OPENGL_PROFILE
,
GLFW_OPENGL_CORE_PROFILE
);
//create window
GLFWwindow
*
window
=
glfwCreateWindow
(
1024
,
1024
,
"Landscape"
,
nullptr
,
nullptr
);
//set framebuffer size data
int
framebufferWidth
=
0
,
framebufferHeight
=
0
;
glfwGetFramebufferSize
(
window
,
&
framebufferWidth
,
&
framebufferHeight
);
//declare framebuffer size callback
glfwSetFramebufferSizeCallback
(
window
,
framebuffer_size_callback
);
//setting the OpenGL context to the window
glfwMakeContextCurrent
(
window
);
//enable capture of cursor and focus it on the middle while hiding the icon
...
...
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