Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (711)
Games in Android Showcase (213)
games submitted by our members
Games in WIP (785)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1] 2 3 ... 10
 1 
 on: 2017-02-28 02:24:46 
Started by BurntPizza - Last post by Ecumene
A friend and I have been working on a multiplayer 6DOF arena shooter. I'm too lazy to explain it so heres a screenshot, if you want more PM me Wink


 2 
 on: 2017-02-27 22:55:11 
Started by Stefantjeeh - Last post by theagentd
It seems like you just keep rotating the matrix more and more. Are you calling glLoadIdentity() somewhere to reset the matrix? glPush/PopMatrix() is really useful too.

 3 
 on: 2017-02-27 19:42:29 
Started by Stefantjeeh - Last post by Archive
http://pastebin.java-gaming.org/46e6f58145515

This is done in my engine, but it should be easy to directly convert to GL 1.1

 4 
 on: 2017-02-27 18:43:02 
Started by Stefantjeeh - Last post by Stefantjeeh
I am making a simple game with lwjgl and slick-util but i'm still a big noob. Im having some trouble trying to rorate a simple 2d quad. These are my attempts:

First attempt:

      GL11.glRotatef(180, 0.0f, 0.0f, 1.0f);
      GL11.glBegin(GL11.GL_QUADS);
      GL11.glTexCoord2f(0, 0);
      GL11.glVertex2f(p.getPosition().x, p.getPosition().y);
      GL11.glTexCoord2f(1, 0);
      GL11.glVertex2f(p.getPosition().x + playerTexture.getTextureWidth(), p.getPosition().y);
      GL11.glTexCoord2f(1, 1);
      GL11.glVertex2f(p.getPosition().x + playerTexture.getTextureWidth(),
            p.getPosition().y + playerTexture.getTextureHeight());
      GL11.glTexCoord2f(0, 1);
      GL11.glVertex2f(p.getPosition().x, p.getPosition().y + playerTexture.getTextureHeight());
      GL11.glEnd();

Second attempt:

      GL11.glTranslatef(1.0f,0.0f, 0.0f);
      GL11.glRotatef(180, 0.0f, 0.0f, 1.0f);
      GL11.glBegin(GL11.GL_QUADS);
      GL11.glTexCoord2f(0, 0);
      GL11.glVertex2f(p.getPosition().x, p.getPosition().y);
      GL11.glTexCoord2f(1, 0);
      GL11.glVertex2f(p.getPosition().x + playerTexture.getTextureWidth(), p.getPosition().y);
      GL11.glTexCoord2f(1, 1);
      GL11.glVertex2f(p.getPosition().x + playerTexture.getTextureWidth(),
            p.getPosition().y + playerTexture.getTextureHeight());
      GL11.glTexCoord2f(0, 1);
      GL11.glVertex2f(p.getPosition().x, p.getPosition().y + playerTexture.getTextureHeight());
      GL11.glEnd();

But they both gave the same flashing image. My goal is to get the mouse to move the 2d image around.
I hope someone can help

 5 
 on: 2017-02-27 16:09:15 
Started by BurntPizza - Last post by TritonDreyja
Got a good start on the cover for my next concept album of instrumentals.

It'll be about how INFP's have a hard time leaving behind the ideal world they have imagined in their mind over the years; yet everyone says we should do so to come back to reality.

The tone of the music will be dreamy and may have some tracks with vocals, but the overall idea is me expressing my inner "f*** it I'll stay in my head if I want to, and I can still be successful".

It's not something that rules my life, but it is however something I can never express properly.



"If you can't escape the reality you've created for yourself, embrace it"

 6 
 on: 2017-02-27 15:25:16 
Started by Chennorris - Last post by elect
I think it's not really clear in my head (I think I lack some experience in this domain) but can you confirm me the difference between texture binding and texture name generation

Then you should invest some time into understanding how opengl (texture) works first.
You can start from here, at the chapter "Texture Binding" at the middle of the page.
From the very same guy, another gold mine is this one.

To sum up, in the init, you should do something like this:
1  
2  
3  
4  
5  
6  
textureName = GLBuffers.newDirectIntBuffers(1)
glGenTextures(1, textureName)
glBindTexture(GL_TEXTURE_2D, textureName.get(0))
glTexImage2D
glTexParameteri
...



and then in the rendering something like this
1  
2  
3  
4  
glActiveTexture(GL_TEXTURE0 + Sampler.DIFFUSE)
glBindTexture(GL_TEXTURE_2D, textureName.get(0))
render
...


