Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 8 of 8

Thread: Simplest direct sample shader find nothing wrong but no effect

  1. #1
    Intern Contributor
    Join Date
    Dec 2012
    Posts
    74

    Unhappy Simplest direct sample shader find nothing wrong but no effect

    The main code is listed as the following:

    c++ code:
    Code :
    readShaderSource("directsampler", &VertexShaderSource, &FragmentShaderSource);
    success=installShaders(VertexShaderSource, FragmentShaderSource);
     
    ......
     
    GLint baseImageLoc;
     
    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
    glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D, 666);
     
    glTexImage2D(GL_TEXTURE_2D,0,GL_RGB8,128,128,0,GL_RGB,GL_UNSIGNED_BYTE,myDemonTextureImage);
     
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_NEAREST);
     
    glUseProgram(progi);
    baseImageLoc = getUniLoc(progi, "baseImage");
    glUniform1i(baseImageLoc, 0);
    glActiveTexture(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D, 666);
     
    ......
     
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glBegin(GL_TRIANGLES);
    	glTexCoord2f(0, 0);
    	glVertex2f(-0.8, 0.8);
     
    	glTexCoord2f(1, 0);
    	glVertex2f(0.8, 0.8);
     
    	glTexCoord2f(0.5, 1);
    	glVertex2f(0.0, -0.8);
    glEnd();
    glutSwapBuffers();

    vertex shader:
    Code :
     
    varying vec2 texcoord;
     
    void main()
    {
    	gl_Position = ftransform();
    	texcoord = vec2(gl_MultiTexCoord0);
    }

    fragment shader:
    Code :
     
    uniform sampler2D baseImage;
     
    varying vec2 texcoord;
     
    void main(void)
    {
    	gl_FragColor=texture2D(baseImage,texcoord);
    }

    The most error-prone part is the c++ code, because v/f shaders are both compiled and linked well.
    Any idea will be appreciated and thanks in advance!

  2. #2
    Member Regular Contributor Nowhere-01's Avatar
    Join Date
    Feb 2011
    Location
    Novosibirsk
    Posts
    251
    Quote Originally Posted by newbiecow View Post
    glBindTexture(GL_TEXTURE_2D, 666);
    what is that?

    first, you should use glGenTextures to generate texture object and use the result as glBindTexture second parameter(don't forget to use glDeleteTextures before closing the programm). second, your vertices should have negative z offset, to avoid near clipping.

    http://nehe.gamedev.net/tutorial/your_first_polygon/13002/

    http://www.nullterminator.net/gltexture.html //updated link

    and also, this question has very little\nothing to do with glsl. it's more appropriate in the beginners section, as it is about inability to google basic stuff.
    Last edited by Nowhere-01; 01-07-2013 at 08:12 AM.

  3. #3
    Intern Contributor
    Join Date
    Dec 2012
    Posts
    74
    Very well indeed! You seem to be an expert and a Russian.
    Can I trust you?
    To tell you the truth, I have paid hundreds dollars for a Russian anti virus software and used that for almost ten years!
    I just wonder when I may try to use a Russian produced operating system?
    Can you Russian be trusted?


    Best Regards,

    newbiecow

  4. #4
    Member Regular Contributor Nowhere-01's Avatar
    Join Date
    Feb 2011
    Location
    Novosibirsk
    Posts
    251
    Quote Originally Posted by newbiecow View Post
    Can you Russian be trusted?
    nope
    following your topic of complete irrelevance, here's some beatiful picture of novosibirsk:
    Click image for larger version. 

Name:	novosibirsk.jpg 
Views:	88 
Size:	19.0 KB 
ID:	952

    p.s.: topic is solved?
    p.p.s.:this russian is a spy

  5. #5
    Intern Contributor
    Join Date
    Dec 2012
    Posts
    74
    Quote Originally Posted by Nowhere-01 View Post
    nope
    following your topic of complete irrelevance, here's some beatiful picture of novosibirsk:
    Click image for larger version. 

Name:	novosibirsk.jpg 
Views:	88 
Size:	19.0 KB 
ID:	952

    p.s.: topic is solved?
    p.p.s.:this russian is a spy

    following our topic even more irrelevant.
    Have you ever played a game called "Red Alert" made by Westwood?
    Beware of dogs!


    Best regards,

    newbiecow

  6. #6
    Intern Contributor
    Join Date
    Dec 2012
    Posts
    74
    Quote Originally Posted by Nowhere-01 View Post
    p.s.: topic is solved?
    p.p.s.:this russian is a spy
    I solved my question by myself.

    p.s.
    You know in some place on earth not dog lead the blind but lead a blind dog.

    p.p.s.
    So can you make out who is the dun and the dung now?


    Best regards,

    newbiecow

  7. #7
    Member Regular Contributor Nowhere-01's Avatar
    Join Date
    Feb 2011
    Location
    Novosibirsk
    Posts
    251
    i'm pretty sure the person who doesn't read tutorials and documentation is dung.

  8. #8
    Intern Contributor
    Join Date
    Dec 2012
    Posts
    74
    Well. You seem to be irritated though I dunno why.

    A specification has announced everything properly while an implementation announced none other than the specification's.
    In this case, which doc can you refer? In most cases, you have to query every default value the implementation has set before using the default settings correctly.

    Anyway, I have solved my question. You can spare your time to help others now. Good luck, irritable man!


    Best regards,

    newbiecow
    Last edited by newbiecow; 01-24-2013 at 03:05 AM.

Posting Permissions

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