Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (475)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (530)
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  
  Texture not rendering  (Read 3422 times)
0 Members and 1 Guest are viewing this topic.
Offline StonePickaxes

JGO Coder


Medals: 4
Projects: 2


Nathan Kramber


« Posted 2012-07-03 00:10:50 »

EDIT:

Ok, so I fixed my texture not showing (really stupid mistake that even I could find) but there's one more issue. Here's my code for drawing my custom cursor

1  
2  
3  
4  
5  
6  
7  
8  
9  
      glPushMatrix();
         glTranslatef(x, y, 0);
         glColor3f(1.0f, 1.0f, 1.0f);
         glBegin(GL_TRIANGLES);
            glVertex2f(0, 0);
            glVertex2f(14, 16);
            glVertex2f(2, 18);
         glEnd();
      glPopMatrix();


but no matter what color I set, it's always black. Any idea why that might be?

EDIT AGAIN: Apparently when I call glDisable(GL_TEXTURE_2D) before I draw the cursor, it shows up in color. Do I really have to keep calling glEnable and glDisable for GL_TEXTURE_2D to draw my cursor, or is there a better way?

| Nathan

Check out my website!
Offline theagentd
« Reply #1 - Posted 2012-07-03 00:48:25 »

Supply texture coordinates?

Myomyomyo.
Offline StonePickaxes

JGO Coder


Medals: 4
Projects: 2


Nathan Kramber


« Reply #2 - Posted 2012-07-03 01:04:51 »

Supply texture coordinates?

I think you are posting this in response to my original post.

My current problem is stated above.

 | Nathan

Check out my website!
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline teletubo
« League of Dukes »

JGO Ninja


Medals: 48
Projects: 4
Exp: 8 years



« Reply #3 - Posted 2012-07-03 02:34:43 »

Supply texture coordinates?

I think you are posting this in response to my original post.

My current problem is stated above.

 | Nathan

This wouldn't happen if you didn't keep editing your original post.

If you have solved your problem and have another one, either open a new thread or post a new message on this one, this will make things far more organized and other people's messages  (like theagentd) will actually make sense.

Don't you think it's a bit selfish of yours to just delete/edit the old question and not share the solution with other people?
We are here to share knowledge, we're not a helpdesk.  

Offline StonePickaxes

JGO Coder


Medals: 4
Projects: 2


Nathan Kramber


« Reply #4 - Posted 2012-07-03 02:39:53 »

Supply texture coordinates?

I think you are posting this in response to my original post.

My current problem is stated above.

 | Nathan

This wouldn't happen if you didn't keep editing your original post.

If you have solved your problem and have another one, either open a new thread or post a new message on this one, this will make things far more organized and other people's messages  (like theagentd) will actually make sense.

Don't you think it's a bit selfish of yours to just delete/edit the old question and not share the solution with other people?
We are here to share knowledge, we're not a helpdesk.  

I'm sorry.

My original question was a very stupid mistake that I fixed almost immediately. I didn't think that it needed to stay, since odds are no one will make that mistake.

 | Nathan

Check out my website!
Offline ra4king

JGO Kernel


Medals: 336
Projects: 2
Exp: 5 years


I'm the King!


« Reply #5 - Posted 2012-07-03 03:38:34 »

In reply to your new question, yes you do need to disable GL_TEXTURE_2D after you're done.

Offline davedes
« Reply #6 - Posted 2012-07-03 04:45:47 »

In reply to your new question, yes you do need to disable GL_TEXTURE_2D after you're done.
To expand on this, you only need to disable/enable texturing when you want to change the state. i.e. If you are drawing a textured triangle, and then you want to draw a non-textured triangle, you will need to enable/disable texturing. A better solution would be to supply your desired "non-textured" triangle with a white pixel (i.e. a 1x1 section of your sprite sheet) which you them modulate with glColor4f. That way you don't need to disable texturing, nor do you need to bind a new texture. In fact, you can include the cursor and the rest of your sprites within the same glBegin/glEnd (or vertex array / VBO).

Offline theagentd
« Reply #7 - Posted 2012-07-03 14:18:32 »

