FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
riCOM_cpp/src/SdlImageWindow.cpp at master · ThFriedrich/riCOM_cpp · GitHub
ThFriedrich
/
riCOM_cpp
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
33
Code
Issues
0
Pull requests
0
Discussions
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
riCOM_cpp
/
src
/
SdlImageWindow.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
73 lines (68 loc) · 2.54 KB
Breadcrumbs
riCOM_cpp
/
src
/
SdlImageWindow.cpp
Copy path
File metadata and controls
73 lines (68 loc) · 2.54 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
Copyright (C) 2021 Thomas Friedrich, Chu-Ping Yu,
* University of Antwerp - All Rights Reserved.
* You may use, distribute and modify
* this code under the terms of the GPL3 license.
* You should have received a copy of the GPL3 license with
* this file. If not, please visit:
* https://www.gnu.org/licenses/gpl-3.0.en.html
*
* Authors:
* Thomas Friedrich <thomas.friedrich@uantwerpen.be>
* Chu-Ping Yu <chu-ping.yu@uantwerpen.be>
*/
#
include
"
SdlImageWindow.h
"
SdlImageWindow::SdlImageWindow
(
const
char
*title, SDL_Surface *srf,
int
nx,
int
ny,
float
scale)
{
this
->
title
= title;
create_window
(srf, nx, ny, scale);
};
SdlImageWindow::SdlImageWindow
(
const
char
*title)
{
this
->
title
= title;
this
->
window
=
NULL
;
//
Pointer for the window
this
->
renderer
=
NULL
;
//
Pointer for the renderer
this
->
tex
=
NULL
;
//
Texture for the window
this
->
srf
=
NULL
;
//
Surface (data source)
};
void
SdlImageWindow::create_window
(SDL_Surface *srf,
int
nx,
int
ny,
float
scale)
{
//
Creating window
window =
SDL_CreateWindow
(title,
SDL_WINDOWPOS_CENTERED
,
SDL_WINDOWPOS_CENTERED
, scale * nx, scale * ny,
SDL_WINDOW_SHOWN
|
SDL_WINDOW_RESIZABLE
|
SDL_WINDOW_OPENGL
);
if
(window ==
NULL
)
{
std::cout <<
"
Window could not be created! SDL Error:
"
<<
SDL_GetError
() << std::endl;
}
//
Creating Renderer
renderer =
SDL_CreateRenderer
(window, -
1
,
SDL_RENDERER_ACCELERATED
|
SDL_RENDERER_PRESENTVSYNC
);
if
(renderer ==
NULL
)
{
std::cout <<
"
Renderer could not be created! SDL Error:
"
<<
SDL_GetError
() << std::endl;
}
//
Creating texture for hardware rendering
tex =
SDL_CreateTexture
(renderer,
SDL_GetWindowPixelFormat
(window),
SDL_TEXTUREACCESS_STATIC
, nx, ny);
if
(tex ==
NULL
)
{
std::cout <<
"
Texture could not be created! SDL Error:
"
<<
SDL_GetError
() << std::endl;
}
//
Maintain Pixel aspect ratio on resizing
if
(
SDL_RenderSetLogicalSize
(renderer, scale * nx, scale * ny) <
0
)
{
std::cout <<
"
Logical size could not be set! SDL Error:
"
<<
SDL_GetError
() << std::endl;
}
this
->
srf
= srf;
}
void
SdlImageWindow::update_image
()
{
if
(srf !=
NULL
)
{
if
(
SDL_UpdateTexture
(tex,
NULL
, srf->
pixels
, srf->
pitch
) == -
1
)
{
std::cout <<
"
SDL_UpdateTexture failed:
"
<<
SDL_GetError
() << std::endl;
}
if
(
SDL_RenderCopy
(renderer, tex,
NULL
,
NULL
) == -
1
)
{
std::cout <<
"
SDL_RenderCopy failed:
"
<<
SDL_GetError
() << std::endl;
}
SDL_RenderPresent
(renderer);
}
}
Back
|
FazBrowse Home
|
New Git URL