English 中文(简体)
试图利用C++在开放式GL中应用沙德阵列的问题
原标题:Problems trying to apply shader to vertex array in OpenGL using C++

我有4个侧面vert(X,Y,A,B),我想把6个单独的2D块地(XxY,XxA,XxB, YxA,......)

My vertices are defined as follows:

GLint data[MAX_N_POINT][4];

I can draw the first (X,Y) of the 2D plots just fine with:

glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(4, GL_INT, 4*sizeof(GLint), &data[0][0]);

glDrawArrays(GL_POINTS, 0, MAX_N_POINT-1);
glDisableclientState(GL_VERTEX_ARRAY);

To draw the other 2D plots (XxA, AxB, etc...) I ve decided to use a shader that swizzles the X,Y,Z,W dimensions of the vertices depending on which dimensions I want to draw.:

uniform int axes;

void main()
{

vec2 point;
if (axes == 0) {
   point = gl_Vertex.xy;
} else if (axes == 1) {
   point = gl_Vertex.xz;
} else if (axes == 2) {
   point = gl_Vertex.xw;
} else if (axes == 3) {
   point = gl_Vertex.yz;
} else if (axes == 4) {
   point = gl_Vertex.yw;
} else if (axes == 5) {
   point = gl_Vertex.zw;
}

gl_Position = gl_ModelViewProjectionMatrix * vec4(point.xy, 0.0, 1.0);

gl_FrontColor = gl_Color;
gl_BackColor = gl_Color;
}

我成功地装满、汇编、加进方案,并将方案联系起来。

现在,我没有制定分方案,不清楚如何利用该方案,从而影响到我空洞阵列的划定方式。 我先尝试如下,但似乎没有任何效果,因为它所引出的正是没有沙子的东西:

glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(4, GL_INT, 4*sizeof(GLint), &data1[0][0]);

//New shader code here
glUseProgram(shaderProg);
int plotAxes = rand()%4;
GLint axes = glGetUniformLocation(shaderProg, "axes"); 
glUniform1i(axes, plotAxes);

glDrawArrays(GL_POINTS, 0, MAX_N_POINT-1);
glDisableClientState(GL_VERTEX_ARRAY);  
glUseProgram(0);

是否有我失踪或不能正确理解的基本条件?

。 我更新了每条基督教建议中的沙分法。 我也核实,如果我在我叫 gl“冰川融化”后检查露天差错,我就没有错误的螺旋式负荷。 OpenGL Error: 无效操作错误。

www.un.org/Depts/DGACM/index_spanish.htm 这里是最后的摇篮:

uniform int axes;

void main()
{
  vec4 point; 
  if (axes == 0) {
     point = gl_Vertex; 
  } else if (axes == 1) {
     point = gl_Vertex.xzyw; 
  } else if (axes == 2) {
     point = gl_Vertex.xwzy; 
  } else if (axes == 3) {
      point = gl_Vertex.yzxw; 
  } else if (axes == 4) {
     point = gl_Vertex.ywxz; 
  } else if (axes == 5) {
     point = gl_Vertex.zwxy; 
  }

  point.z = 0.0; 
  point.w = 1.0; 

  // eliminate w point
  gl_Position = gl_ModelViewProjectionMatrix * point;

    gl_FrontColor = gl_Color;
    gl_BackColor = gl_Color;
}
最佳回答

您在允许/使用该方案(<代码>glUseProgram)之后,必须确定<条码>轴心/代码(<>条码>)的统一(<条码>glUniform1i),否则它就没有任何效果(和<条码>轴心/代码>统一其缺省值,似乎为0)。 但是,我希望你的方案也包含一个有效的碎块,使用你的<代码> passcolor各不相同,因为固定功能碎块处理器没有知道与这种不同的做法。

顺便说一句,尽管它赢得的代价是,如果所有的争斗都走同样的道路,但使用6个不同的摇篮会成为一种更好的想法。 你们仍然可以使用加工前的宏观方法来减少写作费用。

http://www.un.org。 从您的更新来看,似乎你没有使用特殊的碎片。 因此,你刚刚使用碎块的管道,同时使用vert子。 虽然这是可能的,但你仍须与两个阶段相匹配,共同努力。 您的<代码>passcolor各式各样,完全无用,因为固定运行的管道不知道与它做什么。 彩色的颜色用法

passcolor = gl_Color;

iii

gl_FrontColor = gl_Color;
gl_BackColor = gl_Color;       //just to be sure

You should also check if your shaders compile and link successfully and inspect the info log in case they don t, as I suppose your program won t link because of the above varying inconstencies. So you end up iii not using the shader (and iii a bunch of GL_INVALID_OPERATIONs) iiiout noting it.

问题回答

暂无回答




相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签