I want to load raw texture from floats like this:
var missingLM : GLuint # missing lightmap index
let white : seq[float32] = @[1.0'f32, 1.0'f32, 1.0'f32, 1.0'f32]
glGenTextures(1, missingLM.addr)
glBindTexture(GL_TEXTURE_2D,missingLM)
glTexImage2D(GL_TEXTURE_2D, 0'i32, GL_RGBA8.GLint, 1'i32, 1'i32, 0'i32, GL_RGB, cGL_FLOAT, white.unsafeAddr)
However, the output is black, i tried changing the type of the seq, but no luck. I have somekind of output only if i change the type from cGL_FLOAT to GL_UNSIGNED_BYTE, which outputs mangled greenish color ofcorse.
I have the same code in C which works:
GLuint missing_LM_ids;
GLfloat gray_lightmap[] = {0.5f, 0.5f, 0.5f, 0.5f};
glGenTextures(1, &missing_LM_ids);
glBindTexture(GL_TEXTURE_2D, missing_LM_ids);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, GL_RGB, GL_FLOAT, &gray_lightmap);
Have someone encountered something like this?
I do know nothing about OpenGL with Nim, but your code seems to contain again the same error as of most Nim OpenGL beginners:
Nim Seq is not a plain sequence of values! So passing seq.addr where a array (pointer to first element) is expected is always wrong. You may try
glTexImage2D(GL_TEXTURE_2D, 0'i32, GL_RGBA8.GLint, 1'i32, 1'i32, 0'i32, GL_RGB, cGL_FLOAT, white[0].addr)
Of course there may exist more errors in your code, I have not compared all C code to Nim code. Maybe you do not need a seq at all, seq is a dynamic container like C++ vector. If number of elements is a compile time constant, you may use a plain array which is similar to a C array.
Tnx Stefan, it works.
So as i understood, this is similar to &white.front() when using c++ vector?
Great that it works. Yes, I think it is the same as front() for C++ vector.
The OpenGL wrapper is really very ugly, I wonder why your initial code compiled at all.
To make it a bit less ugly you may try something like
var missingLM : GLuint # missing lightmap index
let white : seq[float32] = @[1.0'f32, 1, 1, 1]
glGenTextures(1, missingLM.addr)
glBindTexture(GL_TEXTURE_2D,missingLM)
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8.GLint, 1, 1, 0, GL_RGB, cGL_FLOAT, white[0].addr)
Because for an array/seq literal you have to specify only the type of first element, the other elements have same type. And when passing a literal number to a proc the type should match automatically. (Just a note, not tested. Use whatever works for you.)
:) Well it compiled, but didn't work because all those lacking casts
Anyway, we have lightmaps now :)