[go: up one dir, main page]

Menu

[e79954]: / caelum / caelum.cc  Maximize  Restore  History

Download this file

195 lines (175 with data), 5.1 kB

  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
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
// caelum.cc - Main program for making sky boxes from panoramas.
//
// Copyright (C) 2003 Sam Varner
//
// This file is part of Caelum.
//
// Caelum is free software: you can redistribute 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.
//
// Caelum 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 Caelum. If not, see <http://www.gnu.org/licenses/>.
#include "Sphere_Sky.h"
#include "Cylinder_Sky.h"
#include "../media/Texture_Image.h"
#include <iostream>
#include <cstdlib>
#include <string>
#include <getopt.h>
#include <SDL/SDL.h>
using Vamos_Media::Texture_Image;
int
main (int argc, char* argv [])
{
// Parse the command line.
int help_flag = 0;
int version_flag = 0;
int divisions = 16; // default
int width = 0;
int height = 0;
while (true)
{
static struct option long_options [] =
{
// These options set flags.
{"help", no_argument, &help_flag, 1},
{"version", no_argument, &version_flag, 1},
// These options don't set a flag.
// We distinguish them by their indices.
{"divisions", required_argument, 0, 'd'},
{"width", required_argument, 0, 'w'},
{"height", required_argument, 0, 'h'},
{0, 0, 0, 0}
};
// The option index.
int option_index = 0;
int c = getopt_long (argc, argv, "d:w:h:",
long_options, &option_index);
// Detect the end of the options.
if (c == -1)
break;
switch (c)
{
case 0:
// If this option set a flag, do nothing else now.
if (long_options [option_index].flag != 0)
break;
break;
case 'd':
divisions = atoi (optarg);
break;
case 'w':
width = atoi (optarg);
break;
case 'h':
height = atoi (optarg);
break;
case '?':
// `getopt_long' already printed an error message.
break;
default:
abort ();
}
}
if ((argc - optind) != 1)
{
// wrong number arguments
help_flag = 1;
}
if (help_flag)
{
std::cout << "Usage:\tcaelum [options] image-file\n\n"
<< "Run Caelum, a tool for creating sky boxes.\n\n"
<< "Options:\n"
<< "\t--divisions, -d DIV\tthe number of latitude divisions\n"
<< "\t--height, -h HEIGHT\tthe height of the window\n"
<< "\t--help\t\t\tdisplay this help message and exit\n"
<< "\t--version\t\tdisplay version information and exit\n"
<< "\t--width, -w WIDTH\tthe width of the window\n\n"
<< "Reports bugs to snick-a-doo@comcast.net"
<< std::endl;
return EXIT_SUCCESS;
}
if (version_flag)
{
std::cout << "Caelum 1.0\n"
<< "Copyright (C) 2003 Sam Varner\n"
<< "Caelum comes with ABSOLUTELY NO WARRANTY.\n"
<< "You may redistribute copies of Caelum\n"
<< "under the terms of the GNU General Public License.\n"
<< "For more information about these matters, "
<< "see the file named COPYING."
<< std::endl;
return EXIT_SUCCESS;
}
// Initialize GL.
if (SDL_Init (SDL_INIT_VIDEO) != 0)
exit (1);
atexit (SDL_Quit);
std::string file = argv [optind];
if ((width == 0) || (height == 0))
{
// Load the image just to get the size.
try
{
Texture_Image image (file);
if (width == 0)
width = image.width_pixels () * 2;
if (height == 0)
height = int (image.height_pixels () * 1.5);
}
catch (Vamos_Media::Missing_Texture_File)
{
std::cerr << "Couldn't find " << file << std::endl;
std::exit (EXIT_FAILURE);
}
}
if (SDL_SetVideoMode (width, height, 0,
(SDL_OPENGL | SDL_RESIZABLE | SDL_DOUBLEBUF)) == 0)
exit (1);
// Make window.
std::string title = "Caelum: " + file;
SDL_GL_SetAttribute (SDL_GL_STENCIL_SIZE, 1);
SDL_WM_SetCaption (title.c_str (), title.c_str ());
glEnable (GL_TEXTURE_2D);
glClearColor (0.5, 0.5, 0.5, 0.0);
SDL_EnableKeyRepeat (500, 30);
// Initial delay and interval in ms.
// Construct the sky object.
try
{
// Sphere_Sky caelum (divisions, file, width / 4, height / 3);
Cylinder_Sky caelum (divisions, file, width / 4, height / 3);
SDL_Event event;
while (true)
{
while (SDL_PollEvent (&event))
{
switch (event.type)
{
case SDL_KEYDOWN:
caelum.key_press (event.key.keysym.sym);
break;
case SDL_QUIT:
exit (1);
break;
}
}
SDL_Delay (10);
caelum.display ();
}
}
catch (Vamos_Media::Missing_Texture_File)
{
std::cerr << "Couldn't find " << file << std::endl;
std::exit (EXIT_FAILURE);
}
return EXIT_SUCCESS;
}