To be precise, glGenTextures() only reserve names, the corresponding memory space will be only allocated later, for example at glTexImage2D()

Before calling this part of code, here's the code that permits me to select the right shader :
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  
public static void useShader(GL3 gl, String shader) {
    if (shaders.containsKey(shader)) {
        // Getting the desired shader
        int shaderProgram = shaders.get(shader).getShaderProgram();
        gl.glUseProgram(shaderProgram);

        // Retrieving the shader vertices' attributes locations
        positionHandler = shaders.get(shader).getPositionHandler();
        normalHandler = shaders.get(shader).getNormalHandler();
        colorHandler = shaders.get(shader).getColorHandler();
        uvHandler = shaders.get(shader).getUvHandler();

        // Retrieving the texture uniform location
        defaultTextureHandler = shaders.get(shader).getTextureDefaultHandler();
        textureCubemapHandler = shaders.get(shader).getTextureCubemapHandler();

        // Setting the shader's matrices
        int projectionHandler = shaders.get(shader).getProjectionHandler();
        int viewHandler = shaders.get(shader).getViewHandler();
        if (projectionHandler != -1 && viewHandler != -1) {
            gl.glUniformMatrix4fv(projectionHandler, 1, false, CameraManager.getProjectionMatrix(), 0);
            gl.glUniformMatrix4fv(viewHandler, 1, false, CameraManager.getViewMatrix(), 0);
        }
    }
    else {
        gl.glUseProgram(0);
    }
}

Why are you retreving all those attributes if you are not gonna use them?

Moreover, you are calling attributes location and texture names both as handler, don't do that, this may give you more trouble understanding what is what and introduce subtle bugs..

where shaders is a map like following :
1  
private static Map<String, Shader> shaders;

How many shaders are you using?

My Shader class contains my handlers (positionHandler, colorHandler, …) and initializes them with the following method :
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
public boolean getLocations(GL3 gl) {
    // Detecting the attributes' locations
    positionHandler = gl.glGetAttribLocation(shaderProgram, "position");
    normalHandler = gl.glGetAttribLocation(shaderProgram, "normal");
    colorHandler = gl.glGetAttribLocation(shaderProgram, "color");
    uvHandler = gl.glGetAttribLocation(shaderProgram, "uvCoordinates");

    // Detecting the uniforms' locations
    projectionHandler = gl.glGetUniformLocation(shaderProgram, "projection");
    viewHandler = gl.glGetUniformLocation(shaderProgram, "view");

    // Detecting the textures' locations
    textureDefaultHandler = gl.glGetUniformLocation(shaderProgram, "defaultTexture");
    textureCubemapHandler = gl.glGetUniformLocation(shaderProgram, "textureCubemap");

    return true;
}


Discaimer: I am a freak of minimalist code  Tongue

I'd move this under the shader constructor, remove the attribute locations part and use an unique structure shader-independent to manage them.

This means modifying your vertex shaders as follows
1  
2  
3  
4  
#include semantic.glsl

layout(location = POSITION) in vec3 position;
layout(location = TEXT_COORD) in vec2 texCoord;


and then, along with your shaders, you'd have a semantic.glsl

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
// Vertex attributes
#define POSITION    0
#define NORMAL      1
#define TEXT_COORD  2
#define COLOR       3

// Uniform

// Interfaces

// Fragment outputs


Then you will have a corresponding Semantic.java file on the client (java) side

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
interface Semantic {
   
    Attr {

        int POSITION = 0;
        int NORMAL = 1;
        int TEXT_COORD = 2;
        int COLOR = 3;
    }
    ...
}


In this way you bring down a lot of boilerplate code, no more retrieving/binding vertex attributes.


