Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (487)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (553)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1]
1  Java Game APIs & Engines / OpenGL Development / Regarding Shader Attributes on: 2014-07-09 01:57:54
I get the basic gist of how shaders work, but looking at Matt DesLauriers' excellent tutorials, he's using the SpriteBatch object for quite a bit... this left me wondering how you would "manually" pass in the Position, Color, and TexCoord attributes to the Vertex shader.

These are usually handled by the SpriteBatch object, but I'm using some old-school style rendering for the FBO as follows...

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
int attributeLoc = ARBShaderObjects.glGetUniformLocationARB(currentShader, "texture");
ARBShaderObjects.glUseProgramObjectARB(currentShader);                        
ARBShaderObjects.glUniform1iARB(attributeLoc, fboTexture);

GL11.glColor4f(1, 1, 1, 1);
GL11.glBegin(GL11.GL_QUADS);
           
// Top Left
GL11.glTexCoord2f(0.0f, 1.0f);
GL11.glVertex2i(x, y);        
// Top Right
GL11.glTexCoord2f(1.0f, 1.0f);
GL11.glVertex2i(x + width,  y);      
// Bottom Right
GL11.glTexCoord2f(1.0f, 0.0f);
GL11.glVertex2i(x + width, y + height);      
// Bottom Left      
GL11.glTexCoord2f(0.0f, 0.0f);      
GL11.glVertex2i(x, y + height);  
GL11.glEnd();


What variables can I attach to the shader attributes in place of what SpriteBatch would usually provide?

- Steve
2  Game Development / Newbie & Debugging Questions / Re: Screen Capture To Texture (OpenGL / Slick2D) on: 2014-07-08 00:59:59
Hey guys! I got it! Thank you! Smiley

- Steve
3  Games Center / WIP games, tools & toy projects / Re: Jumproom on: 2014-07-07 19:48:18
Played through the first set of levels during the initial release a month or two ago. I'm really looking forward to trying this new set of levels as well.

For me, the simplicity is ideal for touch platforms, but it still has the charm and challenge of a full-blown title. Very good for pick-up n' play. Grin

- Steve
4  Game Development / Newbie & Debugging Questions / Re: Screen Capture To Texture (OpenGL / Slick2D) on: 2014-07-04 18:17:47
I understand what you're saying, but I've already got a ton of code in place for this and the most pain-free way to integrate this functionality in is to copy the screen to a Texture. Otherwise, I'll have to completely change how everything I'm doing is rendered.

Thanks for the advice either way.

- Steve
5  Game Development / Newbie & Debugging Questions / Re: Screen Capture To Texture (OpenGL / Slick2D) on: 2014-07-04 17:06:08
I'm also wondering if this issue has anything to do with the resulting texture's dimensions not being a power of 2.

 Huh Huh Huh

- Steve
6  Game Development / Newbie & Debugging Questions / Re: Screen Capture To Texture (OpenGL / Slick2D) on: 2014-07-04 16:50:16
I need a way to call back to the captured screen image though while I'm in a screen transition loop, so I figured having a Texture object to reference would be the best way.

Capturing the screen basically helps me avoid redrawing every object each step through the transition loop; instead I just draw the captured screen.

- Steve
7  Game Development / Newbie & Debugging Questions / Re: Screen Capture To Texture (OpenGL / Slick2D) on: 2014-07-04 16:36:38
I tried the drawTexture method with another Texture already loaded in and it worked fine, so the issue is definitely with the getTextureFromScreen method.

