Revision: 38928
http://brlcad.svn.sourceforge.net/brlcad/?rev=38928&view=rev
Author: erikgreenwald
Date: 2010-04-30 20:11:38 +0000 (Fri, 30 Apr 2010)
Log Message:
-----------
erm, redo the change I accidently undid...
Modified Paths:
--------------
isst/trunk/sdl/main.c
Modified: isst/trunk/sdl/main.c
===================================================================
--- isst/trunk/sdl/main.c 2010-04-30 20:09:27 UTC (rev 38927)
+++ isst/trunk/sdl/main.c 2010-04-30 20:11:38 UTC (rev 38928)
@@ -41,17 +41,32 @@
struct adrt_mesh_s *meshes;
tienet_buffer_t buffer_image;
struct SDL_Rect r;
+ struct SDL_Surface *screen;
+ int ogl, sflags, w, h;
};
+void
+resize_isst(struct isst_s *isst)
+{
+ isst->r.w = isst->tile.size_x = isst->camera.w = isst->w;
+ isst->r.h = isst->tile.size_y = isst->camera.h = isst->h;
+ isst->r.x = isst->r.y = isst->tile.orig_x = isst->tile.orig_y = 0;
+ isst->tile.format = RENDER_CAMERA_BIT_DEPTH_24;
+ TIENET_BUFFER_SIZE(isst->buffer_image, 3 * isst->w * isst->h);
+ printf("%dx%d 24 %x\n", isst->w, isst->h, isst->sflags);
+ isst->screen = SDL_SetVideoMode (isst->w, isst->h, 24, isst->sflags);
+ if(isst->screen == NULL) {
+ printf("Failed to generate display context\n");
+ exit(EXIT_FAILURE);
+ }
+}
+
struct isst_s *
-prep_isst(int argc, const char **argv, SDL_Surface *screen)
+prep_isst(int argc, const char **argv)
{
struct isst_s *isst;
isst = (struct isst_s *)malloc(sizeof(struct isst_s));
- isst->r.w = isst->tile.size_x = isst->camera.w = screen->w;
- isst->r.h = isst->tile.size_y = isst->camera.h = screen->h;
- isst->r.x = isst->r.y = isst->tile.orig_x = isst->tile.orig_y = 0;
- isst->tile.format = RENDER_CAMERA_BIT_DEPTH_24;
+ TIENET_BUFFER_INIT(isst->buffer_image);
render_camera_init(&isst->camera, bu_avail_cpus());
isst->camera.type = RENDER_CAMERA_PERSPECTIVE;
isst->camera.fov = 25;
@@ -59,13 +74,28 @@
VSETALL(isst->camera.focus.v, 0);
render_phong_init(&isst->camera.render, NULL);
isst->tie = (struct tie_s *)bu_malloc(sizeof(struct tie_s), "tie");
- TIENET_BUFFER_SIZE(isst->buffer_image, 3*screen->w*screen->h);
load_g(isst->tie, argv[0], argc-1, argv+1, &(isst->meshes));
return isst;
}
+void
+paint_ogl(struct isst_s *isst)
+{
+}
+
+void
+paint_sw(struct isst_s *isst)
+{
+ int i;
+ for(i=0;i<isst->h;i++)
+ memcpy(isst->screen->pixels + i * isst->screen->pitch,
+ isst->buffer_image.data + i * isst->w * 3,
+ isst->screen->w*3);
+ SDL_UpdateRect(isst->screen, 0, 0, 0, 0);
+}
+
int
-do_loop(SDL_Surface *screen, struct isst_s *isst)
+do_loop(struct isst_s *isst)
{
SDL_Event e;
struct timeval ts[2];
@@ -80,8 +110,10 @@
isst->buffer_image.ind = 0;
render_camera_prep(&isst->camera);
render_camera_render(&isst->camera, isst->tie, &isst->tile,
&isst->buffer_image);
- memcpy(screen->pixels, isst->buffer_image.data, screen->w*screen->h*3);
- SDL_UpdateRect(screen, 0, 0, 0, 0);
+ if(isst->ogl)
+ paint_ogl(isst);
+ else
+ paint_sw(isst);
/* some FPS stuff */
fc++;
@@ -93,33 +125,35 @@
gettimeofday(ts, NULL);
}
- /* we can SDL_PollEvent() for continuous rendering */
- SDL_WaitEvent (&e);
- switch (e.type)
- {
- case SDL_VIDEORESIZE:
- printf("Resize!\n");
- break;
- case SDL_KEYDOWN:
- switch (tolower (e.key.keysym.sym))
- {
- case 'x':
- case 'q':
- case SDLK_ESCAPE:
- SDL_Quit ();
- printf("\n");
- return EXIT_SUCCESS;
- break;
- /* TODO: more keys for nifty things like changing mode
or pulling up gui bits or something */
- }
- case SDL_MOUSEMOTION:
- if(e.motion.state) {
- printf("\n%d %d %x\n", e.motion.xrel, e.motion.yrel,
e.motion.state);
- }
- break;
- case SDL_MOUSEBUTTON:
- break;
- }
+ while(SDL_PollEvent (&e))
+ switch (e.type)
+ {
+ case SDL_VIDEORESIZE:
+ isst->w = e.resize.w;
+ isst->h = e.resize.h;
+ resize_isst(isst);
+ break;
+ case SDL_KEYDOWN:
+ switch (tolower (e.key.keysym.sym))
+ {
+ case 'f':
+ if(isst->sflags&SDL_FULLSCREEN)
+ isst->sflags &= ~SDL_FULLSCREEN;
+ else
+ isst->sflags |= SDL_FULLSCREEN;
+ resize_isst(isst);
+ break;
+ case 'x':
+ case 'q':
+ case SDLK_ESCAPE:
+ SDL_Quit ();
+ printf("\n");
+ return EXIT_SUCCESS;
+ break;
+ /* TODO: more keys for nifty things like changing
mode or pulling up gui bits or something */
+ }
+ /* TODO: look for mouse events */
+ }
}
}
@@ -127,21 +161,22 @@
int
main(int argc, char **argv)
{
- SDL_Surface *screen;
struct isst_s *isst;
- int w = 800, h = 600, c;
- int ogl = 0;
+ int w = 800, h = 600, c, ogl = 0, sflags =
SDL_HWSURFACE|SDL_DOUBLEBUF|SDL_RESIZABLE;
const char opts[] =
/* or would it be better to */
#ifdef HAVE_OPENGL
- "w:h:g";
+ "fw:h:g";
#else
- "w:h:";
+ "fw:h:";
#endif
while((c=getopt(argc, argv, opts)) != -1)
switch(c) {
+ case 'f':
+ sflags |= SDL_FULLSCREEN;
+ break;
case 'w':
w = atoi(optarg);
break;
@@ -149,6 +184,7 @@
h = atoi(optarg);
break;
case 'g':
+ sflags |= SDL_OPENGL;
ogl = 1;
break;
case ':':
@@ -172,13 +208,15 @@
SDL_Init (SDL_INIT_VIDEO | SDL_INIT_TIMER);
atexit (SDL_Quit);
- /* can we make this resizable? */
- screen = SDL_SetVideoMode (w, h, 24,
SDL_DOUBLEBUF|SDL_HWSURFACE|SDL_RESIZABLE);
+ isst = prep_isst(argc, (const char **)argv);
+ isst->sflags |= sflags;
+ isst->ogl = ogl;
+ isst->w = w;
+ isst->h = h;
+ resize_isst(isst);
- isst = prep_isst(argc, (const char **)argv, screen);
-
/* main event loop */
- return do_loop(screen, isst);
+ return do_loop(isst);
}
/*
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits