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 =)
// 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();