(solved) Retro game for blender 2.7 GE. Proper texture scrolling and OpenGL requirements

I hope there is still room for (now “retro”) blender 2.7 topics :grinning:.

My computer is kind of “modern”, but I never got used to blender versions after 2.79, because they run a bit slow, and the whole game engine was changed. So I decided i’ll create a “retro” game using the old 2.7 game engine.

I’ve always wanted a function to scroll textures to simulate rivers/lava etc… with the old GE without using GLSL. There are some old posts which talk about using GLSL and / or editing texture coordinates of all vertices using a python loop.

But these methods looked a bit too complicated and “not the best”, because I knew opengl can just update the texture matrix and “move” the uv coordinates of all vertices in one (hardware accelerated) go. So I went to a 2.76 API doc, and there it was… “transformUV”. :grinning: :grinning:

This is a python script which will scroll, scale and rotate a texture using only hardware functions in multitexture mode (again, not GLSL).

from bge import logic
import math
import mathutils
from mathutils import Vector

object = logic.getCurrentController().owner

tx = 0;
ty = 0;
angle = 0;
sx = 1;
sy = 1;
if "Texture_Scroll_X" in object:
    tx = object["Texture_Scroll_X"]   # scroll U
if "Texture_Scroll_Y" in object:
    ty = object["Texture_Scroll_Y"]  # scroll V
if "Texture_Rot" in object:  
    angle = object["Texture_Rot"]  # rotation
if "Texture_Scale_X" in object:
    sx = object["Texture_Scale_X"]   # scale U
if "Texture_Scale_Y" in object:
    sy = object["Texture_Scale_Y"]   # scale V

# 2D rotation components
a =  sx*math.cos(angle)
b = -sy*math.sin(angle)
c =  sx*math.sin(angle)
d =  sy*math.cos(angle)

texture_matrix = [
    [   a,     b, 0.0, tx ],
    [   c,     d, 0.0, ty ],
    [ 0.0,   0.0,  1.0, 0.0],
    [ 0.0,   0.0,  0.0, 1.0]
    ]

#use hardware to update texture matrix
object.meshes[0].transformUV(0,texture_matrix,-1,-1)

To use it, add these (float) properties to an object:
Texture_Scroll_X
Texture_Scroll_Y
Texture_Rot
Texture_Scale_X
Texture_Scale_Y

Not all properties have to be added, just the ones you are going to use. Their float values represent speed, not a fixed value, so setting Texture_Scroll_X to 0,001 will scroll the texture 0.001 units every frame (1 unit represents the whole texture length).
Attach the script to an always actuator, with true (pulse mode) enabled.

I also wanted to know the hardware requirements for a retro game using this game engine. Looking for “blender 2.76 minimum requirements” I found it requires windows xp and opengl 2.1. I then used “apitrace” to capture all opengl functions used by the blenderplayer (only game engine, not blender GUI itself).

The result:
Blender 2.76 game engine (in multitexture mode) uses only opengl 1.4, so that will make my game compatible with really old gpus, and it also works on modern ones with no problem at all.

Great find. Since you are doing it in shader you can read the desired direction from vertex colors and make flow variations just by painting and using the same shader.

The GE minimum requirements really don’t matter that much since you will have to determine your games requirements once its done.