Login | Register 
FEATURES
APPLICATIONS
DOWNLOADS
EDUCATION
BLOG
WIKI
FORUM
STORE

Attempting to make a C++ TOP a filter

General discussion about anything TouchDesigner

Attempting to make a C++ TOP a filter

Postby Ennui » Thu Aug 02, 2018 12:00 pm

So I've been taking apart the example OpenGLTOP and I just want to try and build a filter TOP from that. I'm currently getting the "uniform location could not be found" error when running the DLL and was wondering why that might be.

I'm creating an extra 2 attributes in the vertex array which are to be my UV values and adjusting the stride as necessary. With a uniform white shader I get the correct coordinates coming out so I then change that to a uniform sampler2D as my texture...so my Shaders look a bit like this:

Code: Select all
static const char *vertexShader = "#version 330\n\
in vec3 P; \
in vec2 UV;\
out vec2 TexCoord;\
uniform mat4 uModelView; \
void main() { \
    gl_Position = vec4(P, 1) * uModelView; \
}";

static const char *fragmentShader = "#version 330\n\
in vec2 TexCoord;\
out vec4 finalColor; \
uniform sampler2D uTexture; \
void main() { \
   finalColor = texture(uTexture, TexCoord); \
}";


In SetupGL I setup my attributes like so:

Code: Select all
GLint vertAttribLocation = glGetAttribLocation(myProgram.getName(), "P");
GLint texAttribLocation = glGetAttribLocation(myProgram.getName(), "UV");
myModelViewUniform = glGetUniformLocation(myProgram.getName(), "uModelView");
GLInt myTexSampler = glGetUniformLocation(myProgram.getName(), "uTexture");


I'm then setting my sampler2D in execute by getting the inputs textureindex (OP_TOPInput)
Code: Select all
glUniform1i(myTexSampler, input.textureIndex);


And in the Shape class where I bind the array I'm setting the following in setup:

Code: Select all
 glEnableVertexAttribArray(attrib);
   glEnableVertexAttribArray(uv);
    glVertexAttribPointer(attrib, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), (GLvoid *)0);
   glVertexAttribPointer(uv, 2, GL_FLOAT, GL_FALSE, 8 * sizeof(GLfloat), (GLvoid *)(3 * sizeof(GLfloat)));


Have I completely missed something here? I am not the best at this openGL malarky but the above stuff seems to work ok in my own GLFW app setup.
Richard Burns
User avatar
Ennui
 
Posts: 492
Joined: Sat Oct 03, 2009 2:23 pm

Re: Attempting to make a C++ TOP a filter

Postby malcolm » Sat Aug 04, 2018 12:19 am

So, not related to the error you are saying you see, but the uniform for a sampler needs to be set to it's texture bind point, not the texture index itself. You use glClientActiveTexture to select the current bind point, and then glBindTexture to bind the texture index to that particular bind point. I.e, glUniform1i generally is set to a value 0-32 or so, and isn't the GLuint texture ID.
User avatar
malcolm
Staff
 
Posts: 4197
Joined: Tue Nov 13, 2007 1:11 am

Re: Attempting to make a C++ TOP a filter

Postby Ennui » Sat Aug 04, 2018 7:31 am

Aha I'll have a noodle about with that then and see where I get to. Thanks Malcolm.
Richard Burns
User avatar
Ennui
 
Posts: 492
Joined: Sat Oct 03, 2009 2:23 pm

Re: Attempting to make a C++ TOP a filter

Postby malcolm » Sat Aug 04, 2018 9:35 am

Sorry it's glActiveTexture you are looking for, not glClientActiveTexture
User avatar
malcolm
Staff
 
Posts: 4197
Joined: Tue Nov 13, 2007 1:11 am

Re: Attempting to make a C++ TOP a filter

Postby barakooda » Thu Sep 06, 2018 10:21 am

my two cents,
Why your stride size is different?
(vertex byte size).

Code: Select all
glVertexAttribPointer(attrib, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), (GLvoid *)0);
  glVertexAttribPointer(uv, 2, GL_FLOAT, GL_FALSE, 8 * sizeof(GLfloat), (GLvoid *)(3 * sizeof(GLfloat)));



http://docs.gl/gl3/glVertexAttribPointer

the position and the uv not in the same array ?
User avatar
barakooda
 
Posts: 539
Joined: Fri Nov 27, 2009 5:08 pm


Return to General TouchDesigner Discussion

Who is online

Users browsing this forum: Bing [Bot] and 17 guests