i want to create a 2X2 texture . Each pixel keeps the position of a point in 3D space. How can i access the position i kept in the texture in GPU? is the fellowing correct?
void InitTextures()
{
GLuint edge[2][2][4]=
{
1,0,0,1,
0,1,0,1,
0,0,1,1,
0,0,0,1
};glGenTextures(1,&tex1);
glBindTexture(GL_TEXTURE_2D,tex1);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
//Give it the data
glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,2,2,0,GL_RGBA,GL_UNSIGNED_BYTE,edge);
}
Draw
glBegin(GL_QUADS);
glVertex3f(1,0,0);
glVertex3f(2,0,0);
glVertex3f(3,0,0);
glVertex3f(4,0,0);
glEnd();
GPU code
uniform float4x4 WorldViewProj : state.matrix.mvp;
void main_v(float4 pos:POSITION,
out float4 opos:POSITION,
out float4 color:COLOR,
uniform sampler2D tex)
{
if(pos.x==1)
{
pos.z=0; pos.x = tex2D( tex , float2(0.0,0.0) ).r*255; pos.y = tex2D( tex , float2(0.0,0.0) ).g*255;
}
if(pos.x==2)
{
pos.z=0;
pos.x = tex2D( tex , float2(1.0,0.0) ).r255;
pos.y = tex2D( tex , float2(1.0,0.0) ).g255;
}
if(pos.x==3)
{
pos.z=0;
pos.x = tex2D( tex , float2(1.0,1.0) ).r255;
pos.y = tex2D( tex , float2(1.0,1.0) ).g255;
}
if(pos.x==4)
{
pos.z=0;
pos.x = tex2D( tex , float2(0.0,1.0) ).r255;
pos.y = tex2D( tex , float2(0.0,1.0) ).g255;
}opos=mul(WorldViewProj,pos);
color=float4(a,0,0,1);
}