Java-Gaming.org Hi !
Featured games (88)
games approved by the League of Dukes
Games in Showcase (679)
Games in Android Showcase (194)
games submitted by our members
Games in WIP (733)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: 1 ... 7 8 [9] 10
 81 
 on: 2016-05-27 13:03:46 
Started by useless - Last post by Hydroque
First, make sure that your quad or whatever your drawing pops up.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
#version 400 core

in vec3 pass_position;

out vec4 out_Color;

void main(void) {
   
   out_Color = vec4(1,1,1,1);
   
}

Then make sure that it pops up with color and change the 1's to decimals to make sure that the color changes.

This confirms that you are actually drawing something.

Adding uniform sampler2D u_texture; will allow you to get a texture in there to read the texel at the point and shade it. Thusly, you can add that variable.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
#version 400 core

in vec2 pass_texcoord;

uniform sampler2D u_texture0;

out vec4 out_Color;

void main(void) {
   
   out_Color = vec4(1,1,1,1);
   
}


As you can see, I just plopped it in there. I added a 0 at the end as per when I do multitexturing (u_texture1, u_texture2, etc). So now we have to set the texture in the shader.

First, you need to bind the shader, then get the variable.
// *binds shader*
int shader = shader.getUniform("u_texture" + i); // get the texture variable
GL13.glActiveTexture(GL13.GL_TEXTURE0 + i); // from texture unit 0, translated 0 because let's say i = 0 (on texture 0)
GL11.glBindTexture(GL11.GL_TEXTURE_2D, material.getTextureData().getId()); // actually load the texture into here
shader.bindUniformi(shader, i); // upload to texture unit 0

Then you need to use it in your shader.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
#version 400 core

in vec2 pass_texcoord;

uniform sampler2D u_texture0;

out vec4 out_Color;

void main(void) {
   
   out_Color = texture(u_texture0, pass_texcoord); // and here we are
   
}


If your texture is upside down, you have a texcoord/indices/vertex problem.



 82 
 on: 2016-05-27 11:47:55 
Started by DarkCart - Last post by princec
Exactly. And yet the internet is awash with programmers who seem to be entirely happy about this situation.

I'll suppose those programmers have never spent 20 years designing something, only for some giant corporation to come along and go "yoink! I'm 'avin' that" and subsequently make forty billion dollars out of it without giving them a bean.

Cas Smiley

 83 
 on: 2016-05-27 11:25:05 
Started by DarkCart - Last post by ags1
What irks me about this case is the Google position that no hard, creative labor goes into designing the API. According to Google that is no effort at all and only the implementation involves real work.

I'm sure I'm not the only one who thinks the implementation is relatively trivial in comparison to designing, validating and evolving a good API.

On the other hand, if this went in favor of Oracle, it would be like software patents all over again, but ten times worse.

 84 
 on: 2016-05-27 11:05:06 
Started by ags1 - Last post by ags1
Over the next few years as the language becomes wildly popular I expect the major IDEs will recognize .treeml files and make an appropriate exception for tabs... Wink

 85 
 on: 2016-05-27 11:02:28 
Started by ags1 - Last post by nsigma
I like tabs because they don't require as many keypresses ... to type in the first place.

The crux of the issue is that most people who works with space indented projects (and I don't currently work with anything Java or otherwise that doesn't use spaces) has their editor set up to output spaces when the tab key is used.

I'm currently working on something with lots of YAML, and I don't disagree with the "nasty and dirty" comment, but for me using tabs is even more of a PITA because of the above issue.

 86 
 on: 2016-05-27 10:49:31 
Started by useless - Last post by useless
Hi all,

trying to learn OpenGL using lwjgl3, got stuck at texturing a triangle, nothing is displayed. Decoding png texture to a bytebuffer using Manns PNGDecoder.

The whole thing seems straight forward to me but all i get is black screen. As far as i figured out the texture should be bound automatically to the sampler, i dont need to set the uniform myself in the code.

