- added cybersun screen
authorJohn Tsiombikas <nuclear@member.fsf.org>
Sun, 12 Jul 2020 22:34:31 +0000 (01:34 +0300)
committerJohn Tsiombikas <nuclear@member.fsf.org>
Sun, 12 Jul 2020 22:34:31 +0000 (01:34 +0300)
- fixed gen_plane_mesh dimensions

src/3dgfx/mesh.c
src/3dgfx/mesh.h
src/scr/cybersun.c [new file with mode: 0644]
src/screen.c

index b8bb9c1..c40b491 100644 (file)
@@ -364,8 +364,8 @@ int gen_plane_mesh(struct g3d_mesh *m, float width, float height, int usub, int
        nfaces = usub * vsub;
        uverts = usub + 1;
        vverts = vsub + 1;
-       du = (float)width / (float)usub;
-       dv = (float)height / (float)vsub;
+       du = 1.0f / (float)usub;
+       dv = 1.0f / (float)vsub;
 
        nverts = uverts * vverts;
        nidx = nfaces * 4;
index 5357cb0..e02cf55 100644 (file)
@@ -10,6 +10,8 @@ struct g3d_mesh {
        int vcount, icount;
 };
 
+int init_mesh(struct g3d_mesh *mesh, int prim, int num_verts, int num_idx);
+
 void free_mesh(struct g3d_mesh *mesh);
 void destroy_mesh(struct g3d_mesh *mesh);
 
diff --git a/src/scr/cybersun.c b/src/scr/cybersun.c
new file mode 100644 (file)
index 0000000..bb6055a
--- /dev/null
@@ -0,0 +1,99 @@
+#include <stdio.h>
+#include "demo.h"
+#include "3dgfx.h"
+#include "screen.h"
+#include "gfxutil.h"
+#include "mesh.h"
+#include "image.h"
+
+static int init(void);
+static void destroy(void);
+static void start(long trans_time);
+static void draw(void);
+
+static struct screen scr = {
+       "cybersun",
+       init,
+       destroy,
+       start,
+       0,
+       draw
+};
+
+static float cam_theta = 0, cam_phi = 10;
+static float cam_dist = 6;
+
+static struct g3d_mesh gmesh;
+#define GMESH_GRIDSZ   20
+#define GMESH_SIZE             50
+static struct image gtex;
+
+struct screen *cybersun_screen(void)
+{
+       return &scr;
+}
+
+static int init(void)
+{
+       int i, j;
+
+       if(gen_plane_mesh(&gmesh, GMESH_SIZE, GMESH_SIZE, GMESH_GRIDSZ, GMESH_GRIDSZ) == -1) {
+               return -1;
+       }
+       for(i=0; i<gmesh.vcount; i++) {
+               gmesh.varr[i].u *= GMESH_GRIDSZ;
+               gmesh.varr[i].v *= GMESH_GRIDSZ;
+       }
+       if(load_image(&gtex, "data/pgrid.png") == -1) {
+               return -1;
+       }
+
+       return 0;
+}
+
+static void destroy(void)
+{
+       destroy_mesh(&gmesh);
+       destroy_image(&gtex);
+}
+
+static void start(long trans_time)
+{
+       g3d_matrix_mode(G3D_PROJECTION);
+       g3d_load_identity();
+       g3d_perspective(50.0, 1.3333333, 0.5, 500.0);
+
+       g3d_enable(G3D_CULL_FACE);
+
+       g3d_clear_color(0, 0, 0);
+}
+
+static void draw(void)
+{
+       int i;
+
+       mouse_orbit_update(&cam_theta, &cam_phi, &cam_dist);
+
+       g3d_matrix_mode(G3D_MODELVIEW);
+       g3d_load_identity();
+       g3d_translate(0, 0, -cam_dist);
+       g3d_rotate(cam_phi, 1, 0, 0);
+       g3d_rotate(cam_theta, 0, 1, 0);
+       if(opt.sball) {
+               g3d_mult_matrix(sball_matrix);
+       }
+
+       g3d_clear(G3D_COLOR_BUFFER_BIT | G3D_DEPTH_BUFFER_BIT);
+
+       g3d_set_texture(gtex.width, gtex.height, gtex.pixels);
+       g3d_enable(G3D_TEXTURE_2D);
+
+       g3d_push_matrix();
+       g3d_rotate(-90, 1, 0, 0);
+       draw_mesh(&gmesh);
+       g3d_pop_matrix();
+
+       g3d_disable(G3D_TEXTURE_2D);
+
+       swap_buffers(fb_pixels);
+}
index baf4ec2..15eb57c 100644 (file)
@@ -25,6 +25,7 @@ struct screen *metaballs_screen(void);
 struct screen *greets_screen(void);
 struct screen *infcubes_screen(void);
 struct screen *hairball_screen(void);
+struct screen *cybersun_screen(void);
 
 void start_loadscr(void);
 void end_loadscr(void);
@@ -79,6 +80,9 @@ int scr_init(void)
        if(!(scr[idx++] = hairball_screen())) {
                return -1;
        }
+       if(!(scr[idx++] = cybersun_screen())) {
+               return -1;
+       }
        num_screens = idx;
 
        assert(num_screens <= NUM_SCR);