If you call glColorXX(), all following glVertexXX() calls will get that color. If you call glTexCoordXX(), all following glVertexXX() calls will get that texture coordinate. If a texture is bound and GL_TEXTURE_2D is enabled it will sample the same texture coordinates for the whole triangle unless texture coordinates are given per vertex. Most likely your texture just happens to be black at that point.

You can disable texturing by either calling glDisable(GL_TEXTURE_2D); or glBindTexture(GL_TEXTURE_2D, 0);

Myomyomyo.
Online matheus23

JGO Kernel


Medals: 106
Projects: 3


You think about my Avatar right now!


« Reply #8 - Posted 2012-07-03 14:42:36 »

If you call glColorXX(), all following glVertexXX() calls will get that color. If you call glTexCoordXX(), all following glVertexXX() calls will get that texture coordinate. If a texture is bound and GL_TEXTURE_2D is enabled it will sample the same texture coordinates for the whole triangle unless texture coordinates are given per vertex. Most likely your texture just happens to be black at that point.

You can disable texturing by either calling glDisable(GL_TEXTURE_2D); or glBindTexture(GL_TEXTURE_2D, 0);
where glBindTexture(GL_TEXTURE_2D, 0); is much faster, right?

See my:
    My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Offline theagentd
« Reply #9 - Posted 2012-07-03 15:11:40 »

If you call glColorXX(), all following glVertexXX() calls will get that color. If you call glTexCoordXX(), all following glVertexXX() calls will get that texture coordinate. If a texture is bound and GL_TEXTURE_2D is enabled it will sample the same texture coordinates for the whole triangle unless texture coordinates are given per vertex. Most likely your texture just happens to be black at that point.

You can disable texturing by either calling glDisable(GL_TEXTURE_2D); or glBindTexture(GL_TEXTURE_2D, 0);
where glBindTexture(GL_TEXTURE_2D, 0); is much faster, right?
I don't know, it probably depends on the drivers.

EDIT: Or use shaders, you can just ignore the texture in that case.

Myomyomyo.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Online matheus23

JGO Kernel


Medals: 106
Projects: 3


You think about my Avatar right now!


« Reply #10 - Posted 2012-07-03 16:05:49 »

EDIT: Or use shaders, you can just ignore the texture in that case.
How to do that?

See my:
    My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Offline davedes
« Reply #11 - Posted 2012-07-03 16:31:25 »

Using shaders is completely different from immediate mode. If you plan to use shaders (which you should) then you'll probably want to learn from the very beginning (e.g. using the arcsynthesis tutorials).

Also, regarding the following:
1  
glBindTexture(GL_TEXTURE_2D, 0);


The above doesn't disable texturing, it only binds the default texture. There doesn't seem to be anything in the spec that guarantees the default texture to be white or opaque. I'd say it would be better to disable textures via glDisable(GL_TEXTURE_2D) rather than binding the default texture.

Another solution is to keep textures enabled and specify (with texcoords) a 1x1 white pixel from your sprite sheet. This allows you to push your seemingly "non-textured" sprites in the same "batch" (VBO/vertex array/glBegin) and doesn't require binding a new texture or changing the texture state.

Online matheus23

JGO Kernel


Medals: 106
Projects: 3


You think about my Avatar right now!


« Reply #12 - Posted 2012-07-03 16:33:28 »

Using shaders is completely different from immediate mode. If you plan to use shaders (which you should) then you'll probably want to learn from the very beginning (e.g. using the arcsynthesis tutorials).

Also, regarding the following:
1  
glBindTexture(GL_TEXTURE_2D, 0);


The above doesn't disable texturing, it only binds the default texture. There doesn't seem to be anything in the spec that guarantees the default texture to be white or opaque. I'd say it would be better to disable textures via glDisable(GL_TEXTURE_2D) rather than binding the default texture.

Another solution is to keep textures enabled and specify (with texcoords) a 1x1 white pixel from your sprite sheet. This allows you to push your "non-textured" sprites in the same "batch" (VBO/vertex array/glBegin) and doesn't require binding a new texture or changing the texture state.
The thing is, I tried it out. Using glBindTexture(..., 0) instead of glDisable(GL_TEXTURE_2D); is MUCH faster.
I just didn't got, how to render textures completly without glBindTexture? Or do you mean the glActiveTexture stuff with that?