Decoding the texture and uploading to GPU:
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  
   public static Texture getPNGTexture(String fileName)
    {
        int id;
        ByteBuffer buf = null;
        int imageWidth = 0;
        int imageHeight = 0;

        try {
            InputStream is = new FileInputStream(new File("res/textures/" + fileName + ".png"));
            PNGDecoder decoder = new PNGDecoder(is);
            imageWidth = decoder.getWidth();
            imageHeight = decoder.getHeight();
            if (imageWidth == 0 || imageHeight == 0)
            {
                throw new IOException("Image is zero sized!");
            }

            PNGDecoder.Format format = PNGDecoder.RGBA;

            try{
                buf = BufferUtils.createByteBuffer(imageHeight*imageWidth*format.getNumComponents());
                decoder.decode(buf, imageWidth*format.getNumComponents(), format);
            }catch(IOException e){
                e.printStackTrace();
            }finally {
                is.close();
            }

            buf.flip();
        } catch (IOException e) {
            e.printStackTrace();
        }

        id = glGenTextures();

        glBindTexture(GL_TEXTURE_2D, id);

        glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA, imageWidth, imageHeight);
        glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, imageWidth, imageHeight, GL_RGBA, GL_UNSIGNED_BYTE, buf);

        return new Texture(id);
    }


Getting texture and mesh data:
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  
texture = Texture.getPNGTexture("box");

        test = new Mesh();
        float[] vertices = {
                -0.5f, 0.5f, 0f,
                -0.5f, -0.5f, 0f,
                0.5f, -0.5f, 0f,
        };
        int[] indices = {
                0,1,2
        };
        float[] texCoords = {
                0,0,
                0,1,
                1,1
        };
        test.addVertices(vertices, texCoords, indices);


    public void addVertices(float[] vertices, float[] texCoords, int[] indices)
    {
        size = indices.length;

        glBindVertexArray(vao);                                                             //Bind VAO

        int vbo = glGenBuffers();                                                           //Create new VBO
        int ibo = glGenBuffers();
        int tbo = glGenBuffers();
        buffers.add(vbo);
        buffers.add(ibo);
        buffers.add(tbo);

        glBindBuffer(GL_ARRAY_BUFFER, vbo);                                                 //Bind vbo
        glBufferData(GL_ARRAY_BUFFER, Util.createFlippedBuffer(vertices), GL_STATIC_DRAW);  //Put data in it
        glVertexAttribPointer(0, 3, GL_FLOAT, false, 0, 0);                                 //Put VBO in VAO on pos 0

        glBindBuffer(GL_ARRAY_BUFFER, tbo);
        glBufferData(GL_ARRAY_BUFFER, Util.createFlippedBuffer(texCoords), GL_STATIC_DRAW);
        glVertexAttribPointer(1, 2, GL_FLOAT, false, 0, 0);

        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo);                                                 //Bind vbo
        glBufferData(GL_ELEMENT_ARRAY_BUFFER, Util.createFlippedBuffer(indices), GL_STATIC_DRAW);   //Put data in it
    }


Binding texture bit and drawing mesh:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
    public void render()
    {
        texture.bind();
        shader1.bind();
        shader1.SetUniform("transform", transform1.getProjectedTransformation());

        test.draw();
    }

    public void bind()
    {
        glActiveTexture(GL_TEXTURE0);
        glBindTexture(GL_TEXTURE_2D, id);
    }

    public void draw()
    {
        glBindVertexArray(vao);
        glEnableVertexAttribArray(0);
        glEnableVertexAttribArray(1);
        glDrawElements(GL_TRIANGLES, size, GL_UNSIGNED_INT, 0);
        glDisableVertexAttribArray(0);
        glDisableVertexAttribArray(1);
    }


Shaders:
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  
#version 430 core

layout (location=0) in vec3 position;
layout (location=1) in vec2 texCoords;

out vec2 pass_texCoords;

uniform mat4 transform;

void main()
{
    pass_texCoords = texCoords;
    gl_Position = transform * vec4(position, 1.0);
}




#version 430 core

in vec2 pass_texCoords;
layout (binding=0) uniform sampler2D sampler;

