Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (533)
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  
  One texture for many quads  (Read 1076 times)
0 Members and 1 Guest are viewing this topic.
Offline Mac70
« Posted 2012-11-09 17:25:42 »

Like in topic. Is this possible to bind one texture to many quads and triangles and cover them all in this way? If yes - is this efficient, or maybe there is better way of making and covering 2d models than tons of quads and triangles?

Check out my Devblog! Smiley
Offline theagentd
« Reply #1 - Posted 2012-11-09 17:38:09 »

I don't get what you mean...? You can draw the same texture as many times as you want, so of course you can put the same texture on as many triangles as you want.

Myomyomyo.
Offline Mac70
« Reply #2 - Posted 2012-11-09 17:55:42 »

I have situation like this:



Polygon on this example is made from 3 quads and 1 triangle. I want to texture them all, result should be one visible texture on all of them (like on third picture), not 4 visible textures like on second picture. Is this possible?

Also, is there better way of making polygons than "connecting" many quads and triangles?

Check out my Devblog! Smiley
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline theagentd
« Reply #3 - Posted 2012-11-09 18:09:50 »

I have situation like this:



Polygon on this example is made from 3 quads and 1 triangle. I want to texture them all, result should be one visible texture on all of them (like on third picture), not 4 visible textures like on second picture. Is this possible?

Also, is there better way of making polygons than "connecting" many quads and triangles?
1.You basically want to sample a texture based on the screen position, so just do that with texture coordinates.

2. No, OpenGL can only draw triangles. Even a quad is just two triangles as far as OpenGL is concerned. In the later versions GL_QUADS is deprecated.

Myomyomyo.
Offline pitbuller
« Reply #4 - Posted 2012-11-09 19:40:57 »

at vertex shader.
1  
2  
3  
4  
5  
6  
7  
void main()
{
        gl_Position = u_mvp * a_position;  
   v_screenCoords = gl_Position;
   v_screenCoords.xy += v_screenCoords.w;
   v_screenCoords.xy *=0.5;
}


at fragment shader:

1  
   vec4 tex = texture2DProj(u_texture, v_screenCoords);


This is by far fastest and cleanest way to do it.
For iOs devices this is superior because this do not need dependant texture read.
Offline theagentd
« Reply #5 - Posted 2012-11-09 20:20:40 »

Isn't a shader a bit too advanced if he's having problem with this kind of thing, don't you think? Just do it with glBegin()-glEnd(). Here's an example for a simple screen aligned quad:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
glBegin(GL_QUADS);
{
    glTexCoord2f(x / screenWidth, y / screenHeight);
    glVertex2f(x, y);

    glTexCoord2f((x + width) / screenWidth, y / screenHeight);
    glVertex2f(x + width, y);

    glTexCoord2f((x + width) / screenWidth, (y+height) / screenHeight);
    glVertex2f(x + width, y + height);

    glTexCoord2f(x / screenWidth, (y+height) / screenHeight);
    glVertex2f(x, y + height);
}
glEnd();


Notice how the texture coordinates are the same as the vertex coordinates but divided by the screenWidth. I assume that the texture you want to sample from is screen sized and that you're drawing "holes" where the background can be seen.

There are other more powerful ways of doing this too. You could for example use the stencil buffer to mark pixels with your geometry (no textures used yet) and then in a second pass just draw the a quad covering the whole screen with the texture but only modifying the marked pixels.

Myomyomyo.
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.

pw (24 views)
2014-07-24 01:59:36

Riven (24 views)
2014-07-23 21:16:32

Riven (18 views)
2014-07-23 21:07:15

Riven (21 views)
2014-07-23 20:56:16

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

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

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

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

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

Riven (55 views)
2014-07-14 18:02:53
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!