- Steve
8  Game Development / Newbie & Debugging Questions / Screen Capture To Texture (OpenGL / Slick2D) on: 2014-07-04 16:30:54
Alright, so I'm trying to capture the current screen to a Texture object that I can render in all kinds of fun ways... I'm using the LWJGL tutorial on taking a screenshot, but rather than save that ByteBuffer to a file, I'm trying to create a Slick2D Texture from it.

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  
   public static org.newdawn.slick.opengl.Texture getTextureFromScreen()
   {
      // Copies the current screen.
     GL11.glReadBuffer(GL11.GL_FRONT);
      int width = Display.getDisplayMode().getWidth();
      int height= Display.getDisplayMode().getHeight();
     
      java.nio.ByteBuffer buffer = org.lwjgl.BufferUtils.createByteBuffer(width * height * 4);      
      GL11.glReadPixels(0, 0, width, height, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buffer);            
     
      int textureId = GL11.glGenTextures();
      TextureImpl tex = new TextureImpl("screen", GL11.GL_TEXTURE_2D, textureId);
     
      // produce a texture from the byte buffer
     GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureId);
      GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_REPEAT);
        GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_REPEAT);            
      GL11.glTexParameteri(GL11.GL_TEXTURE_2D,GL11.GL_TEXTURE_MIN_FILTER,GL11.GL_LINEAR);
      GL11.glTexParameteri(GL11.GL_TEXTURE_2D,GL11.GL_TEXTURE_MAG_FILTER,GL11.GL_LINEAR);
      GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, width, height, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buffer);            
     
      return tex;        
   }

   public static void drawTexture(float x, float y, Texture texture, int width, int height, int srcX, int srcY, int srcWidth, int srcHeight, float red, float green, float blue, float alpha, float angle)
   {      
      // If the provided texture string is null or empty, don't try to draw it. :)
     if(texture != null)
      {                                
         texture.bind();
         
         float fSrcX = ((float)srcX / texture.getTextureWidth());
         float fSrcY = ((float)srcY / texture.getTextureHeight());
         float fSrcWidth = (((float)srcX + (float)srcWidth) / texture.getTextureWidth());
         float fSrcHeight = (((float)srcY + (float)srcHeight) / texture.getTextureHeight());        
         
         GL11.glPushMatrix();            
                     
         // Rotation
        if(angle != 0)
         {
            GL11.glTranslatef(x + (width / 2), y + (height / 2), 0); // move to the proper position
           GL11.glRotatef(angle, 0, 0, 1); // now rotate
           GL11.glTranslatef(-1 *(x+ (width / 2)), -1 * (y+(height  / 2)), 0);            
         }
         
         GL11.glColor4f(red, green, blue, alpha);
         GL11.glBegin(GL11.GL_QUADS);
            // Top Left
           GL11.glTexCoord2f(fSrcX, fSrcY);
            GL11.glVertex2f(x,y);
            // Top Right
           GL11.glTexCoord2f(fSrcWidth, fSrcY);
            GL11.glVertex2f(x + width, y);
            // Bottom Right
           GL11.glTexCoord2f(fSrcWidth,fSrcHeight);
            GL11.glVertex2f(x + width,y + height);
            // Bottom Left
           GL11.glTexCoord2f(fSrcX,fSrcHeight);
            GL11.glVertex2f(x,y + height);
         GL11.glEnd();
         
         GL11.glPopMatrix();
      }        
   }


