Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (753)
Games in Android Showcase (228)
games submitted by our members
Games in WIP (842)
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 7737 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

JGO Kernel

Medals: 197
Projects: 4
Exp: 8 years

I did not hit her! I did not!

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

Here's an amazing tutorial on what shaders do:

And for loading shaders into java objects, I don't mind you cheating off my implementation (It's not finished, but its working):

Some example code on how to load/use them from my object:
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");;

For rendering something with the shader:
        //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);

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

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

« JGO Bitwise Duke »

Medals: 485
Exp: 7 years

« 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):
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".

Julien Gouesse | Personal blog | Website | Jogamp
Offline GNecro1
« Reply #6 - Posted 2014-07-29 14:43:38 »

I meant i dont have any libs !!

Java freak! Cheesy
Offline Longor1996

JGO Wizard

Medals: 115
Projects: 2
Exp: 8 years

The cake is probably a lie.

« 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

Offline ra4king

JGO Kernel

Medals: 507
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  

ivj94 (580 views)
2018-03-24 14:47:39

ivj94 (44 views)
2018-03-24 14:46:31

ivj94 (371 views)
2018-03-24 14:43:53

Solater (60 views)
2018-03-17 05:04:08

nelsongames (107 views)
2018-03-05 17:56:34

Gornova (147 views)
2018-03-02 22:15:33

buddyBro (690 views)
2018-02-28 16:59:18

buddyBro (90 views)
2018-02-28 16:45:17

xxMrPHDxx (492 views)
2017-12-31 17:17:51

xxMrPHDxx (728 views)
2017-12-31 17:15:51
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

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 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‑
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!