Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (523)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (592)
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  
  Shaders took my textures!  (Read 1212 times)
0 Members and 1 Guest are viewing this topic.
Offline wessles

JGO Wizard


Medals: 74
Projects: 4
Exp: 4 years


Radirius Software


« Posted 2013-09-28 18:52:26 »

So, I decided to implement shaders into my game engine, and it took away my textures! It just renders every shape in color with:

shader.fs
1  
2  
3  
4  
5  
varying vec3 color;

void main() {
    gl_FragColor = vec4(color, 1);
}


shader.vs
1  
2  
3  
4  
5  
6  
varying vec3 color;

void main() {
    color = gl_Color.rgb;
    gl_Position = ftransform();
}


Why are my textures gone!?

Sorry if this is nooby, but I literally just found out about shaders. I literally only know how to load and use them in java. None of the glsl stuffs.

Offline pjt33
« Reply #1 - Posted 2013-09-28 19:07:56 »

I've never used textures with shaders - in fact I've barely used shaders - but two minutes' Googling leads me to the conclusion that you're missing an assignment along the lines of gl_TexCoord[0] = gl_MultiTexCoord0; in the vertex shader and gl_FragColor = texture2D(sampler, gl_TexCoord[0].xy); in the fragment shader.
Offline opiop65

JGO Kernel


Medals: 159
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #2 - Posted 2013-09-28 19:11:24 »

Take a look at these tutorials:
https://github.com/mattdesl/lwjgl-basics/wiki/Shaders
Take from the site:
  vertex shader:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
//combined projection and view matrix
uniform mat4 u_projView;

//"in" attributes from our SpriteBatch
attribute vec2 Position;
attribute vec2 TexCoord;
attribute vec4 Color;

//"out" varyings to our fragment shader
varying vec4 vColor;
varying vec2 vTexCoord;
 
void main() {
   vColor = Color;
   vTexCoord = TexCoord;
   gl_Position = u_projView * vec4(Position, 0.0, 1.0);
}

Fragment shader:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
//SpriteBatch will use texture unit 0
uniform sampler2D u_texture;

//"in" varyings from our vertex shader
varying vec4 vColor;
varying vec2 vTexCoord;

void main() {
   //sample the texture
   vec4 texColor = texture2D(u_texture, vTexCoord);
   
   //invert the red, green and blue channels
   texColor.rgb = 1.0 - texColor.rgb;
   
   //final color
   gl_FragColor = vColor * texColor;
}

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline RobinB

JGO Ninja


Medals: 44
Projects: 1
Exp: 3 years


Spacegame in progress


« Reply #3 - Posted 2013-09-28 21:32:56 »

//In java
1. Pass texture coordinates each vertrice
2. Pass uniform texture

//In vertex shader
3. Pass texture coordinates to fragment shader

//In fragment shader
4. Sample texture in shader using Texture2D
Offline opiop65

JGO Kernel


Medals: 159
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #4 - Posted 2013-09-29 00:36:56 »

Thats an odd class to put your main method in!

Offline opiop65

JGO Kernel


Medals: 159
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #5 - Posted 2013-09-29 12:54:47 »

Hmm... No I guess not, you win Smiley I just like keeping my main method in very generic classes like the Main class, even if its just a one class example project Tongue I always have a seperate class just for the main method! Just one of my weird things I guess.

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

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

The first screenshot will be displayed as a thumbnail.

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

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

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

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

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

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

digdugdiggy (52 views)
2014-11-12 21:11:50

digdugdiggy (46 views)
2014-11-12 21:10:15

digdugdiggy (41 views)
2014-11-12 21:09:33

kovacsa (67 views)
2014-11-07 19:57:14
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!