See my:
    My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Offline davedes
« Reply #13 - Posted 2012-07-03 16:49:03 »

"MUCH FASTER" is a relative term. Cheesy It's sampling texture data per vertex, which it might not need to if texturing is disabled; therefore maybe it would be "MUCH FASTER" in a different benchmark. Also, it may lead you to issues depending on how the driver implements the default texture. It usually works, and lots of people do it, but that doesn't mean it's necessarily the safest/best practice. Smiley

If you want efficiency, use a 1x1 white pixel like I suggested. This has nothing to do with glActiveTexture; it's just a matter of specifying a 1x1 opaque white pixel in your texture atlas using glTexCoord2f. That way you can push all of your sprites into the same VBO regardless of whether you want them textured or "not textured" (i.e. solid color).

Online matheus23

JGO Kernel


Medals: 106
Projects: 3


You think about my Avatar right now!


« Reply #14 - Posted 2012-07-03 17:13:32 »

"MUCH FASTER" is a relative term. Cheesy It's sampling texture data per vertex, which it might not need to if texturing is disabled; therefore maybe it would be "MUCH FASTER" in a different benchmark. Also, it may lead you to issues depending on how the driver implements the default texture. It usually works, and lots of people do it, but that doesn't mean it's necessarily the safest/best practice. Smiley

If you want efficiency, use a 1x1 white pixel like I suggested. This has nothing to do with glActiveTexture; it's just a matter of specifying a 1x1 opaque white pixel in your texture atlas using glTexCoord2f. That way you can push all of your sprites into the same VBO regardless of whether you want them textured or "not textured" (i.e. solid color).
1. Actually you can't even say that performance went from ~100 frames to ~300+, because I didn't specify my hardware: GTX 550Ti, etc... even then, I would have to specify what I was rendering excactly: I used GL_NEAREST filtering, rendering ~ 1000 sprites, where there are ~20 different sprite images, packed into 2 sprite sheets. Then I would need to specify what programs were running, and even then I didn't specify what other things the game was doing (updating positions, calculating collisions, physics, lighting etc.).

So I just said "MUCH faster". Cheesy
Or lets say, it was about twice as fast?

2. yup I understood.
I was only kind of confused about what theagentd said:
EDIT: Or use shaders, you can just ignore the texture in that case.
what does he mean by "ignore the texture"?
Does he mean, there won't be any texture-binding? I have only seen that in NV_bindless_texture.
Does he mean, you were able to just don't make gl_FragColor (or whatever you use in OGL3+) be dependent on the texture ("texture2D(...);")?

This should clear it up Smiley

See my:
    My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Offline davedes
« Reply #15 - Posted 2012-07-03 18:22:33 »

Quote
what does he mean by "ignore the texture"?
If you are using shaders, you control which attributes (color, texture, vertex normals, etc) to pass to the shader. The shader decides how to color the fragment, so it doesn't need to sample from any textures. There is no concept of "enabling" or "disabling" texturing.

For example, here is a fragment shader that "ignores the texture coordinates" and instead simply returns the color attribute.
1  
2  
3  
4  
5  
6  
7  
8  
#version 120

varying vec4 Color;
varying vec2 TexCoord;

void main(void) {
   gl_FragColor = Color;
}


Newer GLSL versions would define the attributes like so, and use a custom gl_FragOut.
1  
2  
layout(location=1) in vec4 Color;
layout(location=2) in vec4 TexCoord;

Offline sproingie

JGO Kernel


Medals: 201



« Reply #16 - Posted 2012-07-03 18:25:04 »

Binding texture 0 does indeed bind the default texture, and I can't find anything in the 1.0 spec that says what the texture unit is initialized to.  The texture object extension just implies that the default texture is initialized by the driver, but doesn't say anything about what it's initialized to.  I suspect it's just a courtesy that if you didn't supply the texture unit any data, that it acts as if texturing wasn't enabled, but that a segfault would also be equally valid behavior.  

I can't imagine they'd change the behavior now (TONS of things rely on binding texture 0) but did they ever clarify initialization in later revisions of the spec?
Offline davedes
« Reply #17 - Posted 2012-07-03 20:41:22 »

