Jump to content

  • Log In with Google      Sign In   
  • Create Account


Kaptein

Member Since 03 Feb 2008
Offline Last Active Jul 13 2014 10:27 PM
-----

Posts I've Made

In Topic: GLSL texture "tile selection" algorithm?

07 July 2014 - 10:47 AM

int tileY = int(float(tileIndex) / float(columnCount));

 

you want integer division here

you are still not % by rowsize, instead you are % by total count, which makes no sense to me

 

i also seriously doubt that the image is 255 wide

so, lets try again:

#version 330 core

layout(location=0) in vec3 in_pos;
out vec2 out_texCoord;

void main()
{
	int tileIndex = 1;

	int tileWidth  = 32;
	int tileHeight = 32;
	int imgWidth  = 256;
	int imgHeight = 352;
        
        // tiles per row (send as uniform)
	int tilesX = imgWidth / tileWidth;
	int tileX = tileIndex % tilesX;
	int tileY = tileIndex / tilesX;
        
    	// tile size (send this as vec2 uniform)
        float tx = float(tileWidth) / float(imgWidth);
	float ty = float(tileHeight) / float(imgHeight);
        // start position
        vec2 start = vec2(float(tileX), float(tileY)) * vec2(tx, ty);
        // make it so that the tiles start from the topmost row
	start.y = 1.0 - start.y - ty;
        
        int vid = gl_VertexID % 4;
	switch(vid)
	{
	case 0:
		out_texCoord = start + vec2(0.0, 0.0); // (0, 0)
		break;
	case 1:
		out_texCoord = start + vec2(tx, 0.0); // (1, 0)
		break;
	case 2:
		out_texCoord = start + vec2(tx, ty); // (1, 1)
		break;
	case 3:
		out_texCoord = start + vec2(tx, ty); // (0, 1)
		break;
	}
	gl_Position = vec4(in_pos, 1);
}

You also may want to use mod(x, y) instead of %, and you have a fixed amount of tiles in width (8) you can use bit-operations instead of % and idiv.

You can also get texture size from this: https://www.opengl.org/sdk/docs/man/html/textureSize.xhtml

But I recommend just sending the required uniforms precalculated.

 

All in all, you need a vec2 uniform: vec2(tileSizeX, tileSizeY) and the tiles per row: int tilesX

I wrote the new switch() statement like I did to prove a point. As you can see you are multiplying with the constants I put in the comments.

 

vec2 texCoords[] =

{

     vec2(0.0, 0.0),

     vec2(1.0, 0.0)

     vec2(1.0, 1.0),

     vec2(0.0, 1.0)

};

so out_TexCoords = start + tileSize * texCoords[vid];

No need for switch() statement.


In Topic: GLSL texture "tile selection" algorithm?

06 July 2014 - 11:10 PM

You have no use for how many tiles there are in total. You need the number of tiles in a row, which I will call tilesWidth:

 

int tileX = tileID % tilesWidth;

int tileY = tileID / tilesWidth;

 

out_texCoord = vec2(float(tileX) * tileWidth, float(tileY) * tileHeight);

which can be further reduced to:

out_texCoord = vec2(float(tileX), float(tileY)) * tileSize;

 

for gl_VertexID = 0:

out_texCoord += vec2(0, tileHeight);

 

You can also use a static array of texture coordinates to add based on gl_VertexID % 4. No need for branches.


In Topic: So... I'm a Molecular Biologist....

05 July 2014 - 12:41 AM

Some introductory stuff you will want to keep in mind when trying to plan this out:

http://www.sitepoint.com/12-tips-for-better-developer-communication/

http://www.smashingmagazine.com/2009/08/14/how-to-effectively-communicate-with-developers/

http://www.informit.com/articles/article.aspx?p=2044336

 

You don't necessarily need programmers to understand your domain completely. It does help a ton, but if you can communicate the specific needs properly you can pretty much have anything made. It's probably not going to be easy, but you are an educator!

 

Just be aware that if you don't intend to design the game yourself, then you will need a programmer with some heavy experience. Actually, I think it's best if you just design it as best you can, and test it yourself as the project goes on. Through the project you will have opportunities to see what things look like, and later how they work. If you can afford it, you may be able to get something that is decidedly better than what you had originally envisioned.

 

I've worked on projects with educators before, and they always had a positive presence in the development process. It made things easier because we could discuss the complex domain-specific parts of the projects face-to-face, as well as have some user-testing. In my case the project was made FOR the educator though. The educators would come by weekly to check on progress and explain differences in what we understood and what they really meant. It's all part of the process, so don't be too discouraged if you feel you aren't understood properly.

 

Anyways, good luck with your project. And keep in mind that $$$ makes things happen.


In Topic: Strange problem with functions not working properly on different unit in project

29 June 2014 - 11:39 PM

Mainunit->gl*

 

looks suspicious to me, is that a different context?

 

Also, you are allocating 2048*2048*4 uints, which is 67mb, instead of the 16.7mb you really wanted.


In Topic: Indices and vertices

26 June 2014 - 11:17 AM

Yes, I'm currently doing #3.

 

 

I finally found the problem, completely by mistake:

glDrawElements(GL_QUADS, cv->indices[i], GL_UNSIGNED_SHORT, (GLvoid*) (intptr_t) (cv->indexoffset[i]*2));

 

For some reason, the "offset" value is in bytes. I just multiplied by 2 there just to see how fast it would crash.

It boggles the mind.


PARTNERS