I've had some weird results thus far including the resulting texture only capturing one pixel's color (at least that's how it renders) and getting some errors about the ByteBuffer size. Any ideas??

- Steve
9  Games Center / Showcase / Re: Dangerous Dave on: 2014-06-19 20:41:26
Old school pixel goodness! What's not to love!  Cool

A few things I noticed:
  • There was some ghosting whenever the map was rotating in the second level
  • It might be this way to emulate the original, but the falling and walking feels really slow for me
  • The player 1 control scheme felt cramped; maybe the jetpack keys could move to z and x or something on the left side of the keyboard. Smiley

Overall though, nice-looking little game. I love this kind of stuff.

- Steve
10  Games Center / WIP games, tools & toy projects / Re: Moon Pad v0.3 on: 2014-04-22 23:08:24
A java program for writing java programs...

<neo>...woah...</neo>  Cool

- Steve
11  Games Center / WIP games, tools & toy projects / Re: Helibomber SDX on: 2014-04-22 23:03:22
Hey guys! I'm pleased to report the game is done and can be moved out of the WIP section! Woo! Grin

http://sfsoftware.sevensoupcans.com/games/helibomber-sdx/

Thanks for the interest! If anyone happens to grab it, please let me know if there are any weird issues. About six people tested it across various operating systems, but things still happen!

Special thanks to the community including the dudes behind LWJGL, Slick2D, and JOrbis!! It's so awesome to see an active community for this stuff!

- Steve
12  Games Center / WIP games, tools & toy projects / Re: Helibomber SDX on: 2014-04-21 14:57:06
Just a quick update on this game - it's in beta now and will be released very soon. We've even got a nice little page up for it on our site here: http://sfsoftware.sevensoupcans.com/games/helibomber-sdx/

It would have been finished sooner, but real life intervenes and things get pushed aside... you know how it goes. Smiley I'm looking forward to see how high some of these scores will go once it's released!

- Steve
13  Game Development / Newbie & Debugging Questions / Re: Loading Resources in Runnable Jar on: 2014-04-17 00:42:45
Danny, you're a lifesaver! That worked great!

Now I'm just going to strip out the Guava stuff; very useful tool!

- Steve
14  Game Development / Newbie & Debugging Questions / Re: Loading Resources in Runnable Jar on: 2014-04-16 15:02:35
Wow! That is awesome! I'm going to have to give this a shot; thank you so much! Smiley

- Steve
15  Game Development / Newbie & Debugging Questions / Loading Resources in Runnable Jar on: 2014-04-16 13:55:07
So, I have the following code in a method to load all PNG files found in a specific directory as textures.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
String files;
File folder = new File(GRAPHICS_FILE_PATH);
File[] listOfFiles = folder.listFiles();
           
for (int i = 0; i < listOfFiles.length; i++)
{          
       if (listOfFiles[i].isFile())
       {
          files = listOfFiles[i].getName();
           if (files.endsWith(".png") || files.endsWith(".PNG"))
           {                    
              Texture temp = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream(GRAPHICS_FILE_PATH + "/" + files));
              texture.put(files.substring(0, files.indexOf(".")), temp);
                }
        }
}


This works great when testing in the IDE, but I want to distribute my final program as a runnable jar. Since there is only a single jar file and not this blown up file structure, the program freaks out saying it can't find the specified resource.

If I hard code the texture names, slick's ResourceLoader class works great in a jar or when the file structure exists; where's the fun in hard-coding all those texture filenames though? This is programming; we want things done automatically! Wink

My question is: is there a simple way to retrieve all the resources at a specific path in either a jar or file structure? I found this method, but I'm not having much luck implementing it in a way I can just point to "res/graphics"; it seems to depend on the same folder where the provided class exists.

- Steve
16  Games Center / WIP games, tools & toy projects / Re: Helibomber SDX on: 2014-01-07 13:51:07
Here's a short trailer showing the arcade action in motion! Take a look!  Shocked

<a href="http://www.youtube.com/v/sPZsyAwuSp0?version=3&amp;hl=en_US&amp;start=" target="_blank">http://www.youtube.com/v/sPZsyAwuSp0?version=3&amp;hl=en_US&amp;start=</a>

- Steve
17  Games Center / WIP games, tools & toy projects / Helibomber SDX on: 2014-01-05 20:53:07
Hey guys!

Port/rewrite of the old S&F Software freeware game Helibomber DX here - Helibomber SDX (SUPER Deluxe)!! New additions include original soundtrack, controller support, online high scores, and some fun, new gameplay features.



Basically, if you like some of the classics like Defender of Choplifter, you'll be able to sink some time into this one. It's a very straightforward arcade-type game that gets hard pretty quickly.

Follow us on twitter for updates! More info coming soon!

- Steve
18  Java Game APIs & Engines / OpenGL Development / Re: Easiest Way to Pass Textures to Fragment Shader on: 2013-09-03 19:08:56
Hmm, then I find pages like this where it makes me think those can just be populated by something like this in the vertex shader:

1  
2  
3  
4  
5  
6  
7  
8  
void main()
{
    // Transforming The Vertex
   gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;

    // Passing The Texture Coordinate Of Texture Unit 0 To The Fragment Shader
   texture_coordinate = vec2(gl_MultiTexCoord0);
}


From - http://stackoverflow.com/questions/11537356/pass-through-vertex-shader-for-texture-mapping

