Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
S
SWE
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Gaurav Kukreja
SWE
Commits
8a22a1bd
Commit
8a22a1bd
authored
Oct 18, 2012
by
Sebastian Rettenberger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add instructions
parent
9ccbd0ac
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
275 additions
and
8 deletions
+275
-8
SConstruct
SConstruct
+6
-0
SConscript
src/SConscript
+1
-0
FreeSans.ttf
src/opengl/FreeSans.ttf
+0
-0
text.cpp
src/opengl/text.cpp
+24
-0
text.h
src/opengl/text.h
+186
-0
visualization.cpp
src/opengl/visualization.cpp
+48
-8
visualization.h
src/opengl/visualization.h
+10
-0
No files found.
SConstruct
View file @
8a22a1bd
...
...
@@ -82,6 +82,8 @@ vars.AddVariables(
BoolVariable
(
'openGL'
,
'compile with OpenGL visualization'
,
False
),
BoolVariable
(
'openGL_instr'
,
'add instructions to openGL version (requires SDL_ttf)'
,
False
),
BoolVariable
(
'writeNetCDF'
,
'write output in the netCDF-format'
,
False
),
BoolVariable
(
'asagi'
,
'use ASAGI'
,
False
),
...
...
@@ -215,6 +217,10 @@ if env['parallelization'] in ['mpi_with_cuda', 'mpi']:
if
env
[
'openGL'
]
==
True
:
env
.
Append
(
LIBS
=
[
'SDL'
,
'GL'
,
'GLU'
])
if
env
[
'openGL_instr'
]
==
True
:
# We assume that SDL_ttf is in the same directory as SDL
env
.
Append
(
LIBS
=
[
'SDL_ttf'
])
env
.
Append
(
CPPDEFINES
=
[
'USESDLTTF'
])
# set the compiler flags for libSDL
if
'libSDLDir'
in
env
:
...
...
src/SConscript
View file @
8a22a1bd
...
...
@@ -66,6 +66,7 @@ if env['openGL'] == True:
sourceFiles
.
append
(
[
'opengl/controller.cpp'
]
)
sourceFiles
.
append
(
[
'opengl/shader.cpp'
]
)
sourceFiles
.
append
(
[
'opengl/visualization.cpp'
]
)
sourceFiles
.
append
(
[
'opengl/text.cpp'
]
)
# Asagi scenario
if
env
[
'asagi'
]
==
True
:
...
...
src/opengl/FreeSans.ttf
0 → 100644
View file @
8a22a1bd
File added
src/opengl/text.cpp
0 → 100644
View file @
8a22a1bd
// =====================================================================
// This file is part of SWE_CUDA (see file SWE_Block.cu for details).
//
// Copyright (C) 2012 Sebastian Rettenberger
//
// SWE_CUDA is free software: you can redristribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// SWE_CUDA is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with SWE_CUDA. If not, see <http://www.gnu.org/licenses/>.
// =====================================================================
#include "text.h"
unsigned
int
Text
::
instances
=
0
;
TTF_Font
*
Text
::
font
=
0L
;
src/opengl/text.h
0 → 100644
View file @
8a22a1bd
// =====================================================================
// This file is part of SWE_CUDA (see file SWE_Block.cu for details).
//
// Copyright (C) 2012 Sebastian Rettenberger
//
// SWE_CUDA is free software: you can redristribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// SWE_CUDA is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with SWE_CUDA. If not, see <http://www.gnu.org/licenses/>.
// =====================================================================
#ifndef TEXT_H
#define TEXT_H
#include <cmath>
#include <string>
#include <SDL_ttf.h>
#include <SDL_opengl.h>
class
Text
{
public
:
Text
()
{
// Initialize TTF if not done yet
if
(
instances
==
0
)
{
if
(
TTF_Init
()
<
0
)
{
fprintf
(
stderr
,
"
\n
Could not initialize SDL_ttf
\n
"
);
exit
(
-
1
);
}
openFont
();
}
instances
++
;
}
~
Text
()
{
instances
--
;
if
(
instances
==
0
)
{
TTF_CloseFont
(
font
);
TTF_Quit
();
}
}
void
startTextMode
()
{
// Enable 2D mode
int
vPort
[
4
];
glGetIntegerv
(
GL_VIEWPORT
,
vPort
);
glMatrixMode
(
GL_PROJECTION
);
glPushMatrix
();
glLoadIdentity
();
glOrtho
(
0
,
vPort
[
2
],
0
,
vPort
[
3
],
-
1
,
1
);
glMatrixMode
(
GL_MODELVIEW
);
glPushMatrix
();
glLoadIdentity
();
glDisable
(
GL_DEPTH_TEST
);
glEnable
(
GL_BLEND
);
glBlendFunc
(
GL_ONE_MINUS_DST_COLOR
,
GL_ONE_MINUS_SRC_ALPHA
);
}
void
showText
(
const
char
*
text
,
SDL_Rect
&
location
)
{
if
(
!
font
)
return
;
// Draw string
SDL_Color
black
=
{
0
,
0
,
0
,
255
};
SDL_Surface
*
surf
=
TTF_RenderText_Blended
(
font
,
text
,
black
);
if
(
surf
)
{
unsigned
int
texture
;
/* Tell GL about our new texture */
glGenTextures
(
1
,
&
texture
);
glBindTexture
(
GL_TEXTURE_2D
,
texture
);
glTexImage2D
(
GL_TEXTURE_2D
,
0
,
4
,
surf
->
w
,
surf
->
h
,
0
,
GL_BGRA
,
GL_UNSIGNED_BYTE
,
surf
->
pixels
);
/* GL_NEAREST looks horrible, if scaled... */
glTexParameteri
(
GL_TEXTURE_2D
,
GL_TEXTURE_MIN_FILTER
,
GL_LINEAR
);
glTexParameteri
(
GL_TEXTURE_2D
,
GL_TEXTURE_MAG_FILTER
,
GL_LINEAR
);
/* prepare to render our texture */
glEnable
(
GL_TEXTURE_2D
);
glBindTexture
(
GL_TEXTURE_2D
,
texture
);
glColor3f
(
1
.
0
f
,
1
.
0
f
,
1
.
0
f
);
/* Draw a quad at location */
glBegin
(
GL_QUADS
);
/* Recall that the origin is in the lower-left corner
That is why the TexCoords specify different corners
than the Vertex coords seem to. */
glTexCoord2f
(
0
.
0
f
,
1
.
0
f
);
glVertex2f
(
location
.
x
,
location
.
y
-
surf
->
h
);
glTexCoord2f
(
1
.
0
f
,
1
.
0
f
);
glVertex2f
(
location
.
x
+
surf
->
w
,
location
.
y
-
surf
->
h
);
glTexCoord2f
(
1
.
0
f
,
0
.
0
f
);
glVertex2f
(
location
.
x
+
surf
->
w
,
location
.
y
);
glTexCoord2f
(
0
.
0
f
,
0
.
0
f
);
glVertex2f
(
location
.
x
,
location
.
y
);
glEnd
();
/* Bad things happen if we delete the texture before it finishes */
glFinish
();
/* return the deltas in the unused w,h part of the rect */
location
.
w
=
surf
->
w
;
location
.
h
=
surf
->
h
;
/* Clean up */
SDL_FreeSurface
(
surf
);
glDeleteTextures
(
1
,
&
texture
);
}
}
void
endTextMode
()
{
// Disable 2D mode
glDisable
(
GL_BLEND
);
glEnable
(
GL_DEPTH_TEST
);
glMatrixMode
(
GL_PROJECTION
);
glPopMatrix
();
glMatrixMode
(
GL_MODELVIEW
);
glPopMatrix
();
}
private
:
static
void
openFont
()
{
std
::
string
fullFileName
=
""
;
// On unix: determine directory of exec
#ifdef __unix__
// Code taken from:
// http://www.gamedev.net/community/forums/topic.asp?topic_id=459511
std
::
string
path
=
""
;
pid_t
pid
=
getpid
();
char
buf
[
20
]
=
{
0
};
sprintf
(
buf
,
"%d"
,
pid
);
std
::
string
_link
=
"/proc/"
;
_link
.
append
(
buf
);
_link
.
append
(
"/exe"
);
char
proc
[
512
];
int
ch
=
readlink
(
_link
.
c_str
(),
proc
,
512
);
if
(
ch
!=
-
1
)
{
proc
[
ch
]
=
0
;
path
=
proc
;
std
::
string
::
size_type
t
=
path
.
find_last_of
(
"/"
);
path
=
path
.
substr
(
0
,
t
);
}
fullFileName
=
path
+
std
::
string
(
"/"
);
#endif
fullFileName
.
append
(
"FreeSans.ttf"
);
font
=
TTF_OpenFont
(
fullFileName
.
c_str
(),
16
);
if
(
!
font
)
{
fprintf
(
stderr
,
"TTF_OpenFont: %s
\n
"
,
TTF_GetError
());
fprintf
(
stderr
,
"All text will be ignored
\n
"
);
}
}
/** Number of text classes */
static
unsigned
int
instances
;
/** The only font we use */
static
TTF_Font
*
font
;
};
#endif // TEXT_H
src/opengl/visualization.cpp
View file @
8a22a1bd
...
...
@@ -30,7 +30,9 @@
*/
Visualization
::
Visualization
(
int
windowWidth
,
int
windowHeight
,
const
char
*
window_title
,
int
_grid_xsize
,
int
_grid_ysize
)
{
int
_grid_xsize
,
int
_grid_ysize
)
:
windowHeight
(
windowHeight
)
{
// Initialize member variables
grid_xsize
=
_grid_xsize
;
grid_ysize
=
_grid_ysize
;
...
...
@@ -41,6 +43,9 @@ Visualization::Visualization(int windowWidth, int windowHeight, const char* wind
initGLWindow
(
windowWidth
,
windowHeight
);
initGLDefaults
();
initCUDA
();
#ifdef USESDLTTF
text
=
new
Text
();
#endif // USESDLTTF
// Load camera and shaders
camera
=
new
Camera
(
_grid_xsize
*
1.5
f
,
window_title
);
...
...
@@ -64,6 +69,9 @@ Visualization::Visualization(int windowWidth, int windowHeight, const char* wind
Visualization
::~
Visualization
()
{
delete
camera
;
delete
shaders
;
#ifdef USESDLTTF
delete
text
;
#endif // USESDLTTF
SDL_Quit
();
}
...
...
@@ -97,6 +105,35 @@ void Visualization::renderDisplay() {
// Shaded pass
DrawWaterSurface
(
vboWaterSurface
,
vboNormals
,
verticesIndex
);
#ifdef USESDLTTF
text
->
startTextMode
();
SDL_Rect
location
=
{
5
,
windowHeight
-
5
,
0
,
0
};
text
->
showText
(
"Keys:"
,
location
);
location
.
y
-=
location
.
h
;
#ifdef ASAGI
text
->
showText
(
" Scenarios: 1-5"
,
location
);
#else // ASAGI
text
->
showText
(
" Scenarios: 1-3"
,
location
);
#endif // ASAGI
location
.
y
-=
location
.
h
;
text
->
showText
(
" Pause/Resume: Space"
,
location
);
location
.
y
-=
location
.
h
;
text
->
showText
(
" Next frame (when paused): ->"
,
location
);
location
.
y
-=
location
.
h
;
text
->
showText
(
" Reset scenario: r"
,
location
);
location
.
y
-=
location
.
h
;
text
->
showText
(
"Mouse:"
,
location
);
location
.
y
-=
location
.
h
;
text
->
showText
(
" Left button: rotate"
,
location
);
location
.
y
-=
location
.
h
;
text
->
showText
(
" Right button: move"
,
location
);
location
.
y
-=
location
.
h
;
text
->
showText
(
" Middle button: reset camera"
,
location
);
location
.
y
-=
location
.
h
;
text
->
showText
(
" Wheel: zoom in/out"
,
location
);
text
->
endTextMode
();
#endif // USESDLTTF
// Update framebuffer
camera
->
displayImage
();
...
...
@@ -374,16 +411,20 @@ void Visualization::initGLWindow(int width, int height) {
*/
int
Visualization
::
resizeWindow
(
int
newWidth
,
int
newHeight
)
{
if
(
SDL_SetVideoMode
(
newWidth
,
newHeight
,
0
,
SDL_OPENGL
|
SDL_RESIZABLE
|
SDL_ANYFORMAT
)
==
NULL
)
#ifdef USESDLTTF
// We need this, to set the text correctly
windowHeight
=
newHeight
;
#endif // USESDLTTF
if
(
SDL_SetVideoMode
(
newWidth
,
newHeight
,
0
,
SDL_OPENGL
|
SDL_RESIZABLE
|
SDL_ANYFORMAT
)
==
NULL
)
{
fprintf
(
stderr
,
"Could not get a surface after resize: %s
\n
"
,
SDL_GetError
(
)
);
return
1
;
}
else
{
initGLWindow
(
newWidth
,
newHeight
);
return
0
;
}
initGLWindow
(
newWidth
,
newHeight
);
initGLWindow
(
newWidth
,
newHeight
);
return
0
;
}
/**
...
...
@@ -626,7 +667,6 @@ void Visualization::initCUDA() {
cudaGLSetGLDevice
(
dev
)
;
}
/**
Sets current rendering mode
...
...
src/opengl/visualization.h
View file @
8a22a1bd
...
...
@@ -4,6 +4,7 @@
// This file is part of SWE_CUDA (see file SWE_Block.cu for details).
//
// Copyright (C) 2010,2011 Tobias Schnabel
// Copyright (C) 2012 Sebastian Rettenberger
//
// SWE_CUDA is free software: you can redristribute it and/or modify
// it under the terms of the GNU General Public License as published by
...
...
@@ -25,6 +26,9 @@
#include "camera.h"
#include "simulation.h"
#include "shader.h"
#ifdef USESDLTTF
#include "text.h"
#endif // USESDLTTF
void
checkCUDAError
(
const
char
*
msg
);
typedef
enum
RenderMode
{
...
...
@@ -91,6 +95,12 @@ private:
// Shader helper class
Shader
*
shaders
;
#ifdef USESDLTTF
// Text helper class
Text
*
text
;
int
windowHeight
;
#endif // USESDLTTF
// Helper function
int
coord
(
int
x
,
int
y
,
int
width
=
-
1
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment