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 1 of 3 123 LastLast
Results 1 to 10 of 25

Thread: GL_TEXTURE_RECTANGLE with GLuint data?

  1. #1
    Intern Newbie
    Join Date
    Dec 2010
    Posts
    49

    GL_TEXTURE_RECTANGLE with GLuint data?

    No matter what values i fill my data with, the texture is drawn black. Since it is being drawn to the screen, I use the screen coordinates as texel coordinates in the shader.
    <div class="ubbcode-block"><div class="ubbcode-header">Click to reveal.. <input type="button" class="form-button" value="Show me!" onclick="toggle_spoiler(this, 'Yikes, my eyes!', 'Show me!')" />]<div style="display: none;">
    Code :
    static const Uint32 MAX_UINT32 = 0xFFFFFFFF;
    void CreateTexture(){
    	Uint32 lsize = SCREEN_WIDTH*SCREEN_HEIGHT*4;
    	GLuint* ldata = new GLuint[lsize];
    	for( Uint32 i=0; i<lsize; ++i ){
    		if( (i+1)%4 ){
    			ldata[i]=0;  //black
    		}
    		else{
    			ldata[i]=MAX_UINT32;  //alpha
    		}
    	}
            //white pixel in center of screen
    	ldata[lsize/2+(Uint32)HALF_W] = MAX_UINT32;
    	ldata[lsize/2+(Uint32)HALF_W+1] = MAX_UINT32;
    	ldata[lsize/2+(Uint32)HALF_W+2] = MAX_UINT32;
     
    	glActiveTexture( GL_TEXTURE0 );
     
    	glGenTextures( 1, &amp;mTexId );
    	glBindTexture( GL_TEXTURE_RECTANGLE, mTexId );
    	glTexImage2D(	GL_TEXTURE_RECTANGLE, 0, GL_RGBA, 
    			SCREEN_WIDTH, SCREEN_HEIGHT, 0, 
    			GL_RGBA, GL_UNSIGNED_INT, ldata );
    	delete[] ldata;
    }
    [/QUOTE]</div>

    No white pixels show up, even if I initialize all the data to MAX_UINT32

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Mar 2009
    Location
    Singapore
    Posts
    802

    Re: GL_TEXTURE_RECTANGLE with GLuint data?

    Try this
    Code :
    Uint32 lsize = SCREEN_WIDTH*SCREEN_HEIGHT*4;
    Uint32 HALF_W = SCREEN_WIDTH>>1;
    Uint32 HALF_H = SCREEN_HEIGHT>>1;
    GLuint* ldata = new GLuint[lsize];
    for( Uint32 i=0; i<lsize; ++i ){
       if( (i+1)%4 ){
          ldata[i]=0;  //black
       }
       else{
          ldata[i]=MAX_UINT32;  //alpha
       }
    }
      //white pixel in center of screen
      ldata[(SCREEN_WIDTH*HALF_W+ HALF_H)*4] = MAX_UINT32;
      ldata[(SCREEN_WIDTH*HALF_W+ HALF_H)*4+1] = MAX_UINT32;
      ldata[(SCREEN_WIDTH*HALF_W+ HALF_H)*4+2] = MAX_UINT32; 		
      glActiveTexture( GL_TEXTURE0 );
      glGenTextures( 1, &amp;mTexId );
      glBindTexture( GL_TEXTURE_RECTANGLE, mTexId );
      glTexParameteri(GL_TEXTURE_RECTANGLE, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
      glTexImage2D(	GL_TEXTURE_RECTANGLE, 0, GL_RGBA, SCREEN_WIDTH, SCREEN_HEIGHT, 0, GL_RGBA, GL_UNSIGNED_INT, ldata );
      delete[] ldata;
    Also make sure that the texture coordinates you assign to the geometry are not normalized like this,
    Code :
    glBegin(GL_QUADS);
       glTexCoord2f(0,0);glVertex2i(0,0);
       glTexCoord2f(SCREEN_WIDTH,0);glVertex2i(SCREEN_WIDTH,0);
       glTexCoord2f(SCREEN_WIDTH,SCREEN_HEIGHT);glVertex2i(SCREEN_WIDTH,SCREEN_HEIGHT);
       glTexCoord2f(0,SCREEN_HEIGHT);glVertex2i(0,SCREEN_HEIGHT);
    glEnd();
    Regards,
    Mobeen

  3. #3
    Intern Newbie
    Join Date
    Dec 2010
    Posts
    49

    Re: GL_TEXTURE_RECTANGLE with GLuint data?

    Still can't get anything but black pixels to draw. And yes, since the texel coords and screen coords co-incide, I am just passing on the texture coordinates like so [tt]out vec2 texPos = inVertex.xy[/tt]

    Isn't MAX_UINT32 supposed to be white for a texture specified with
    GL_UNSIGNED_INT as the type? Even if I fill my data with all MAX_UINT32 values, it still draws black.

  4. #4
    Advanced Member Frequent Contributor
    Join Date
    Mar 2009
    Location
    Singapore
    Posts
    802

    Re: GL_TEXTURE_RECTANGLE with GLuint data?

    Quote Originally Posted by PrestoChung
    Isn't MAX_UINT32 supposed to be white for a texture specified with
    GL_UNSIGNED_INT as the type? Even if I fill my data with all MAX_UINT32 values, it still draws black.
    Well i get this output which is exactly what I should get.
    Could u try this minimal glut code and tell me what u get?
    Code :
    #include <gl/glew.h>
    #include <gl/glut.h> 
    typedef unsigned int Uint32;
    static const Uint32 SCREEN_WIDTH = 800;
    static const Uint32 SCREEN_HEIGHT = 600;
    static const Uint32 MAX_UINT32 = 0xFFFFFFFF;
    int HALF_W = SCREEN_WIDTH>>1;
    int HALF_H = SCREEN_HEIGHT>>1;
    GLuint txt; 
    unsigned char* bitmapData;
    void Render()
    {	
      glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); 
      glBegin(GL_QUADS);
        glTexCoord2i(0,0);glVertex2i(0,0);
        glTexCoord2i(SCREEN_WIDTH,0);glVertex2i(SCREEN_WIDTH,0);
        glTexCoord2i(SCREEN_WIDTH,SCREEN_HEIGHT);glVertex2i(SCREEN_WIDTH,SCREEN_HEIGHT);
        glTexCoord2i(0,SCREEN_HEIGHT);glVertex2i(0,SCREEN_HEIGHT);
      glEnd();
     
      glFinish();
      glutSwapBuffers();
    }
    void CreateTexture(GLuint* texID){
      Uint32 lsize = SCREEN_WIDTH*SCREEN_HEIGHT*4 ;
      GLuint* ldata = new GLuint[lsize ];
      memset(ldata,0,lsize );
      for( Uint32 i=0; i<lsize; ++i ){
        if( (i+1)%4 ){
    	ldata[i]=0;  //black
        }else{
    	ldata[i]=MAX_UINT32;  //alpha
        }
      }	
      //white pixel in center of screen
      ldata[(SCREEN_WIDTH*HALF_H+ HALF_W)*4] = MAX_UINT32;
      ldata[(SCREEN_WIDTH*HALF_H+ HALF_W)*4+1] = MAX_UINT32;
      ldata[(SCREEN_WIDTH*HALF_H+ HALF_W)*4+2] = MAX_UINT32; 
     
      glActiveTexture( GL_TEXTURE0 );
      glGenTextures( 1, texID );
      glBindTexture( GL_TEXTURE_RECTANGLE, *texID );
      glTexParameterf(GL_TEXTURE_RECTANGLE, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 
      glTexImage2D(	GL_TEXTURE_RECTANGLE, 0, GL_RGBA, SCREEN_WIDTH, SCREEN_HEIGHT, 0, GL_RGBA, GL_UNSIGNED_INT, ldata );
      delete[] ldata;
    }
     
     
    int main(int argc, char** argv)
    {	
      glutInit(&amp;argc,argv);
      glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE);
      glutInitWindowSize(SCREEN_WIDTH,SCREEN_HEIGHT);
      glutCreateWindow("SIMPLE DISPLAY");
      glewInit();
      glutDisplayFunc(Render);	
     
      glMatrixMode(GL_PROJECTION);
      glLoadIdentity();
      gluOrtho2D(0,SCREEN_WIDTH, 0, SCREEN_HEIGHT);
     
      glEnable(GL_TEXTURE_RECTANGLE);    
      CreateTexture(&amp;txt); 
      glutMainLoop();
      return 0;
    }
    This should give u this output. There is a small white dot in the center.
    Regards,
    Mobeen

  5. #5
    Intern Newbie
    Join Date
    Dec 2010
    Posts
    49

    Re: GL_TEXTURE_RECTANGLE with GLuint data?

    I think it's because I'm using sampler2D but I need samplerRECT

    Is this not core functionality in a 3.3 context? How hard would it be to add?

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

    Re: GL_TEXTURE_RECTANGLE with GLuint data?

    I think it's because I'm using sampler2D but I need samplerRECT
    And that's why it's a good idea to post your shader.

    Is this not core functionality in a 3.3 context? How hard would it be to add?
    You just use a samplerRect in your shader instead of a sampler2d.

  7. #7
    Intern Newbie
    Join Date
    Dec 2010
    Posts
    49

    Re: GL_TEXTURE_RECTANGLE with GLuint data?

    Okay I found that I can use a usampler2DRect,
    but there does not seem to be defined a texture2DRect( , );, I get the shader compiler error C7531: "global function texture2DRect requires "#extension GL_EXT_gpu_shader4 : enable" before use

    is this a line I can add to my code somewhere? or do I need some header files?

    Edit: I got it, just add #extension GL_EXT_gpu_shader4 : enable to my shader now it all works

  8. #8
    Intern Newbie
    Join Date
    Dec 2010
    Posts
    49

    Re: GL_TEXTURE_RECTANGLE with GLuint data?

    Is GL_TEXTURE_RECTANGLE not compatible with glCopyTexImage2D? I wanted to copy the last frame into this texture but it would complicate things if the texture has to be a power of 2 instead of the screen dimensions.

  9. #9
    Advanced Member Frequent Contributor
    Join Date
    Mar 2009
    Location
    Singapore
    Posts
    802

    Re: GL_TEXTURE_RECTANGLE with GLuint data?

    Quote Originally Posted by PrestoChung
    Is GL_TEXTURE_RECTANGLE not compatible with glCopyTexImage2D? I wanted to copy the last frame into this texture but it would complicate things if the texture has to be a power of 2 instead of the screen dimensions.
    glCopyTexImage2D should work fine with GL_TEXTURE_RECTANGLE. You should check your code. The first thing i would look at is my texture format and the internal format I am passing to glCopyTexImage2D.
    Regards,
    Mobeen

  10. #10
    Intern Newbie
    Join Date
    Dec 2010
    Posts
    49

    Re: GL_TEXTURE_RECTANGLE with GLuint data?

    <div class="ubbcode-block"><div class="ubbcode-header">Click to reveal.. <input type="button" class="form-button" value="Show me!" onclick="toggle_spoiler(this, 'Yikes, my eyes!', 'Show me!')" />]<div style="display: none;">
    Code :
    #version 330
    #extension GL_EXT_gpu_shader4 : enable
     
    uniform usampler2DRect tex;
     
    in vec2 texPos;
     
    out vec4 outFragColor;
     
    void main()
    {
    	vec4 out_color;
    	vec4 tex_color_left;
     
    	vec2 top = vec2(0, 1);
    	vec2 bottom = vec2(0, -1);
    	vec2 right = vec2(1, 0);
    	vec2 left = vec2(-1, 0);
     
    	tex_color_left = texture(tex, texPos+left);
     
    	if( tex_color_left.x>0.5 ){
    		out_color = vec4(1.0, 1.0, 1.0, 1.0);
    	}
    	else{
    		out_color = vec4(0.0, 0.0, 0.0, 1.0);
    	}
     
    	outFragColor = out_color;
    }
    [/QUOTE]</div>

    Edit: ah, i answered my own question again (problem with equality with floats)

Posting Permissions

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