I keep thinking about this in terms of me setting an attribute from my Java code in the shader program...

- Steve
19  Java Game APIs & Engines / OpenGL Development / Re: Easiest Way to Pass Textures to Fragment Shader on: 2013-09-03 11:50:19
So I am messing around with the rendering method for individual sprites. I think I'm starting to get an idea of how things'll work, but I still have to bind the TexCoord to the vertex shader as an attribute, correct?

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  
// Bind the current texture to the current shader if one is in use.
if(useShader)
{
     setShaderUniform(currentShader, "texture", getTextureId(temp));
}
           
temp.bind();
           
float fSrcX = ((float)srcX / temp.getTextureWidth());
float fSrcY = ((float)srcY / temp.getTextureHeight());
float fSrcWidth = (((float)srcX + (float)srcWidth) / temp.getTextureWidth());
float fSrcHeight = (((float)srcY + (float)srcHeight) / temp.getTextureHeight());
           
GL11.glColor4f(red, green, blue, alpha);
GL11.glBegin(GL11.GL_QUADS);
// Top Left
GL11.glTexCoord2f(fSrcX, fSrcY);
GL11.glVertex2f(x,y);
// Top Right
GL11.glTexCoord2f(fSrcWidth, fSrcY);
GL11.glVertex2f(x + width, y);
// Bottom Right
GL11.glTexCoord2f(fSrcWidth,fSrcHeight);
GL11.glVertex2f(x + width,y + height);
// Bottom Left
GL11.glTexCoord2f(fSrcX,fSrcHeight);
GL11.glVertex2f(x,y + height);
GL11.glEnd();


Thanks for answering the endless of array of stupid questions. Smiley

- Steve
20  Java Game APIs & Engines / OpenGL Development / Re: Easiest Way to Pass Textures to Fragment Shader on: 2013-09-03 02:41:22
So the way I'm reading this... when you bind a texture to a quad, it should automatically be handed off to the vertex shader where it can, in turn, be processed by the fragment shader?

Do you need to manually modify any uniforms in the shaders for the texture or anything?

Great tutorials, by the way. I was going off the LWJGL ones which use the ARB stuff. I've done a decent amount of 2D game dev in the past, but never really messed with shaders til now; seems like you can do some really cool stuff with them.

- Steve
21  Java Game APIs & Engines / OpenGL Development / Easiest Way to Pass Textures to Fragment Shader on: 2013-09-03 00:04:58
Hey guys,

I'm pretty new to shaders, so I'm a little bit stuck. What i'm trying to do *should* be easy. I'm trying to get the current pixel and multiply it by another color to get kind of a blue hue over the entire screen (not including the HUD). The end goal is to kind of have a night type feel to everything by doing this.

It seems like every example I am finding uses the SpriteBatch class with LibGDX or Slick to handle passing texture data to the shader. I already have a large portion of rendering code in place and I'd like to find a way to do something like this:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
ARBShaderObjects.glUseProgramObjectARB(shaderProgram);
updatePlayingField(0);      
Actor.updateCast();                        
player.update();  
updatePlayingField(1);
Particle.updateAll();
ARBShaderObjects.glUseProgramObjectARB(0);

FloatingText.updateAll();
updateHUD();


That would be in my main game loop. Basically I have a simple shader working now, but all it does is change every pixel to a specific color. All of the individual sprites are drawn in each of those methods in that loop. It doesn't seem possible that I can just get the "current" pixel color value when the fragment shader is run sadly... Sad

Is there an easy way to handle shaders without re-writing all of my existing rendering code and over-complicating the systems I already have in place? I guess another option might be that I could apply a shader to the entire buffer before rendering the HUD? I don't know - any and all suggestions are welcome. More code available upon request - didn't want to overcomplicate things since I have basic shaders already working. Grin

- Steve
Pages: [1]
 

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

The first screenshot will be displayed as a thumbnail.

TehJavaDev (13 views)
2014-08-28 18:26:30

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

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

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

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

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

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

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

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

BurntPizza (34 views)
2014-08-08 02:01:56
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!