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 5 of 5

Thread: Only getting one pixel of a texture [Windows]

  1. #1
    Junior Member Newbie
    Join Date
    Jul 2012
    Posts
    4

    Only getting one pixel of a texture [Windows]

    For my project I need to create a plugin for Unity3D to render into an another window the exact same thing than the in-game rendering of the editor.

    I use the same OpenGL context than unity, however the window context is different.

    I use the GetNativeTextureID() in the Unity c# environment to get the texture ID. In the C++ plugin code a full screen textured quad is draw show the texture into the plugin generated window.

    My problem is that I can only see one pixel of the texture. I was wondering which states of OpenGL could cause that? Maybe it's because I use a different OpenGL version?

    Thats my OpenGL code:

    Thanks for any help =)
    Code :
                    // Start Rendering into the plugin window
    		window->setContextToWindow();
     
     
    		glViewport(0,0, config->getWidth(), config->getHeight() );
     
    		glEnable(GL_TEXTURE_2D);
    		glDisable(GL_LIGHTING);
    		glDisable(GL_CULL_FACE);
     
    		glClearColor( 0.5f, 0.5f, 0.5f, 0.0f );
    		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    		glDisable(GL_DEPTH_TEST);
     
    		glMatrixMode(GL_TEXTURE);
    		glLoadIdentity();
     
    		glMatrixMode(GL_PROJECTION);
    		glLoadIdentity();
    		gluOrtho2D(-1.0f,1.0f,-1.0f,1.0f);
     
    		glMatrixMode(GL_MODELVIEW);
    		glLoadIdentity();
     
    		glBindTexture(GL_TEXTURE_2D, textureIndex_);
     
    		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_MAG_FILTER, GL_NEAREST);
    		glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
     
     
    		glPushMatrix();
     
     		glBegin( GL_QUADS );
     			//glColor3f(1.0f,1.0f,1.0f);
     			glTexCoord2d(0.0f, 0.0f);glVertex2f( -1.0f, -1.0f );
     			glTexCoord2d(1.0f, 0.0f);glVertex2f( 1.0f, -1.0f );
     			glTexCoord2d(1.0f, 1.0f);glVertex2f( 1.0f, 1.0f );
     			glTexCoord2d(0.0f, 1.0f);glVertex2f( -1.0f, 1.0f );
     		glEnd();
    		glPopMatrix();
     
    		if (!SwapBuffers( window->getHdc() ))
    		{
    			int error = GetLastError();
    			cout << "Cant swap buff: " << error << endl;
    		}
     
    		// Continue rendering into the Unity Editor
    		window->setContextToExtern();

  2. #2
    Junior Member Newbie
    Join Date
    Jul 2012
    Posts
    4
    Even if I create and apply my own texture on the quad it shows only one pixel of the texture. If I test the same code on my own executable it works perfectly.

  3. #3
    Senior Member OpenGL Pro
    Join Date
    Jan 2007
    Posts
    1,789
    Double-check your viewport dimensions, and ensure that you don't have scissor enabled seem to be the first 2 places to look.

  4. #4
    Junior Member Newbie
    Join Date
    Jul 2012
    Posts
    4
    I forgot to say that the pixel is being rendered on the entire quad(The entire screen). It's like OpenGL is setting the same texture coordinate for all the vertices.

  5. #5
    Junior Member Newbie
    Join Date
    Jul 2012
    Posts
    4
    I resolved my problem! I wanted to verify the texture coordinate using a shader. I found that the texture coordinate looked ok in the color output of the fragment shaders. and I decided to use a shader to output the texture. It worked. There was something in the Unity context that was preventing opengl to use texture coordinate without a shader.

Posting Permissions

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