GLSL texture mapping - need some help

Hi, i started learning GLSL recently, and now i try to make a simple program with a single texture on the ground:
(
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
GLfloat m_colcoords[12]={0.0f, 0.4f, 0.0f,0.0f, 0.4f, 0.0f,0.0f, 0.4f, 0.0f,0.0f, 0.4f, 0.0f}; //now it isnt used
GLint m_primcoords[12]={0,0,0, 50,0,0, 50,50,0, 0,50,0}; //my ground coords, yep its vertical but doesn't matter
GLint m_texcoords[8]={0,0,0,1,1,1,1,0};                  //texture coords

GLuint colorBuffer;
GLuint vertexcBuffer;
GLuint textureBuffer;

void PNDRENDER::load()
{
	glGenBuffers(1,&colorBuffer);
	glGenBuffers(1,&vertexcBuffer);
	glGenBuffers(1,&textureBuffer);

	glBindBuffer(GL_ARRAY_BUFFER,vertexcBuffer);
	glBufferData(GL_ARRAY_BUFFER,sizeof(GLint)*12,m_primcoords,GL_STATIC_DRAW);

	glBindBuffer(GL_ARRAY_BUFFER,colorBuffer);
	glBufferData(GL_ARRAY_BUFFER,sizeof(GLfloat)*12,m_colcoords,GL_STATIC_DRAW);
	
	glBindBuffer(GL_ARRAY_BUFFER,textureBuffer);
	glBufferData(GL_ARRAY_BUFFER,sizeof(GLfloat)*8,m_texcoords,GL_STATIC_DRAW);
}


this is my loader for the vbos. and this is during the init method(this goes first):
1
2
3
  shaderProgram->bindAttrib(0,"a_Vertex");
  shaderProgram->bindAttrib(1,"a_Color");
  shaderProgram->bindAttrib(2,"a_TexCoord");

and finally the rendering:
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
void PNDRENDER::render()
{
	GLfloat modelviewMatrix[16];
	GLfloat projectionMatrix[16];

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glLoadIdentity();

	cameraMove();

	GLuint texturegrass = ploadtexture("grass.bmp"); //my beautiful paint drawing

	glGetFloatv(GL_MODELVIEW_MATRIX,modelviewMatrix);
	glGetFloatv(GL_PROJECTION_MATRIX,projectionMatrix);
	
	shaderProgram->sendUniform4x4("modelview_matrix",modelviewMatrix); //i used them also in my vertex shader
	shaderProgram->sendUniform4x4("projection_matrix",projectionMatrix);   //but i replaced with a simplier

	glEnableVertexAttribArray(0);
	glEnableVertexAttribArray(1);
	glEnableVertexAttribArray(2);

	glActiveTexture(GL_TEXTURE0);
	shaderProgram->sendUniform("color_texture",0);
	glBindTexture(GL_TEXTURE_2D, texturegrass);

	glBindBuffer(GL_ARRAY_BUFFER,colorBuffer);
	glVertexAttribPointer((GLint)1,3,GL_FLOAT,GL_FALSE,0,0);

	glBindBuffer(GL_ARRAY_BUFFER,textureBuffer);
	glVertexAttribPointer((GLint)2,2,GL_INT,GL_FLASE,0,0);

	glBindBuffer(GL_ARRAY_BUFFER,vertexcBuffer);
	glVertexAttribPointer((GLint)0,3,GL_INT,GL_FALSE,0,0);

	glDrawArrays(GL_QUADS,0,12);

	glDisableVertexAttribArray(0);
	glDisableVertexAttribArray(1);
	glDisableVertexAttribArray(2);
}


My problem is that it only makes the ground with a color, and i realized that the color is the color of my texture's corner pixels(like finalcolor= ctopleft*ctopright*cbotleft*cbotright).

heres my shaders:

vertex:
1
2
3
4
5
6
7
#version 330

void main() 
{            
    gl_TexCoord[0] = gl_MultiTexCoord0;
    gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
}


fragment:
1
2
3
4
5
6
7
8
#version 330

uniform sampler2D color_texture;

void main() 
{
	gl_FragColor = texture2D(color_texture, gl_TexCoord[0].st);
}


I dont know if the problem is with the shaders or with my program.(everything works fine on immediate mode)
Thanks for any help!

And for "google is your friend" answers" - i searched the sol. everywhere:P
Last edited on
i can send the texture loader class too
Your types are inconsistent, so the size argument to glBufferData will be wrong.

1
2
3
GLint m_texcoords[8]={0,0,0,1,1,1,1,0};
    // ...
glBufferData(GL_ARRAY_BUFFER,sizeof(GLfloat)*8,m_texcoords,GL_STATIC_DRAW);


[Edit: But that may not be the issue. It's possible they're the same size.]
Last edited on
Yupp!
that was the first problem, thanks a lot:D
There was another with texture coord mapping, i changed the glsquare to triangle strip, and remapped that way, i wanted to do that altough, cuz i'm making a heightmap, so 2in1:P
Topic archived. No new replies allowed.