Just had a look at the file details between the working textures and the negativeY and I discovered that my negativeY texture was 24 color-depthed while other ones are 32 color-depthed (sorry for my english in case « color-depthed » doesn't exist ^^). In Gimp, I added an alpha channel and saved again my texture and now, everything works fine (every buffer now has the same size and the skybox is properly displayed).

Technically this would't be a problem as far as you load the other faces as rgb, in glTexImage2D() you need to tell OpenGL which formats it has to expect reading the buffer (format and type) you provide and how you want it to save it inside (internalFormat). Read those link I gave you, they are really excellent  Wink

I also tried to replace my int arrays by IntBuffers but glBindTexture works with an int for the second parameter… Does that mean that I have to flip my IntBuffer everytime I need to call glBindTexture?

1  
glBindTexture(GL_TEXTURE_2D, textureName.get(0))


no need to deal with flip. Jogl doesn't touch the position of the buffer you provide, but it relies on that.

if you have a IntBuffer with 2 texture names (integers) and you do

1  
2  
textureName.position(1)
glDeleteTextures(1, textureName)


this means the second texture will be deleted. And textureName position will still be 1 after that.

This also means that
1  
2  
textureName.position(1)
glDeleteTextures(2, textureName)


will produce unhappy results..  Cheesy

 7 
 on: 2017-02-27 15:06:43 
Started by Chennorris - Last post by Chennorris
I just found something very very interesting…

As the handler for my cubemap was correct (≠ -1), I suggested to myself that the problem may come from the data I was buffering and decided to log into the console the buffers and here is what I discovered :
1  
2  
3  
4  
5  
6  
PositiveX data = java.nio.DirectByteBuffer[pos=0 lim=4194304 cap=4194304]
NegativeX data = java.nio.DirectByteBuffer[pos=0 lim=4194304 cap=4194304]
PositiveY data = java.nio.DirectByteBuffer[pos=0 lim=4194304 cap=4194304]
NegativeY data = java.nio.DirectByteBuffer[pos=0 lim=3145728 cap=3145728]
PositiveZ data = java.nio.DirectByteBuffer[pos=0 lim=4194304 cap=4194304]
NegativeZ data = java.nio.DirectByteBuffer[pos=0 lim=4194304 cap=4194304]


The negative Y texture size is different from the other textures. I just had a look at my texture and discovered that the negative Y was not in 1024×1024 but in 1024×873. My mistake Cranky
I changed the size of my texture with Gimp to set it to 1024×1024 but the file size still seems wrong (cubemap still black). But by copying another texture (negativeX) and renaming it to negativeY, the cubemap is properly displayed Cool

So I have now to understand why my negativeY texture doesn't work (maybe I can find some compression options inside Gimp, I'll see). Anyway, I'll the post the solution when I find it.

________________________
EDIT :

