Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (499)
Games in Android Showcase (118)
games submitted by our members
Games in WIP (567)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Shader libs?  (Read 2064 times)
0 Members and 1 Guest are viewing this topic.
Offline GNecro1
« Posted 2014-07-27 13:09:52 »

Is there any lib that provides you with using shaders? What i meant is that I am making a game in java, pure java no libs but i want shaders in my game. So is it posible that you just add it to my game and render it?

Java freak! Cheesy
Offline PandaMoniumHUN

JGO Coder


Medals: 32
Exp: 3 years


White-bearded OGL wizard


« Reply #1 - Posted 2014-07-27 13:23:05 »

Why would you need a library for that?
You can implement shaders in less than 50 lines of code.
The process for a shader: Generate an id for the shader, attach source, compile, check if successfully compiled(, if not log the shader's infolog).
For a shader program: Generate an id, attach shaders, link, check if successfully linked(, if not print the program's infolog), detach and delete shaders, optionally validate the program.

It might seem scary at first written out like that but it is actually pretty simple. Smiley
Sorry for not providong code examples but I'm currently on mobile.

Edit: Oh, you mean pure Java as Java2D? In that case you can't use shaders since those are part of OpenGL.

My Blog | Jumpbutton Studio - INOP Programmer
Can't stress enough: Don't start game development until you haven't got the basics of programming down! Pointing
Offline Ecumene

Senior Member


Medals: 5


Generating memes since 2013!


« Reply #2 - Posted 2014-07-28 20:06:09 »

Here's an amazing tutorial on what shaders do:
https://www.youtube.com/watch?v=bgckX62f4EA

And for loading shaders into java objects, I don't mind you cheating off my implementation (It's not finished, but its working):
https://github.com/ecumene-software/LibEcu/blob/master/source/ecumene/opengl/Shader.java

Some example code on how to load/use them from my object:
1  
2  
3  
4  
5  
6  
7  
8  
9  
ambient = new Shader();
//Attaching source files:
ambient.attachShaderSource(new File("./assets/shaders/ambient.fs"), GL20.GL_FRAGMENT_SHADER);
ambient.attachShaderSource(new File("./assets/shaders/ambient.vs"), GL20.GL_VERTEX_SHADER);
//Using them with VAOs:
ambient.bindAttribute(0, "in_Position");
ambient.bindAttribute(1, "in_TextureUV");
ambient.bindAttribute(2, "in_Color");
ambient.link();


For rendering something with the shader:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
ambient.bind();
        //Uniforms can only be set after the shader is being used!!!
       //Setting uniform matrices
  ambient.setUniformM4("projMatrix", true, camera.getProjection());
   ambient.setUniformM4("viewMatrix", true, camera.getView());
   
        //For setting "samplers" with "texture units (multi-texture)" use glUniformi NOT glUniformf
  ambient.setUniformi("diffuse", 0);
        //For setting a uniform vec4 (vector 4 data being used as a color)
  ambient.setUniformf("ambientLight", 1f, 1f, 1f, 1f);
        renderMyObjects();
ambient.unbind();


EDIT: And if you have any small questions, just PM me, I'm fine with that. Smiley

You acknowledge that this software is not designed, licensed or intended for use in the design, construction, operation or maintenance of any nuclear facility.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline SHC
« Reply #3 - Posted 2014-07-29 04:25:19 »

I think he meant to use shaders with Java2D. It is IMPOSSIBLE.

Offline BurntPizza
« Reply #4 - Posted 2014-07-29 06:16:50 »

Waiting for lib to transpile GLSL to BufferedImageOps. Roll Eyes
Not that it would be thoroughly useless or anything...
Offline gouessej
« Reply #5 - Posted 2014-07-29 13:05:19 »

And for loading shaders into java objects, I don't mind you cheating off my implementation (It's not finished, but its working):
https://github.com/ecumene-software/LibEcu/blob/master/source/ecumene/opengl/Shader.java
Your code goes a lot less farther than the usual shader code / program / state abstraction implemented in some engines and in JogAmp.

Shaders might be used with hardware accelerated implementations of Java2D based on OpenGL but not the build-in one. However, it defeats the purpose of something "pure Java, no libs".

Offline GNecro1
« Reply #6 - Posted 2014-07-29 14:43:38 »

I meant i dont have any libs !!

Java freak! Cheesy
Offline Longor1996
« Reply #7 - Posted 2014-07-29 14:50:39 »

I meant i dont have any libs !!


That doesn't make any sense at all.

If you want to make a game with pure Java, you have to use Java2D, which does not provide shaders.
You can't have "shaders" with pure Java. Its impossible.

You will need to use LWJGL/JogAmp or (even better) libGDX.
These give you the ability to use shaders.

Have a nice day.

- Longor1996

Sorry for my bad English! That's because i am from Germany.
Offline ra4king

JGO Kernel


Medals: 347
Projects: 3
Exp: 5 years


I'm the King!


« Reply #8 - Posted 2014-07-30 03:18:37 »

It's not that it's impossible, it's that OP has no clue what shaders are in the first place, as it doesn't make sense to ask for shaders at the level of abstraction Java2D offers.

Offline Longarmx
« Reply #9 - Posted 2014-07-30 05:43:53 »

You can create your own GLSL parser for the files, and then draw everything (through a "fragment shader") to a fullscreen BufferedImage. This isn't hardware accelerated though, which is why you would use shaders in the first place.

Also, it would be pointless to do something like this, when you have perfectly good, hardware accelerated shaders provided by Opengl that require minimal effort to get working.

Pages: [1]
  ignore  |  Print  
 
 

 

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

The first screenshot will be displayed as a thumbnail.

Pippogeek (37 views)
2014-09-24 16:13:29

Pippogeek (29 views)
2014-09-24 16:12:22

Pippogeek (18 views)
2014-09-24 16:12:06

Grunnt (42 views)
2014-09-23 14:38:19

radar3301 (24 views)
2014-09-21 23:33:17

BurntPizza (60 views)
2014-09-21 02:42:18

BurntPizza (30 views)
2014-09-21 01:30:30

moogie (36 views)
2014-09-21 00:26:15

UprightPath (49 views)
2014-09-20 20:14:06

BurntPizza (52 views)
2014-09-19 03:14:18
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!