I couldn't find anything in the spec, but posts like this suggests drivers may implement it differently.

In theory the default texture (id = 0) should act like any other texture -- e.g. you could manipulate it with glTexImage2D. The only difference is that it can't be deleted.
Quote
In addition to the default textures TEXTURE_1D, TEXTURE_2D, and TEXTURE_3D_EXT, it is possible to create named 1, 2, and 3-dimensional texture objects. The name space for texture objects is the unsigned integers, with zero reserved by the GL.
http://www.opengl.org/registry/specs/EXT/texture_object.txt

For the curious: "named" textures were introduced with glGenTextures() and glBindTexture() in 1.1. Before that, as I understand it, you would only have a single texture unit (aka the "default texture") to play with. The "default texture" was left in tact for backwards compatibility with OpenGL 1.0.

However, since users almost never rely on the default texture these days (instead we tend to create a new texture), drivers may not implement texture 0 exactly as you'd expect. IMO the safest solution is to not touch the default texture. Smiley

Offline theagentd
« Reply #18 - Posted 2012-07-03 23:35:35 »

Quote
what does he mean by "ignore the texture"?
If you are using shaders, you control which attributes (color, texture, vertex normals, etc) to pass to the shader. The shader decides how to color the fragment, so it doesn't need to sample from any textures. There is no concept of "enabling" or "disabling" texturing.

For example, here is a fragment shader that "ignores the texture coordinates" and instead simply returns the color attribute.
1  
2  
3  
4  
5  
6  
7  
8  
#version 120

varying vec4 Color;
varying vec2 TexCoord;

void main(void) {
   gl_FragColor = Color;
}

In this case, the varying TexCoord will be optimized away, so there's not need to have it in the first place. It won't even be found if you query the varying location for it.

Concering the default texture:
It's kind of irrelevant for OGL3 since you can just choose not to sample the texture in the shader, but it's still possible to sample the default texture. In my experience, this has always returned (1, 1, 1, 1) = white meaning it's a no-op. I've always just enabled GL_TEXTURE_2D at initialization and bound the default texture when I needed untextured surfaces. In a real game though you very rarely need untextured surfaces.

EDIT: Assuming the spec is consistent (lol): When using Framebuffer Objects (FBOs), the default FBO 0 refers to the screen framebuffer and is obviously perfectly valid.

Myomyomyo.
Online matheus23

JGO Kernel


Medals: 106
Projects: 3


You think about my Avatar right now!


« Reply #19 - Posted 2012-07-06 14:35:05 »

Quote
what does he mean by "ignore the texture"?
If you are using shaders, you control which attributes (color, texture, vertex normals, etc) to pass to the shader. The shader decides how to color the fragment, so it doesn't need to sample from any textures. There is no concept of "enabling" or "disabling" texturing.

For example, here is a fragment shader that "ignores the texture coordinates" and instead simply returns the color attribute.
1  
2  
3  
4  
5  
6  
7  
8  
#version 120

varying vec4 Color;
varying vec2 TexCoord;

void main(void) {
   gl_FragColor = Color;
}


Newer GLSL versions would define the attributes like so, and use a custom gl_FragOut.
1  
2  
layout(location=1) in vec4 Color;
layout(location=2) in vec4 TexCoord;


yes. Just what I wanted to say with:
Does he mean, you were able to just don't make gl_FragColor (or whatever you use in OGL3+) be dependent on the texture ("texture2D(...);")?

See my:
    My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
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.

ctomni231 (32 views)
2014-07-18 06:55:21

Zero Volt (28 views)
2014-07-17 23:47:54

danieldean (24 views)
2014-07-17 23:41:23

MustardPeter (25 views)
2014-07-16 23:30:00

Cero (40 views)
2014-07-16 00:42:17

Riven (42 views)
2014-07-14 18:02:53

OpenGLShaders (29 views)
2014-07-14 16:23:47

Riven (29 views)
2014-07-14 11:51:35

quew8 (26 views)
2014-07-13 13:57:52

SHC (63 views)
2014-07-12 17:50:04
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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!