- Home /
Question by
Lasseastrup3 · May 01, 2014 at 09:26 PM ·
graphicsrendertexturematerial colorgl
GL.Quads not correctly displaying color. It's all black
Hey I'm currently in a situation where I have several cameras in my scene, each with the TestClass script (se below) attached. Each of their textures (_texture) is being draw correctly on screen, but when I start adding elements in the Splatter dictionary the quads added are all black, regardless of what color I pass along. Why is that? I'm using a simple VertexLit shader.
What am I missing?
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using System.Diagnostics;
[RequireComponent(typeof(Camera))]
public class TestClass : MonoBehaviour
{
private Texture2D _texture;
private Material _mat;
private RenderTexture _renderTexture;
public Dictionary<Vector2,Color> Splatter;
void Awake()
{
Splatter = new Dictionary<Vector2, Color>();
}
public RenderTexture SetTexture(Texture2D tex, Material mat)
{
_mat = mat;
_texture = tex;
_renderTexture = new RenderTexture(tex.width,tex.height, 0);
_renderTexture.generateMips = false;
_renderTexture.filterMode = FilterMode.Point;
_renderTexture.Create();
Graphics.Blit(tex, _renderTexture);
GetComponent<Camera>().targetTexture = _renderTexture;
return _renderTexture;
}
public void OnPostRender()
{
Graphics.Blit(_texture, _renderTexture);
GL.PushMatrix();
GL.LoadPixelMatrix(0, _texture.width, _texture.height, 0);
GL.Begin(GL.QUADS);
foreach (var pos in Splatter)
{
GL.Color(pos.Value);
GL.Vertex3(pos.Key.x, -pos.Key.y + _texture.height, 0);
GL.Vertex3(pos.Key.x + 1, -pos.Key.y + _texture.height, 0);
GL.Vertex3(pos.Key.x + 1, -pos.Key.y - 1 + _texture.height, 0);
GL.Vertex3(pos.Key.x, -pos.Key.y - 1 + _texture.height, 0);
}
GL.End();
GL.PopMatrix();
}
}
I've done all of this as a way of manipulating a texture without using Texture2D.Apply().
Hope someone out there can help :)
Kind Regards Lasse
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613144032im_/https://answers.unity.com/themes/thub/images/avi.jpg)