Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (732)
Games in Android Showcase (222)
games submitted by our members
Games in WIP (806)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
  JavaGaming.org - Pastebin



Author: Archive (posted 2017-01-02 05:31:41, viewed 2258 times)

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  
/*
 * dither.java
 * This program demonstrates dithering in FFP.
 * A smooth shaded polygon is drawn and dithered
 * into the palette specified. Press R to increment
 * the red component of the palette, press G to
 * increment the green component of the palette, and press
 * B to increment the blue component of the palette.
 * Press W to begin auto-rotation and press A to snap it
 * back to the original rotation.
 */

import ffp.FFP;
import ffp.FFPAUX;
import vid.OSGDevice;
import vid.OSGInput;
import vid.OSGVideo;

public class dither extends video {

   public static void main(String[] args) {
      video_create(new dither());
   }

   static int r = 2, g = 1, b = 1;
   static boolean rotate = false;
   static float roty = 0;

   private static void create_projection(int w, int h) {
      FFP.ffpMatrixMode(FFP_PROJECTION);
      FFP.ffpLoadIdentity();
      FFPAUX.ffpauxPerspective(45.0f, (float) w / (float) h, 1.0f, 50.0f);
      FFP.ffpMatrixMode(FFP_MODELVIEW);
      FFP.ffpLoadIdentity();
      FFP.ffpTranslatef(0, 0, -5);
   }

   @Override
   public void osg_init(int video_mode, boolean fullscreen, int display_id) {
      FFP.ffpVideoOutput(OSGVideo.vid_get());
      FFP.ffpViewport(0, 0, WND_WIDTH, WND_HEIGHT);
      create_projection(WND_WIDTH, WND_HEIGHT);
      FFP.ffpVideoClearColor(0, 0, 0);
      FFP.ffpEnable(FFP_SMOOTH_SHADING);
      FFP.ffpVideoPropertyi(FFP_VIDEO_COLOR_DITHER, FFP_TRUE);
      FFP.ffpVideoPropertyiv(FFP_VIDEO_DITHER_PALETTE_RGB, new int[] { r, g, b });
      OSGDevice.osg_resizable(false);
   }

   @Override
   public void osg_load() {

   }

   @Override
   public void osg_update(OSGInput input, long elapsed_time) {
      if (input.key_pressed(OSGInput.KEY_W)) {
         rotate = !rotate;
      }
      if (input.key_pressed(OSGInput.KEY_A)) {
         roty = 0;
      }
      boolean change = false;
      if (input.key_pressed(OSGInput.KEY_R)) {
         r++;
         change = true;
      }
      if (input.key_pressed(OSGInput.KEY_G)) {
         g++;
         change = true;
      }
      if (input.key_pressed(OSGInput.KEY_B)) {
         b++;
         change = true;
      }
      r &= 0xff;
      g &= 0xff;
      b &= 0xff;
      if (r * g * b > 256) {
         r = 1;
         g = 1;
         b = 1;
      }
      if (change) {
         FFP.ffpVideoPropertyiv(FFP_VIDEO_DITHER_PALETTE_RGB, new int[] { r, g, b });
      }
      if (input.key_pressed(OSGInput.KEY_R)) {
         r++;
         change = true;
      }
   }

   @Override
   public void osg_render() {
      FFP.ffpClear(FFP_VIDEO_MEMORY | FFP_DEPTH_MEMORY);
      FFP.ffpPushMatrix();
      FFP.ffpRotatef(roty, 0, 1, 0);
      FFP.ffpBegin(FFP_TRIANGLES);
      FFP.ffpColor3i(255, 0, 0);
      FFP.ffpVertex2f(-1.0f, -1.0f);
      FFP.ffpColor3i(0, 255, 0);
      FFP.ffpVertex2f(1.0f, -1.0f);
      FFP.ffpColor3i(0, 0, 255);
      FFP.ffpVertex2f(-1.0f, 1.0f);
      FFP.ffpEnd();
      FFP.ffpPopMatrix();
      FFP.ffpFlush(FFP_MULTI_THREADED);
      int start = 0;
      int cheight = OSGVideo.vid_sysfont_height() + 4;
      OSGVideo.vid_draw_text("colors: " + (r * g * b), 2, start += cheight, 0xffffff);
      OSGVideo.vid_draw_text("red: " + r, 2, start += cheight, 0xff0000);
      OSGVideo.vid_draw_text("green: " + g, 2, start += cheight, 0x00ff00);
      OSGVideo.vid_draw_text("blue: " + b, 2, start += cheight, 0x0000ff);
      if (rotate) {
         roty += 0.5f;
      }
   }

   @Override
   public void osg_resize(int wnd_width, int wnd_height) {

   }

   @Override
   public void osg_exit() {

   }

}





Dump your java code here :



Special syntax:
  • To highlight a line (yellow background), prefix it with '@@'
  • To indicate that a line should be removed (red background), prefix it with '-'
  • To indicate that a line should be added (green background), prefix it with '+'
  • To post multiple snippets, seperate them by '~~~~'
  EOF
 
Sralse (15 views)
2017-07-25 17:13:48

Archive (414 views)
2017-04-27 17:45:51

buddyBro (595 views)
2017-04-05 03:38:00

CopyableCougar4 (1058 views)
2017-03-24 15:39:42

theagentd (1089 views)
2017-03-24 15:32:08

Rule (1059 views)
2017-03-19 12:43:22

Rule (1045 views)
2017-03-19 12:42:17

Rule (1037 views)
2017-03-19 12:36:21

theagentd (1178 views)
2017-03-16 05:07:07

theagentd (1141 views)
2017-03-15 22:37:06
List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05

SF/X Libraries
by SkyAphid
2017-03-02 06:38:56

SF/X Libraries
by SkyAphid
2017-03-02 06:38:32

SF/X Libraries
by SkyAphid
2017-03-02 06:38:05

SF/X Libraries
by SkyAphid
2017-03-02 06:37:51
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!