Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (482)
Games in Android Showcase (110)
games submitted by our members
Games in WIP (550)
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: Code Mage (posted 2014-07-08 23:49:08, viewed 45 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  
//create vao and vbo
for (int i = 0; i < vertices.length/4; i++) {
   elementsBuffer.put(vertices[i*4]);
   elementsBuffer.put(vertices[i*4+1]);
   elementsBuffer.put(vertices[i*4+2]);
   elementsBuffer.put(vertices[i*4+3]);
         
   elementsBuffer.put(normals[i*3]);
   elementsBuffer.put(normals[i*3+1]);
   elementsBuffer.put(normals[i*3+2]);
      
   elementsBuffer.put(ambient[i*3]);
   elementsBuffer.put(ambient[i*3+1]);
   elementsBuffer.put(ambient[i*3+2]);
         
   elementsBuffer.put(diffuse[i*3]);
   elementsBuffer.put(diffuse[i*3+1]);
   elementsBuffer.put(diffuse[i*3+2]);
         
   elementsBuffer.put(specular[i*3]);
   elementsBuffer.put(specular[i*3+1]);
   elementsBuffer.put(specular[i*3+2]);
}
elementsBuffer.flip();
      
indicesCount = indices.length;
ByteBuffer indicesBuffer = BufferUtils.createByteBuffer(indicesCount);
indicesBuffer.put(indices);
indicesBuffer.flip();
   
vaoId = GL30.glGenVertexArrays();
GL30.glBindVertexArray(vaoId);
      
vboId = GL15.glGenBuffers();
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, vboId);
GL15.glBufferData(GL15.GL_ARRAY_BUFFER, elementsBuffer, GL15.GL_STATIC_DRAW);
GL20.glVertexAttribPointer(0, 4, GL11.GL_FLOAT, false, 64, 0);
GL20.glVertexAttribPointer(1, 3, GL11.GL_FLOAT, false, 64, 16);
GL20.glVertexAttribPointer(2, 3, GL11.GL_FLOAT, false, 64, 28);
GL20.glVertexAttribPointer(3, 3, GL11.GL_FLOAT, false, 64, 40);
GL20.glVertexAttribPointer(4, 3, GL11.GL_FLOAT, false, 64, 52);
GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
      
GL30.glBindVertexArray(0);
      
vboiId = GL15.glGenBuffers();
GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vboiId);
GL15.glBufferData(GL15.GL_ELEMENT_ARRAY_BUFFER, indicesBuffer, GL15.GL_STATIC_DRAW);
GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0);

   
//render
GL30.glBindVertexArray(vaoId);
      
GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vboiId);
      
GL11.glDrawElements(GL11.GL_POINTS, indicesCount, GL11.GL_UNSIGNED_BYTE, 0);


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  
//vertex shader
#version 150 core

uniform mat4 matrix;
uniform mat4 rotationMatrix;
uniform mat4 view;
uniform mat4 perspective;

in vec4 in_Position;
in vec3 in_Ambience;
in vec3 in_Diffuse;
in vec3 in_Specular;
in vec3 in_Normal;

out vec4 pass_Position;
out vec3 pass_Ambience;
out vec3 pass_Diffuse;
out vec3 pass_Specular;
out vec3 pass_Normal;

void main(void) {
   
   gl_Position=in_Position;
   pass_Position=in_Position;
   
   pass_Position= in_Position;
   pass_Normal= vec3(rotationMatrix * vec4(in_Normal, 0));
   pass_Ambience=in_Ambience;
   pass_Diffuse=in_Diffuse;
   pass_Specular=in_Specular;
}


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  
//fragment shader
#version 150 core
uniform sampler2D texture_diffuse;
vec4 lightPos=vec4(0.0, 0.0, -1.0, 0.0);

in vec4 pass_Position;
in vec3 pass_Ambience;
in vec3 pass_Diffuse;
in vec3 pass_Specular;
in vec3 pass_Normal;


vec3 Ls = vec3 (1.0, 1.0, 1.0); // white specular colour
vec3 Ld = vec3 (0.7, 0.7, 0.7); // dull white diffuse light colour
vec3 La = vec3 (0.2, 0.2, 0.2); // grey ambient colour

float specular_exponent = 3; // specular 'power'

out vec4 out_Color;

void main(void) {
   out_Color = pass_Position;

   vec3 lightDir=vec3(normalize(lightPos-pass_Position));
   vec3 eyeDir=normalize(-vec3(pass_Position));

   // ambient intensity
   vec3 Ia = La * pass_Ambience;

     // diffuse intensity
   vec3 distance_to_light_eye = vec3(lightPos - pass_Position);
   vec3 direction_to_light_eye = normalize (distance_to_light_eye);
     float dot_prod = dot (direction_to_light_eye, pass_Normal);
     dot_prod = max (dot_prod, 0.0);
     vec3 Id = Ld * pass_Diffuse * dot_prod;

     // specular intensity
   vec3 Is=vec3(0.0, 0.0, 0.0);
   direction_to_light_eye = vec3(normalize (-pass_Position+lightPos));
     vec3 surface_to_viewer_eye = normalize (-vec3(pass_Position));
   vec3 reflection=reflect(-direction_to_light_eye, pass_Normal);
     float dot_prod_specular = dot (reflection, surface_to_viewer_eye);
     dot_prod_specular = max (dot_prod_specular, 0.0);
     float specular_factor = pow (dot_prod_specular, specular_exponent);
   
   if(dot(surface_to_viewer_eye, pass_Normal)>0){ // final specular intensity
        Is = Ls * pass_Specular * specular_factor;
   }

     // final colour
     out_Color = vec4 (Id + Ia + Is, 1.0);
}





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.

CopyableCougar4 (14 views)
2014-08-22 19:31:30

atombrot (28 views)
2014-08-19 09:29:53

Tekkerue (25 views)
2014-08-16 06:45:27

Tekkerue (23 views)
2014-08-16 06:22:17

Tekkerue (15 views)
2014-08-16 06:20:21

Tekkerue (22 views)
2014-08-16 06:12:11

Rayexar (61 views)
2014-08-11 02:49:23

BurntPizza (39 views)
2014-08-09 21:09:32

BurntPizza (31 views)
2014-08-08 02:01:56

Norakomi (37 views)
2014-08-06 19:49:38
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

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!