Just had a look at the file details between the working textures and the negativeY and I discovered that my negativeY texture was 24 color-depthed while other ones are 32 color-depthed (sorry for my english in case « color-depthed » doesn't exist ^^). In Gimp, I added an alpha channel and saved again my texture and now, everything works fine (every buffer now has the same size and the skybox is properly displayed).

END OF EDIT :
________________________

I also tried to replace my int arrays by IntBuffers but glBindTexture works with an int for the second parameter… Does that mean that I have to flip my IntBuffer everytime I need to call glBindTexture ?

 8 
 on: 2017-02-27 13:08:56 
Started by Chennorris - Last post by Chennorris
Hi elect,

Thanks for this first response, it starts to help me a lot.

Understood for the change in my fragment shader (my mistake : I suppose the alpha component was still forced to 1 after debugging tries, I think I just forgot to put it back like you said).

Quote
Texture binding and texture name generation poorly match.
I think it's not really clear in my head (I think I lack some experience in this domain) but can you confirm me the difference between texture binding and texture name generation :
  • Texture binding (made with gl.glBindTexture) permits to snap an integer on a type of texture (GL_TEXTURE_CUBE_MAP for example),
  • Texture name generation is the generation of an integer (the part where I should use IntBuffers instead of int array).
Is that right ? In that case, maybe I should rename isBinded into isNamed in my code…


Before calling this part of code, here's the code that permits me to select the right shader :
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  
public static void useShader(GL3 gl, String shader) {
    if (shaders.containsKey(shader)) {
        // Getting the desired shader
        int shaderProgram = shaders.get(shader).getShaderProgram();
        gl.glUseProgram(shaderProgram);

        // Retrieving the shader vertices' attributes locations
        positionHandler = shaders.get(shader).getPositionHandler();
        normalHandler = shaders.get(shader).getNormalHandler();
        colorHandler = shaders.get(shader).getColorHandler();
        uvHandler = shaders.get(shader).getUvHandler();

        // Retrieving the texture uniform location
        defaultTextureHandler = shaders.get(shader).getTextureDefaultHandler();
        textureCubemapHandler = shaders.get(shader).getTextureCubemapHandler();

        // Setting the shader's matrices
        int projectionHandler = shaders.get(shader).getProjectionHandler();
        int viewHandler = shaders.get(shader).getViewHandler();
        if (projectionHandler != -1 && viewHandler != -1) {
            gl.glUniformMatrix4fv(projectionHandler, 1, false, CameraManager.getProjectionMatrix(), 0);
            gl.glUniformMatrix4fv(viewHandler, 1, false, CameraManager.getViewMatrix(), 0);
        }
    }
    else {
        gl.glUseProgram(0);
    }
}

where shaders is a map like following :
1  
private static Map<String, Shader> shaders;


My Shader class contains my handlers (positionHandler, colorHandler, …) and initializes them with the following method :
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
public boolean getLocations(GL3 gl) {
    // Detecting the attributes' locations
    positionHandler = gl.glGetAttribLocation(shaderProgram, "position");
    normalHandler = gl.glGetAttribLocation(shaderProgram, "normal");
    colorHandler = gl.glGetAttribLocation(shaderProgram, "color");
    uvHandler = gl.glGetAttribLocation(shaderProgram, "uvCoordinates");

    // Detecting the uniforms' locations
    projectionHandler = gl.glGetUniformLocation(shaderProgram, "projection");
    viewHandler = gl.glGetUniformLocation(shaderProgram, "view");

    // Detecting the textures' locations
    textureDefaultHandler = gl.glGetUniformLocation(shaderProgram, "defaultTexture");
    textureCubemapHandler = gl.glGetUniformLocation(shaderProgram, "textureCubemap");

    return true;
}

 9 
 on: 2017-02-27 10:47:14 
Started by vastmind - Last post by vastmind
I've found another solution:

Just created another yet card class:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
package com.mygdx.game;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.Texture;


public class CardTwo {

    public void DrawCardTwo(SpriteBatch sprBatch, Texture myTexture){

        sprBatch.draw(myTexture, 300, 300);

    }

}

Main:
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  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
package com.mygdx.game;

import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;



public class Main extends ApplicationAdapter {

   SpriteBatch myBatch;
   ShapeRenderer sr;
   int tileSize = 32;
   Card card1;
   Texture tex, tex2;
   CardTwo card2;





   @Override
   public void create () {


      myBatch = new SpriteBatch();
      sr = new ShapeRenderer();
      tex = new Texture(Gdx.files.internal("ball.png"));
      tex2 = new Texture(Gdx.files.internal("badlogic.jpg"));
      card1 = new Card(tex);
      card2 = new CardTwo();



      }

   public void grid(){

      int height = Gdx.app.getGraphics().getHeight();
      int width = Gdx.app.getGraphics().getWidth();

      for (int i = 0; i <= width; i = i + tileSize) {

         sr.rectLine(i, height, i, 0,2, Color.BLACK, Color.BLACK);
      }

      for (int j = 0; j <= width; j = j + tileSize){

         sr.rectLine(width, j, 0, j,2, Color.BLACK, Color.BLACK);
      }

   }

   @Override
   public void render () {

      Gdx.gl.glClearColor(20/255f, 40/255f, 100/255f, 1);
      Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

      myBatch.begin();
      sr.begin(ShapeRenderer.ShapeType.Filled);
      grid();
      sr.end();
      myBatch.end();


      myBatch.begin();
      card1.draw(myBatch);
      card1.setPosition(100,100);
      myBatch.end();


      myBatch.begin();
      card2.DrawCardTwo(myBatch, tex2);
      myBatch.end();

   }



   @Override
   public void dispose () {

      sr.dispose();

   }
}

I'm excited). Thanks for help.

 10 
 on: 2017-02-27 09:10:09 
Started by FrozenShade - Last post by FrozenShade


We are on Steam Greenlight, if you are willing to help us, please vote here: http://steamcommunity.com/sharedfiles/filedetails/?id=870575498

Pages: [1] 2 3 ... 10
 
Archive (84 views)
2017-02-27 19:41:49

Riven (77 views)
2017-02-27 17:26:59

numerical (445 views)
2017-02-21 07:32:16

numerical (449 views)
2017-02-21 07:31:46

theagentd (559 views)
2017-02-18 13:42:33

theagentd (555 views)
2017-02-18 13:35:16

h.pernpeintner (1730 views)
2017-01-24 22:39:11

h.pernpeintner (1686 views)
2017-01-24 22:38:32

Galdo (2268 views)
2017-01-12 13:44:09

Archive (2183 views)
2017-01-02 05:31:41
List of Learning Resources
by elect
2016-09-09 09:47:55

List of Learning Resources
by elect
2016-09-08 09:47:20

List of Learning Resources
by elect
2016-09-08 09:46:51

List of Learning Resources
by elect
2016-09-08 09:46:27

List of Learning Resources
by elect
2016-09-08 09:45:41

List of Learning Resources
by elect
2016-09-08 08:39:20

List of Learning Resources
by elect
2016-09-08 08:38:19

Rendering resources
by Roquen
2016-08-08 05:55:21
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!