Skip to content

Instantly share code, notes, and snippets.

@grimmdev
Created May 16, 2015 03:42
Show Gist options
  • Save grimmdev/7c15295edf9adf3cdb14 to your computer and use it in GitHub Desktop.
Save grimmdev/7c15295edf9adf3cdb14 to your computer and use it in GitHub Desktop.
Small Texture Utility for some texture functions in Unity
using UnityEngine;
using System.Collections;
public class TextureTest : MonoBehaviour {
public Renderer rend;
// Use this for initialization
private void Awake () {
rend.material.mainTexture = TextureUtility.CamToText ();
}
}
using UnityEngine;
using System;
using System.Collections;
public class TextureUtility {
// Let's convert or make a texture 2d from a webcam image.
public static Texture2D CamToTexture() {
WebCamTexture webcamTexture = new WebCamTexture();
webcamTexture.Play();
Texture2D tempText = new Texture2D(webcamTexture.width,webcamTexture.height);
IntPtr pointer = webcamTexture.GetNativeTexturePtr();
tempText.UpdateExternalTexture(pointer);
return tempText;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment