OpenGL noob issue: cubemap

OpenGL noob issue: cubemap

Discuss the source code and development of Spring Engine in general from a technical point of view. Patches go here too.

Moderator: Moderators

Post Reply
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

OpenGL noob issue: cubemap

Post by Argh »

How do I define a cubemap in Lua OpenGL?

I want to replace Spring reflections with a static cubemap. I have cubemaps I've built, but I'm stuck. Just sending the texture doesn't work. Spring ignores it.

So, once I've bound a texture via glTexture, what do I do to tell Spring it's a cubemap?

Or do I have to do a FBO and render it to another texture with those parameters.

Sorry, I know that's probably trivial, but I'm stuck.

I tried:

Code: Select all

glTexture(2,"unittextures/mesa_city_cube.tga")
gl.MultiTexGen(2, GL.REFLECTION_MAP,true)
And that doesn't work.
User avatar
jK
Spring Developer
Posts: 2299
Joined: 28 Jun 2007, 07:30

Re: OpenGL noob issue: cubemap

Post by jK »

erm you ... can ... not

I thought about this already, but didn't ever needed it.
So you can neither load cubemaps from dds nor construct them from other images. The only way atm is to create a renderable Lua Texture and then to use a FBO to fill it.

Depending on your problem you could also use a spheremap instead.
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: OpenGL noob issue: cubemap

Post by Argh »

erm you ... can ... not
Well, that certainly simplifies stuff :lol:

So I could create a Lua Texture via:

gl.CreateTexture(Xsize, Ysize, texSpec)

where texSpec = {
target = GL.REFLECTION_CUBE,
min_filter = GL.NEAREST,
mag_filter = GL.NEAREST,
}

And then fill it via a FBO and a quick shader to a quad?

OK, I've got all that crap written in POPS, I guess I'll move it over.
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: OpenGL noob issue: cubemap

Post by Argh »

Oh, noes.

It's not quite that easy. Drat. Here's what I tried. More if I can find time to get back to this.

Code: Select all

--REFLECTION SETUP
local reflectionSpec = {
	target = GL.REFLECTION_MAP,
	min_filter = GL.LINEAR,
	mag_filter = GL.LINEAR,
}	

local reflectionTex = gl.CreateTexture(3072, 512, reflectionSpec)

  reflectionFBO = gl.CreateFBO()
 reflectionFBO.color0 = reflectionTex
  reflectionFBO.drawbuffers = {
    GL_COLOR_ATTACHMENT0_EXT,
  }


local function CreateReflectionTexture()
local reflectionShader = gl.CreateShader({
    vertex = [[
        void main(void)
        {    
            gl_TexCoord[0].xy = gl_MultiTexCoord0.xy;
            gl_Position = gl_Vertex;
        }
    ]],
    fragment = [[
              uniform sampler2D ReflectTextureOne;
            uniform sampler2D ReflectTextureTwo;            
        void main()
        {
//    RENDER TO TEXTURES
            gl_FragData[0] = texture2D(ReflectTextureTwo,gl_TexCoord[0].xy);
        }
        ]],
    uniformInt = {
        ReflectTextureOne = 0,
        ReflectTextureTwo = 1,        
        },
      })
    return reflectionShader
end

function gadget:Initialize()
	reflectionShader = CreateReflectionTexture()
end

local reflectionSet = 0
function gadget:DrawWorld()
	if reflectionSet == 0 then
		gl.ActiveFBO(reflectionFBO, true, function()
			glTexture(1,"unittextures/mesa_city_cube.tga")		
			glUseShader(reflectionShader)  -- DRAW THE TEXTURE
			gl.TexRect(-1,-1,1,1,0,0,1,1)
		end)  -- END FBO	
		reflectionSet = 1
	end
end
It all compiles and stuff, but it's getting treated like a 2D image when I send it to unitRendering, i.e. it gets ignored. And attempting to define ReflectTextureOne as a cubemap causes the shader to crash... so, did I forget something when setting the texture parameters, or is there something else I need to do here?
Post Reply

Return to “Engine”