Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 2 of 2 FirstFirst 12
Results 11 to 20 of 20

Thread: Textures and glsl

  1. #11
    Intern Newbie
    Join Date
    Dec 2010
    Posts
    36

    Re: Textures and glsl

    I built a check image of 128x128. Black and white. The data which I bound is totally 128*128*3 bytes.

    The data is arranged like row major data. But I don't think it is a problem with the image, I changed already to completely white but the result was still black.

    I will check later the possibility if the shader produces the black fragments.

    I guess, maybe I made a mistake in the initialization... Do you have any ideas, what could be wrong?

  2. #12
    Intern Newbie
    Join Date
    Dec 2010
    Posts
    36

    Re: Textures and glsl

    Now I tested the LightIntensity... it was not the reason.
    I think it is a problem with configuration.

  3. #13
    Senior Member OpenGL Pro BionicBytes's Avatar
    Join Date
    Mar 2009
    Location
    UK, London
    Posts
    1,171

    Re: Textures and glsl

    yo'll have to post code showing how you obtain the uniform location and how you send the uniform values.
    eg your shader compilation and object rendering code.

  4. #14
    Intern Newbie
    Join Date
    Dec 2010
    Posts
    36

    Re: Textures and glsl

    This is image creation:
    Code :
    for (unsigned int j=0; j<imgSize; ++j) {
    	for (unsigned int i=0; i<imgSize; ++i) {
    		if ( ((i+j) % tfs) < fs) {
    			checkImage[i*3 + j*imgSize*3] = (GLubyte) 0;
    			checkImage[(i+1)*3 + j*imgSize*3] = (GLubyte) 0;
    			checkImage[(i+2)*3 + j*imgSize*3] = (GLubyte) 0;
    		} else {
    			checkImage[i*3 + j*imgSize*3] = (GLubyte) 255;
    			checkImage[(i+1)*3 + j*imgSize*3] = (GLubyte) 255;
    			checkImage[(i+2)*3 + j*imgSize*3] = (GLubyte) 255;
    		}
    	}
    }

    After that: Creation of the texture:
    Code :
    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
    glGenTextures(1, &amp;_id);
    glBindTexture(GL_TEXTURE_2D, _id);
     
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
     
    glTexImage2D(GL_TEXTURE_2D,
    	0,
    	GL_RGB,
    	128,
    	128,
    	0,
    	GL_RGB,
    	GL_UNSIGNED_BYTE,
    	checkImage);
    glBindTexture(GL_TEXTURE_2D ,0);

    Now rendering: The shader program is in use
    Code :
    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D, _id);
     
    int texunit = 0;
    GLint loc = glGetUniformLocation(program, "SampleTexture");
    glUniform1iv(loc, uniform._count, (GLint*) &amp;texunit);
     
    // render

    Here the details around the texels for the attribute...
    Code :
    glGenBuffers(1, &amp;_buffers);
    glBindBuffer(GL_ARRAY_BUFFER, _buffers);
    GLfloat *texelBuffer = new GLfloat[texels.size()];
    std::copy(texels.begin(), texels.end(), texelBuffer);
    glBufferData(GL_ARRAY_BUFFER, texels.size()*sizeof(GLfloat), texelBuffer, GL_STATIC_DRAW);
    glVertexAttribPointer((GLuint)3, 2, GL_FLOAT, GL_FALSE, 0, 0);
     
    // At rendering time
    glBindVertexArray(_vao);
    ...
    glEnableVertexAttribArray(3);
    glDrawElements(...)

    That's it! Thanks a lot for your help.

  5. #15
    Intern Newbie
    Join Date
    Dec 2010
    Posts
    36

    Re: Textures and glsl

    so any idea???

  6. #16
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,734

    Re: Textures and glsl

    Code :
    glUniform1iv(loc, uniform._count, (GLint*) &amp;texunit);

    Several things.

    1: Why are you uploading that as an array? It's not a sampler array; it's just a single sampler. Use `glUniform1i` instead.

    2: Most important of all, did you call `glUseProgram(program)` before this? If not, then this call should generate a GL error (unless some other program was bound, in which case you likely did something really bad).

    so any idea???
    You waited a whole hour to bump the thread.

  7. #17
    Intern Newbie
    Join Date
    Dec 2010
    Posts
    36

    Re: Textures and glsl

    First it doesn't matter if I load one single element to the uniform or an array of size one. Why I do it, has some decisions around my project which I am developing. Even I changed it in the case of one element using the simpler function 'glUniform1i' but the result is the same I have black geometries!
    Most important of all, did you call `glUseProgram(program)` before this? If not, then this call should generate a GL error (unless some other program was bound, in which case you likely did something really bad).
    Of course!!! If I wouldn't switch on the program then my whole scene would be black. I made a whole simple scene and T am using more than one shader program (by the way). The geometries which are affected by the texture shader are black, all others are rendered fine.

    So far, did you see something what is wrong or in wrong order? What's about the glActiveTexture? Do I need 'glEnable(GL_TEXTURE)'?

  8. #18
    Intern Newbie
    Join Date
    Dec 2010
    Posts
    36

    Re: Textures and glsl

    OK!
    I fixed the problem. It was the "InternalFormat" and Format of "glTexImage". Both use the same flags but the types are different.
    InternalFormat -> GLint
    Format -> GLenum
    My mistake was I sent nothing to internalFormat because my storage managment was a little bit confused!

    Thank you for your help!

  9. #19
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    2,882

    Re: Textures and glsl

    Quote Originally Posted by Gabba123XXL
    It was the "InternalFormat" and Format of "glTexImage". Both use the same flags but the types are different.
    No, they don't accept all the same flags (enumeration defines), but for legacy reasons there are a few enumeration defines that can be provided to both.

    Format only specifies which components you're providing (if you're even providing data) for instance, GL_RED, GL_RGB, GL_RGBA, etc.

    Whereas internal format typically specifies a precise internal format (including type and number of components and bits per component), for instance GL_R16F, GL_RGB8, GL_RGB10_A2, etc.

    What sometimes is confusing is that you can provide "generic" formats such as GL_RGB to internal format and it tells OpenGL to just pick a specific internal format that it thinks is good enough for you.

    Also regarding the types: In practice, internal format is a GLenum. However, I think the history on internal format being a GLint rather than a GLenum is that in days long ago you could provide 1, 2, 3, and 4 as internal formats and, again, that told OpenGL to just pick some format that it thinks may be good enough for you. Generally speaking, you should tell it precisely the one you want, with an specific internal format enum symbol (e.g. GL_RGB8).

  10. #20
    Intern Newbie
    Join Date
    Dec 2010
    Posts
    36

    Re: Textures and glsl

    thank you... this helped me very much!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •