Java-Gaming.org Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (799)
Games in Android Showcase (236)
games submitted by our members
Games in WIP (865)
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: deepthought (posted 2015-06-30 15:36:52, viewed 571 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   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   195   196   197   198   199   200   201   202   203   204   205   206   207   208   209   210   211   212   213   214   215   216   217   218   219   220   221   222   223   224   225   226   227   228   229   230   231   232   233   234   235   236   237   238   239   240   241   242   243   244   245   246   247   248   249   250   251   252   253   254   255   256   257   258   259   260   261   262   263   264   265   266   267   268   269   270   271   272   273   274   275   276   277   278   279   280   281   282   283   284   285   286   287   288   289   290   291   292   293   294   295   296   297   298   299   300   301   302   303   304   305   306   307   308   309   310   311   312   313   314   315   316   317   318   319   320   321   322   323   324   325   326   327   328   329   330   331   332   333   334   335   336   337   338   339   340   341   342   343   344   345   346   347   348   349   350   351   352   353   354   355   356   357   358   359   360   361   362   363   364   365   366   367   368   369   370   371   372   373   374   375   376   377   378   379   380   381   382   383   384   385   386   387   388  
package SPAGE.engine.gui;

import java.io.File;
import java.io.FileNotFoundException;
import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import java.util.Random;
import java.util.Scanner;

import javafx.application.Platform;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.HBox;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import javafx.scene.text.Text;

import org.lwjgl.BufferUtils;
import org.lwjgl.glfw.Callbacks;
import org.lwjgl.glfw.GLFW;
import org.lwjgl.glfw.GLFWCharCallback;
import org.lwjgl.glfw.GLFWCursorPosCallback;
import org.lwjgl.glfw.GLFWErrorCallback;
import org.lwjgl.glfw.GLFWKeyCallback;
import org.lwjgl.glfw.GLFWMouseButtonCallback;
import org.lwjgl.opengl.ARBVertexArrayBGRA;
import org.lwjgl.opengl.EXTBGRA;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;
import org.lwjgl.opengl.GL13;
import org.lwjgl.opengl.GL20;
import org.lwjgl.opengl.GLContext;

import static org.lwjgl.glfw.GLFW.*;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.opengl.GL15.*;
import static org.lwjgl.opengl.GL20.*;
import static org.lwjgl.opengl.GL30.*;
import static org.lwjgl.opengl.GL31.*;
import static org.lwjgl.opengl.GL32.*;
import static org.lwjgl.opengl.GL33.*;
import static org.lwjgl.system.MemoryUtil.*;


public class glembedtest {
   
   private GLFWErrorCallback errorCallback = Callbacks.errorCallbackPrint(System.err);
   
   long window;
   
   private GLFWKeyCallback keyCallback = new GLFWKeyCallback() {
       @Override
       public void invoke(long window, int key, int scancode, int action, int mods) {
          
       
          
          
           if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) {
               glfwSetWindowShouldClose(window, GL_TRUE);
           }
       }
   };
   
   
   private GLFWCursorPosCallback poscall = new GLFWCursorPosCallback()
   {

      public void invoke(long window, double x, double y) {
         
         if(plat!=null)
         {
            plat.mousemove((int)x,(int) y);
         }
         
      }
      
   };
   
   private GLFWMouseButtonCallback butt_call= new GLFWMouseButtonCallback()
   {

      public void invoke(long window, int button, int action, int mods) {
         if(plat!=null)
         {
            if(action==GLFW_PRESS)
            {
               
               
               plat.mousepress(button+1);
            }
            
            if(action==GLFW_RELEASE)
            {
               plat.mouserelease(button+1);
            }
            
            
         }
         
      }
      
   };
   
   
   private GLFWCharCallback charcall = new GLFWCharCallback()
   {

      public void invoke(long window, int codepoint) {


      plat.keytype((char)codepoint);
      }
      
   };
   
   glStagePlatform plat = new glStagePlatform(512,512, new subimageupdater());
   

   
   int vbo;
   int tcb;
   int tex;
   int program;
   

   
   public void go()
   {
      glfwSetErrorCallback(errorCallback);
      
      if (glfwInit() != GL_TRUE) {
          throw new IllegalStateException("Unable to initialize GLFW");
      }
      
      
      glfwDefaultWindowHints();
      glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
      glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
      glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
      glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
      glfwWindowHint(GLFW_RESIZABLE,GL_FALSE);
      
       window = glfwCreateWindow(512, 512, "My Title",NULL, NULL);
      if (window == NULL) {
          glfwTerminate();
          throw new RuntimeException("Failed to create the GLFW window");
      }
      
      glfwSetKeyCallback(window, keyCallback);
      glfwSetCursorPosCallback(window,poscall);
      glfwSetMouseButtonCallback(window,butt_call);
      GLFW.glfwSetCharCallback(window, charcall);

      
      glfwMakeContextCurrent(window);
      GLContext.createFromCurrent();
      
      
        Platform.runLater(new Runnable() {
            @Override
            public void run() {
           plat.setScene(createScene());
            }
       });
    

   Random r = new Random();
   

   tex=plat.setup_texture();
   

   int vao = glGenVertexArrays();
   glBindVertexArray(vao);
   
   //set up vbo
   
   float[] vbodata = {
         1f,-1f,
         -1f,-1f,
         1f,1f,
         -1f,1f,
  
      };
   
   FloatBuffer fb= BufferUtils.createFloatBuffer(vbodata.length);
   fb.put(vbodata);
   fb.flip();
   
   vbo=glGenBuffers();
   
   glBindBuffer(GL_ARRAY_BUFFER,vbo);
   
    glBufferData(GL_ARRAY_BUFFER,fb,  GL_STATIC_DRAW);
   
    float[] tcs={
          1f,1f,
          0f,1f,
          1f,0f,
         0f,0f,      
    };
    
    fb= BufferUtils.createFloatBuffer(tcs.length);
      fb.put(tcs);
      fb.flip();
    
      tcb=glGenBuffers();
      
      glBindBuffer(GL_ARRAY_BUFFER,tcb);
      
       glBufferData(GL_ARRAY_BUFFER,fb,  GL_STATIC_DRAW);
      
      
    
    program=createshaders("shaders/shader.vtex","shaders/shader.frag");
        
    glClearColor(0f, 0f, .4f, 1.0f);
    
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
      
      while (glfwWindowShouldClose(window) != GL_TRUE)
      {
       mainloop();
      }
      
      glfwDestroyWindow(window);
      keyCallback.release();
      glfwTerminate();
      errorCallback.release();
      Platform.exit();
   }
   
   public static void main(String[] args)
   {
      new glembedtest().go();
      
   }

   
   public void mainloop()
   {
      
   
      
      plat.update();
   
   
      
      glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
      glUseProgram(program);
      
      glEnableVertexAttribArray(0);
      glEnableVertexAttribArray(1);
      glBindBuffer(GL_ARRAY_BUFFER, vbo);
      GL20.glVertexAttribPointer(0, 2, GL_FLOAT, false, 0, 0);
      
      glBindBuffer(GL_ARRAY_BUFFER, tcb);
      GL20.glVertexAttribPointer(1, 2, GL_FLOAT, false, 0, 0);
      
      
      GL13.glActiveTexture(GL13.GL_TEXTURE0);
      int texloc=glGetUniformLocation(program, "mytex");
      glUniform1i(texloc,0);
      glBindTexture(GL_TEXTURE_2D, tex);
      
      
      
      glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
      


      glfwSwapBuffers(window);
      glfwPollEvents();
      

      
   }
   
   
   
    private  Scene createScene() {
        Group  root  =  new  Group();
        Scene  scene  =  new  Scene(root,new Color(1,1,1,0));
        
       
        
     

        Button button2 = new Button("Accept");
        button2.setStyle("-fx-font: 22 arial; -fx-base: #b6e7c9;");

        
        
        
       
Label label1 = new Label("Name:");
 TextField textField = new TextField ();
label1.setTextFill(Color.RED);
HBox hb = new HBox();
hb.getChildren().addAll(label1, textField,button2);
hb.setSpacing(10);

root.getChildren().add(hb);

textField.requestFocus();


button2.setOnAction(new EventHandler<ActionEvent>() {
    @Override public void handle(ActionEvent e) {
        label1.setText("Accepted");
    }
});


        
        return (scene);
    }
   
   
    
    int createshaders(String vert, String frag)
    {
       int VertexShaderID = glCreateShader(GL_VERTEX_SHADER);
        int FragmentShaderID = glCreateShader(GL_FRAGMENT_SHADER);
        
        String code="";
        try {
         Scanner scan = new Scanner(new File(vert));
         
         while(scan.hasNext())
         {
            code+=scan.nextLine()+"\n";
         }
         scan.close();
         
      glShaderSource(VertexShaderID,code);
      glCompileShader(VertexShaderID);

      int result=glGetShaderi(VertexShaderID, GL_COMPILE_STATUS);
      String log=glGetShaderInfoLog(VertexShaderID);
      System.out.println("vtx shader returned: "+log);
      
      
       scan = new Scanner(new File(frag));
      
       code="";
      while(scan.hasNext())
      {
         code+=scan.nextLine()+"\n";
      }
      scan.close();
      
   glShaderSource(FragmentShaderID,code);
   glCompileShader(FragmentShaderID);

    result=glGetShaderi(FragmentShaderID, GL_COMPILE_STATUS);
    log=glGetShaderInfoLog(FragmentShaderID);
   System.out.println("frag shader returned: "+log);
      
      
   int ProgramID = glCreateProgram();
    glAttachShader(ProgramID, VertexShaderID);
    glAttachShader(ProgramID, FragmentShaderID);
    glLinkProgram(ProgramID);
   
    result=glGetProgrami(ProgramID, GL_LINK_STATUS);
    log=glGetProgramInfoLog(ProgramID);
    System.out.println("program link returned: "+log);
         
    return ProgramID;
         
      } catch (FileNotFoundException ex) {
         
         ex.printStackTrace();
      }
        
        return -1;
        
    }
    
}





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
 
Riven (185 views)
2019-09-04 15:33:17

hadezbladez (4863 views)
2018-11-16 13:46:03

hadezbladez (1785 views)
2018-11-16 13:41:33

hadezbladez (5135 views)
2018-11-16 13:35:35

hadezbladez (1015 views)
2018-11-16 13:32:03

EgonOlsen (4367 views)
2018-06-10 19:43:48

EgonOlsen (5215 views)
2018-06-10 19:43:44

EgonOlsen (2944 views)
2018-06-10 19:43:20

DesertCoockie (3867 views)
2018-05-13 18:23:11

nelsongames (4293 views)
2018-04-24 18:15:36
Java Gaming Resources
by philfrei
2019-05-14 16:15:13

Deployment and Packaging
by philfrei
2019-05-08 15:15:36

Deployment and Packaging
by philfrei
2019-05-08 15:13:34

Deployment and Packaging
by philfrei
2019-02-17 20:25:53

Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45
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!