Java-Gaming.org Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (803)
Games in Android Showcase (237)
games submitted by our members
Games in WIP (867)
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  
  Abnormal Texturing?  (Read 2912 times)
0 Members and 1 Guest are viewing this topic.
Offline Nouht

Senior Newbie





« Posted 2015-09-05 15:21:53 »

Hi. So I'm trying out OpenGL 3.3 with Core Profile and I'm having some weird results when drawing textures to triangles.

Here's what the result looks like:

The problem: I'm not expecting that to be drawn. I have a plain pink texture (255, 0, 255, 255) that should be drawn on the triangle. There is some transparency issues too.


Here's my main render loop:

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  
protected void renderScene(Renderer renderer) {
   viewMatrix.rotateX(xRot);
   viewMatrix.rotateY(yRot);
   viewMatrix.translate(new Vector3f(pos).negate());

   basicShader.bind();

   glActiveTexture(GL_TEXTURE0);
   texture.bind();
   basicShader.setUniform("tex", 0);

   basicShader.setUniform("modelMatrix", modelMatrix);
   basicShader.setUniform("viewMatrix", viewMatrix);
   basicShader.setUniform("projectionMatrix", projectionMatrix);

   Tessellator t = Tessellator.instance;
   t.begin(GL_TRIANGLES);
   t.colour(1, 1, 0, 1);
   t.normal(0, -2, 0);

   t.texCoord(1.0f, 1.0f);
   t.vertex(1.0f, 1.0f, 0.0f);

   t.texCoord(0.0f, 1.0f);
   t.vertex(-1.0f, 1.0f, 0.0f);

   t.texCoord(1.0f, 0.0f);
   t.vertex(1.0f, -1.0f, 0.0f);

   t.texCoord(0.0f, 0.0f);
   t.vertex(-1.0f, -1.0f, 0.0f);
   t.end();

   texture.unbind();

   basicShader.unbind();
}


Note: The Tessellator class is basically a helpful vertex drawing tool where I use Vertex Array Objects to draw my vertices.

Here's my fragment shader code:

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

in vec4 vColour;
in vec2 vTexCoords;

out vec4 fragColour;

uniform sampler2D tex;

void main() {
   vec4 colour = vColour*texture(tex, vTexCoords);
    fragColour = colour;
}


Edit: Here's my Texture loading code, sorry.

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  
public Texture(int width, int height, int[] pixels) {
   this.width = width;
   this.height = height;
   this.pixels = pixels;
}

public void create(ParameterListener parameterListener) {
   ByteBuffer buffer = MemoryTracker.createByteBuffer(width * height * 4);
   for (int y = 0; y < height; y++) {
      for (int x = 0; x < width; x++) {
         int colour = pixels[x + y * width];

         byte r = (byte) ((colour >> 16) & 0xff);
         byte g = (byte) ((colour >> 8) & 0xff);
         byte b = (byte) (colour & 0xff);
         byte a = (byte) ((colour >> 24) & 0xff);
         buffer.put(r).put(g).put(b).put(a);
      }
   }

   id = glGenTextures();
   glBindTexture(GL_TEXTURE_2D, id);
   glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer);

   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST/*GL_LINEAR*/);
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

   glBindTexture(GL_TEXTURE_2D, 0);

   System.out.println("Successfully created texture!");
}


If you need anything else to help me please ask. Thanks for your time.  Smiley
Offline theagentd
« Reply #1 - Posted 2015-09-05 16:19:05 »

And the problem...? What are you expecting to get?

Myomyomyo.
Offline Nouht

Senior Newbie





« Reply #2 - Posted 2015-09-05 16:24:36 »

I'm not expecting that to be drawn. I have a plain pink texture (255, 0, 255) that should be drawn on the triangle.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline theagentd
« Reply #3 - Posted 2015-09-05 16:29:51 »

Try to
1) not use your tessellator. Just draw a GL_QUADS quad to ensure that's not the problem.
2) show us the texture loading code.

Myomyomyo.
Offline Nouht

Senior Newbie





« Reply #4 - Posted 2015-09-05 16:36:36 »

Hi, thanks for your time. I've updated the post with the texture loading code.

I'm not sure what you mean by not use the Tessellator? It's a class that has worked before in my other projects that have used textures. And I don't think you can use GL_QUADS with VBO's. I can't use Immediate Mode either because it's depreciated.
Offline theagentd
« Reply #5 - Posted 2015-09-05 18:14:25 »

You didn't flip your buffer. You're uploading garbage.

Myomyomyo.
Offline Nouht

Senior Newbie





« Reply #6 - Posted 2015-09-05 19:17:18 »

I completely forgot about that. Thank you. Sorry for wasting your time.
Offline Longarmx
« Reply #7 - Posted 2015-09-05 19:25:47 »

You did not waste anyone's time (probably), because if someone comes along and has the same problem, they can try this potential solution. Pointing

Edit: Plus, now it will be more likely for you to remember to flip you buffers!

Offline theagentd
« Reply #8 - Posted 2015-09-05 19:41:38 »

No need to apologize.

Myomyomyo.
Pages: [1]
  ignore  |  Print  
 
 

 
Riven (397 views)
2019-09-04 15:33:17

hadezbladez (5280 views)
2018-11-16 13:46:03

hadezbladez (2204 views)
2018-11-16 13:41:33

hadezbladez (5544 views)
2018-11-16 13:35:35

hadezbladez (1150 views)
2018-11-16 13:32:03

EgonOlsen (4584 views)
2018-06-10 19:43:48

EgonOlsen (5462 views)
2018-06-10 19:43:44

EgonOlsen (3119 views)
2018-06-10 19:43:20

DesertCoockie (4015 views)
2018-05-13 18:23:11

nelsongames (4708 views)
2018-04-24 18:15:36
A NON-ideal modular configuration for Eclipse with JavaFX
by philfrei
2019-12-19 19:35:12

Java Gaming Resources
by philfrei
2019-05-14 16:15:13

Deployment and Packaging
by philfrei
2019-05-08 15:15:36

Deployment and Packaging
by philfrei
2019-05-08 15:13:34

Deployment and Packaging
by philfrei
2019-02-17 20:25:53

Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04: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!