示例#1
0
 private void ResizeTexture(int w, int h)
 {
     if (buffer == null)
     {
         buffer = new TextureHandle(w, h);
     }
     else
     {
         buffer.SetTextureSize(w, h);
     }
 }
        public void Render(IController controller)
        {
            GetSpectrum(controller);

            Gl.glPushAttrib(Gl.GL_ENABLE_BIT);
            Gl.glDisable(Gl.GL_DEPTH_TEST);
            Gl.glTexEnvf(Gl.GL_TEXTURE_ENV, Gl.GL_TEXTURE_ENV_MODE, Gl.GL_DECAL);

            // voiceprint

            Gl.glMatrixMode(Gl.GL_PROJECTION);
            Gl.glPushMatrix();
            Gl.glLoadIdentity();

            Glu.gluOrtho2D(0, controller.Width, 0, controller.Height);

            Gl.glMatrixMode(Gl.GL_TEXTURE);
            Gl.glPushMatrix();
            Gl.glLoadIdentity();

            Gl.glScalef(1f / controller.Width, 1f / controller.Height, 1f);

            if (voiceprintBuffer == null)
            {
                voiceprintBuffer = new TextureHandle(controller.Width, controller.Height);
            }
            else
            {
                voiceprintBuffer.SetTextureSize(controller.Width, controller.Height);
            }

            Gl.glBindTexture(Gl.GL_TEXTURE_2D, voiceprintBuffer.TextureId);
            // OPTIMIZATION: could just copy texture of width voiceprintHeightPx
            // but then the coordinates get tricky
            Gl.glCopyTexImage2D(Gl.GL_TEXTURE_2D, 0, Gl.GL_RGB, 0, 0,
                                controller.Width, controller.Height, 0);

            // clean palette
            Gl.glClearColor(0, 0, 0, 1);
            Gl.glClear(Gl.GL_COLOR_BUFFER_BIT);

            // paste voiceprint region of copied texture, shifted down 1px
            Gl.glEnable(Gl.GL_TEXTURE_2D);
            Gl.glBegin(Gl.GL_QUADS);

            Gl.glTexCoord2f(0, 1);
            Gl.glVertex2f(0, 0);

            Gl.glTexCoord2f(0, voiceprintHeightPx);
            Gl.glVertex2f(0, voiceprintHeightPx - 1);

            Gl.glTexCoord2f(controller.Width, voiceprintHeightPx);
            Gl.glVertex2f(controller.Width, voiceprintHeightPx - 1);

            Gl.glTexCoord2f(controller.Width, 1);
            Gl.glVertex2f(controller.Width, 0);

            Gl.glEnd();
            Gl.glDisable(Gl.GL_TEXTURE_2D);

            Gl.glBegin(Gl.GL_QUADS);
            // instead of using a smoothed buffer like with the analyzer,
            // use the direct buffer for nicer looking output (less blurry)
            float x = 0;

            for (int i = 0; i < bufferLength; i++)
            {
                float v = spectrumBuffer[i];
                Color.FromHSL(120 * (1 - v), 1, Math.Min(0.5f, v)).Use();

                // draw a little beyond the edge to ensure no visible seams
                Gl.glVertex2f(x, voiceprintHeightPx - 1);
                Gl.glVertex2f(x, voiceprintHeightPx + 1);
                x += bufferScaling[i];
                Gl.glVertex2f(x, voiceprintHeightPx + 1);
                Gl.glVertex2f(x, voiceprintHeightPx - 1);
            }
            Gl.glEnd();

            Gl.glMatrixMode(Gl.GL_TEXTURE);
            Gl.glPopMatrix();

            Gl.glMatrixMode(Gl.GL_PROJECTION);
            Gl.glPopMatrix();

            // analyzer

            Gl.glMatrixMode(Gl.GL_PROJECTION);
            Gl.glPushMatrix();
            Gl.glLoadIdentity();

            // analyzer at top side of screen
            Glu.gluOrtho2D(-1, 1, 1 - analyzerHeightOrtho, 1);

            RenderAnalyzer();// coordinates: [-1,+1] in x,y

            Gl.glMatrixMode(Gl.GL_PROJECTION);
            Gl.glPopMatrix();

            Gl.glPopAttrib();
        }
示例#3
0
        private void ResizeToWidgetSize()
        {
            if (renderWidth == widgetWidth &&
                renderHeight == widgetHeight)
            {
                if (resizeTexture != null)
                {
                    resizeTexture.Dispose();
                    resizeTexture = null;
                }

                return;
            }

            if (resizeTexture == null)
            {
                resizeTexture = new TextureHandle();
            }

            resizeTexture.SetTextureSize(renderWidth, renderHeight);

            Gl.glPushAttrib(Gl.GL_ENABLE_BIT);
            Gl.glDisable(Gl.GL_DEPTH_TEST);
            Gl.glEnable(Gl.GL_TEXTURE_2D);

            Gl.glTexEnvf(Gl.GL_TEXTURE_ENV, Gl.GL_TEXTURE_ENV_MODE, Gl.GL_DECAL);
            Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_S, Gl.GL_CLAMP);
            Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_WRAP_T, Gl.GL_CLAMP);

            Gl.glBindTexture(Gl.GL_TEXTURE_2D, resizeTexture.TextureId);
            Gl.glCopyTexImage2D(Gl.GL_TEXTURE_2D, 0, Gl.GL_RGB, 0, 0,
                                renderWidth, renderHeight, 0);

            Gl.glViewport(0, 0, widgetWidth, widgetHeight);

            Gl.glMatrixMode(Gl.GL_PROJECTION);
            Gl.glLoadIdentity();

            Gl.glMatrixMode(Gl.GL_MODELVIEW);
            Gl.glLoadIdentity();

            Gl.glColor4f(1, 1, 1, 1);

            Gl.glBegin(Gl.GL_QUADS);

            Gl.glTexCoord2f(0, 0);
            Gl.glVertex2f(-1, -1);

            Gl.glTexCoord2f(0, 1);
            Gl.glVertex2f(-1, 1);

            Gl.glTexCoord2f(1, 1);
            Gl.glVertex2f(1, 1);

            Gl.glTexCoord2f(1, 0);
            Gl.glVertex2f(1, -1);

            Gl.glEnd();

            Gl.glPopAttrib();
        }