Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (526)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (593)
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: Cero (posted 2012-02-28 19:36:43, viewed 158176 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   130   131   132   133   134   135   136   137   138   139   140  
package main;

import java.nio.ByteBuffer;

import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.opengl.GL11;

import uk.co.caprica.vlcj.player.MediaPlayerFactory;
import uk.co.caprica.vlcj.player.direct.DirectMediaPlayer;
import uk.co.caprica.vlcj.player.direct.RenderCallback;

import com.sun.jna.Memory;
 
public class VLCJinLWJGL implements RenderCallback
{
   private MediaPlayerFactory mediaPlayerFactory;
    private DirectMediaPlayer mediaPlayer;
    private ByteBuffer buf = null;
    
    public static void main(String[] argv)
   {
      VLCJinLWJGL example = new VLCJinLWJGL();
      example.start();
   }
   
   public VLCJinLWJGL()
   {
      System.setProperty("jna.library.path", "vlib");
       if (isMac())
          mediaPlayerFactory = new MediaPlayerFactory(new String[] {"--no-video-title-show", "--plugin-path=vlib/plugins", "--vout=macosx"});
       else
          mediaPlayerFactory = new MediaPlayerFactory(new String[] {"--no-video-title-show", "--plugin-path=vlib/plugins"});
       
        mediaPlayer = mediaPlayerFactory.newDirectMediaPlayer("RGBA", 1280, 544, 1280 * 4, this);
        mediaPlayer.playMedia("diehard4.mov");
    }
    
    public static boolean isMac()
    {
       return (System.getProperty("os.name").toLowerCase().indexOf( "mac" ) >= 0); 
   }
    
   public void start()
   {
      initGL(1280,544); // init OpenGL
 
      while (!Display.isCloseRequested())
      {
         if (buf != null)
         {
             GL11.glTexImage2D(GL11.GL_TEXTURE_2D,
                       0,
                       GL11.GL_RGB,
                       get2Fold(1280),
                       get2Fold(544),
                       0,
                       GL11.GL_RGB,
                       GL11.GL_UNSIGNED_BYTE,
                       buf );
         }
         
         // Clear The Screen And The Depth Buffer
         GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
         GL11.glPushMatrix();
         
            GL11.glBindTexture(GL11.GL_TEXTURE_2D, 1);
//            texture.bind();
            
            GL11.glBegin(GL11.GL_QUADS);
            {
               GL11.glTexCoord2f(0,0);
               GL11.glVertex2f(0,0);
               GL11.glTexCoord2f(1,0);
               GL11.glVertex2f(0+get2Fold(1280),0);
               GL11.glTexCoord2f(1,1);
               GL11.glVertex2f(0+get2Fold(1280),0+get2Fold(544));
               GL11.glTexCoord2f(0,1);
               GL11.glVertex2f(0,0+get2Fold(544));
            }
            GL11.glEnd();
            
         GL11.glPopMatrix();
 
         Display.update();
         Display.sync(60);
      }
      
      mediaPlayer.stop();
          mediaPlayer.release();
          mediaPlayerFactory.release();
          mediaPlayerFactory = null;
          mediaPlayer = null;
 
      Display.destroy();
   }

 
   private void initGL(int width, int height) {
      try {
         Display.setDisplayMode(new DisplayMode(width,height));
         Display.create();
         Display.setVSyncEnabled(true);
      } catch (LWJGLException e) {
         e.printStackTrace();
         System.exit(0);
      }
 
      GL11.glEnable(GL11.GL_TEXTURE_2D);               
 
      GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);          
 
        // enable alpha blending
        GL11.glEnable(GL11.GL_BLEND);
        GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
 
        GL11.glViewport(0,0,width,height);
      GL11.glMatrixMode(GL11.GL_MODELVIEW);
 
      GL11.glMatrixMode(GL11.GL_PROJECTION);
      GL11.glLoadIdentity();
      GL11.glOrtho(0, width, height, 0, 1, -1);
      GL11.glMatrixMode(GL11.GL_MODELVIEW);
   }
   
   @Override
   public void display(Memory memory)
   {
      buf = memory.getByteBuffer(0, 1280 * 544 * 4);
   }
   
   private static int get2Fold(int fold) {
        int ret = 2;
        while (ret < fold) {
            ret *= 2;
        }
        return ret;
    }
}





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
 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

toopeicgaming1999 (73 views)
2014-11-26 15:22:04

toopeicgaming1999 (62 views)
2014-11-26 15:20:36

toopeicgaming1999 (15 views)
2014-11-26 15:20:08

SHC (29 views)
2014-11-25 12:00:59

SHC (27 views)
2014-11-25 11:53:45

Norakomi (32 views)
2014-11-25 11:26:43

Gibbo3771 (27 views)
2014-11-24 19:59:16

trollwarrior1 (40 views)
2014-11-22 12:13:56

xFryIx (78 views)
2014-11-13 12:34:49

digdugdiggy (56 views)
2014-11-12 21:11:50
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
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!