out vec4 color;

void main()
{
    color = texture(sampler, pass_texCoords);
}

 87 
 on: 2016-05-27 10:46:21 
Started by noctarius - Last post by Roquen
I love LISP.  "Absence makes the heart grow fonder."  The last time we got together we tried to kill each other.

 88 
 on: 2016-05-27 10:26:18 
Started by ags1 - Last post by ags1
Standard Java style is tabs, not spaces.

You can see now why whitespace with semantic meaning is a disaster.

Cas Smiley

A disaster ONLY if the language syntax allows a mix of tabs and spaces.

Also, to be totally correct I am using the tab character as semantically significant, not the whitespace it is represented with in the editor. There is a difference. You can configure your editor to represent the tabs with one space or eight (or even zero), but that doesn't change the meaning of the document.

I could use a different character without a whitespace representation if that would make more sense (but it wouldn't).

I opted for tabs because spaces were worse. Would I hardcode that a specific number of spaces equals an official indentation level? Or would I follow YAML and allow any change in indentation to be significant? In my opinion the YAML approach is just nasty and dirty, and hard-coding a number of spaces (or allowing each user to configure it somehow) means hard coding a visual preference into every treeml file. Tabs feel wrong, but in this case they're right.

Here's what the YAML spec has to say about indenting:

Quote
In general, a node must be indented further than its parent node. All sibling nodes must use the exact same indentation level, however the content of each sibling node may be further indented independently. The “-”, “?” and “:” characters used to denote block collection entries are perceived by people to be part of the indentation. Hence the indentation rules are slightly more flexible when dealing with these indicators. First, a block sequence need not be indented relative to its parent node, unless that node is also a block sequence. Second, compact in-line notations allow a nested collection to begin immediately following the indicator (where the indicator is counted as part of the indentation). This provides for an intuitive collection nesting syntax.

This was the inspiration for treeml, after reading that paragraph I knew I would never willingly use YAML Smiley

Also, regarding proportional fonts: I don't use proportional fonts but spaces are fine for indenting a proportional font file. The spaces are at the beginning of the line (i.e. with zero characters before them) so proportionality is not a factor.

 89 
 on: 2016-05-27 10:05:35 
Started by ags1 - Last post by princec
Since Eclipse has used tabs by default for code formatting since before it was even called Eclipse that sort of made tabs a defacto standard.

I like tabs because they don't require as many keypresses to navigate around, or indeed to type in the first place.

I make extensive use of //formatter:off/on too in my code.

Cas Smiley

 90 
 on: 2016-05-27 09:55:17 
Started by ags1 - Last post by basil_
if there is an option "replace tabs by spaces on save" - i cannot imagine why one woudln't check it and forget about tabs altogether.

Pages: 1 ... 7 8 [9] 10
 
Hydroque (20 views)
2016-05-26 14:45:46

Mac70 (41 views)
2016-05-24 21:16:33

theagentd (43 views)
2016-05-14 18:38:35

theagentd (77 views)
2016-05-10 22:37:41

theagentd (85 views)
2016-05-10 22:33:46

IanParcs (111 views)
2016-04-18 14:18:53

KaiHH (110 views)
2016-04-18 08:35:41

KaiHH (132 views)
2016-04-15 12:43:58

theagentd (136 views)
2016-04-14 02:16:17

theagentd (159 views)
2016-04-14 02:15:43
FPS Camera Tutorial
by Hydroque
2016-05-22 05:40:58

Website offering 3D Models specifically for games for free
by vusman
2016-05-18 17:23:09

Website offering 3D Models specifically for games for free
by vusman
2016-05-09 08:50:56

Website offering 3D Models specifically for games for free
by vusman
2016-05-06 11:10:21

Website offering 3D Models specifically for games for free
by vusman
2016-04-29 12:56:17

List of Learning Resources
by SilverTiger
2016-02-05 09:39:47

List of Learning Resources
by SilverTiger
2016-02-05 09:38:38

List of Learning Resources
by SilverTiger
2016-02-05 09:35:50
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!