Jump to content
  • Advertisement

Terrimus

Member
  • Content Count

    36
  • Joined

  • Last visited

Community Reputation

122 Neutral

About Terrimus

  • Rank
    Member
  1. Terrimus

    SOLVED: Triangle Strip + GLSL = ?

    I thought attribute variables could be changed at any time? Anyway, I just found a way around setting the variable per vertex as I thought I had to do. Edit: I misunderstood your post. Now I see, I can set the attribute variables, but not get the location of the between glBegin-glEnd :)
  2. I have this test code which works: GLShader shader("shaders/test.vert", "shaders/test.frag"); ... shader.bind(); for(int j = 0; j < 100; j += 10) { shader.setAttrib1f("a", 1.0f); glBegin(GL_TRIANGLE_STRIP); for(int i = 0; i < 100; i += 10) { glVertex3f(i, 0, j); glVertex3f(i, 0, j + 10); } glEnd(); } shader.unbind(); but if I put the setAttrib-call inside the blBegin(), I get some strange results. This: glBegin(GL_TRIANGLE_STRIP); for(int i = 0; i < 100; i += 10) { shader.setAttrib1f("a", 1.0f); glVertex3f(i, 0, j); glVertex3f(i, 0, j + 10); } gives me: I've used shaders + triangle strip before without this issue, and I really don't understand what is wrong. The shaders are really basic: vert: attribute float a; void main() { vec4 v = vec4(gl_Vertex); v.y = a; gl_Position = gl_ModelViewProjectionMatrix * v; } frag: void main() { gl_FragColor = vec4(1, 1, 1, 1); } The setAttrib-function: void GLShader::setAttrib1f(const char* name, float value) { GLint location = glGetAttribLocationARB(m_prog, name); glVertexAttrib1fARB(location, value); } [Edited by - Terrimus on December 3, 2009 7:14:30 PM]
  3. Again, I think I've solved the problem. I added a '\0' to the buffer returned from my textfile-reading method. Stupid error, but now I know :)
  4. Ok, thanks for the tip :)
  5. This is from the render-function in the heightmap-class: ... if(m_shader.getID() == 0) m_shader.load("shaders/terrain.vert", "shaders/terrain.frag"); m_shader.bind(); if(m_textures[0] == 0) { m_textures[0] = TextureManager::getInstance()->createTexture("data/arrow.tga"); m_textures[1] = TextureManager::getInstance()->createTexture("data/grass.tga"); m_textures[2] = TextureManager::getInstance()->createTexture("data/mountain.tga"); m_shader.setUniform1i("arrow", 0); m_shader.setUniform1i("grass", 1); m_shader.setUniform1i("mount", 2); } glActiveTextureARB(GL_TEXTURE0_ARB); glBindTexture(GL_TEXTURE_2D, m_textures[0]); glEnable(GL_TEXTURE_2D); glActiveTextureARB(GL_TEXTURE1_ARB); glBindTexture(GL_TEXTURE_2D, m_textures[1]); glEnable(GL_TEXTURE_2D); glActiveTextureARB(GL_TEXTURE2_ARB); glBindTexture(GL_TEXTURE_2D, m_textures[2]); glEnable(GL_TEXTURE_2D); ...
  6. Well, after 3-4 hours trying to avoid cryptic errors and things not working, it seems like I've got my code to work (as expected). I am trying to write a simple shader for textureing a heightmap. But to be able to set the sampler2D-variables in my fragment shader I have to declare an empty variable first? this doesn't work: uniform sampler2D arrow, grass, mount; void main() { // vec4 color = texture2D(tex0, vec2(gl_TexCoord[0])) + texture2D(tex1, vec2(gl_TexCoord[0])) + texture2D(tex2, vec2(gl_TexCoord[0])); gl_FragColor = texture2D(mount, vec2(gl_TexCoord[0])); } but this do: uniform sampler2D x, arrow, grass, mount; void main() { // vec4 color = texture2D(tex0, vec2(gl_TexCoord[0])) + texture2D(tex1, vec2(gl_TexCoord[0])) + texture2D(tex2, vec2(gl_TexCoord[0])); gl_FragColor = texture2D(mount, vec2(gl_TexCoord[0])); } Though my code work as I want now, I really want to know why I have to declare that variable. Is it an issue with my graphic card (NVIDIA GeForce 8200M)?
  7. Terrimus

    GLSL: strange syntax error?

    Think I've solved it. I changed my shader-class to properly detach and delete the shaders/program, and now it seems to work. So if anyone else have the same problem try that :P
  8. Terrimus

    GLSL: strange syntax error?

    Hm, maybe there is a issue with my graphic card driver? Seems like glGetUniformLocation allways return -1.
  9. Terrimus

    GLSL: strange syntax error?

    *bump* new strange syntax error :S (see top)
  10. Terrimus

    GLSL: strange syntax error?

    I apparently fixed it. Just added if(!GLEW_ARB_multitexture || (glActiveTexture == NULL) || (glClientActiveTexture == NULL)) { cout << "Warning! No multitexture support!" << endl; } in my glew-initiating method, and now it works. :O
  11. Hi I am getting some strange (and random) errors when trying to use a shader. Fragment info ------------- 0(14) : error C0000: syntax error, unexpected $undefined at token "<undefined>" 0(14) : error C0501: type name expected at token "<undefined>" This is a simple shader just taking the color from the the first texture Vertex: void main() { gl_TexCoord[0] = gl_MultiTexCoord0; gl_Position = ftransform(); } Fragment: uniform sampler2D Texture0; uniform sampler2D Texture1; void main() { vec4 tex0, tex1; tex0 = texture2D(Texture0, gl_TexCoord[0].st); tex1 = texture2D(Texture1, gl_TexCoord[0].st); gl_FragColor = tex1; } I've run this code some times, and sometimes I get the error, sometimes I don't. But I can't see any syntax errors? I set the TextureX-variables like this: glUniform1i(glGetUniformLocation(programID, "Texture0"), tex0); [Edited by - Terrimus on November 26, 2009 11:20:05 AM]
  12. Ok, thanks. I've just wanted to try to use quaternions because I wanted to learn it, but guess they still are over my head. I'm sticking to matrices for now :)
  13. Hi I'm trying to create a simple camera class. I'm using 3 vectors (eye, view, up) and trying to use quaternions for rotation, but getting undesirable results (e.g. crazy results). I'm only rendering a quad at (0, 0, -10). When I try to rotate the cam it just seem to spin around the origo. But when I move the camera, suddenly it appear a different place or totaly disappear. I've checked the quaternion-class against the calculator here and it seems to work. I've got a rotation-function in the camera class which rotates the camera-view around the Y-axis: axis.x = 0; axis.y = 1; axis.z = 0; Quat tmp = createRotationQuaternion(angle, axis); Quat view(0, m_view.x, m_view.y, m_view.z); Quat res = (tmp * view) * conjugate(tmp); m_view.x = res.x; m_view.y = res.y; m_view.z = res.z; The createRotationQuaternion(float, Vec3) looks like this: Quat createRotationQuaternion(const float angle, const Vec3& axis) { float halfTheta = angle * 0.5f; float sinHalfTheta = sinf(halfTheta); float w = cosf(halfTheta); float x = sinHalfTheta * axis.x; float y = sinHalfTheta * axis.y; float z = sinHalfTheta * axis.z; return Quat(w, x, y, z); } I am using gluLookAt() to apply the camera. The whole code can be viewed here: http://www.mipmap.org/au3d-trac/browser/trunk
  14. Terrimus

    Matrix combined transformation and rotation

    Yes, I know that I have to invert the transformation (the way I have it now I just "invert" the values on keypress. E.g. when I press forward I actually move backwards. I almost have it working now, but I get some strange results. It seems to work when I start the application, but when I do some rotation/strafing I get the strange results. Again; I want to move (translate along the Z-axis according to the rotation), and strafe (translate along the X-axis according to the rotation). Any good articles/books on this subject? Found a lot about matrices/transformations, but nothing about how to actually implement it in a game engine :(
  15. Terrimus

    Matrix combined transformation and rotation

    1. column-major (since I am using OpenGL) 2. no idea ;) a vector is simple stored as three floats xyz 3. m_trans is an instance of my Matrix-class in the camera class. It holds the camera's transformation 4. currently I am not doing any inverting 5. I doubt it. I 'apply' my camera with glMultMatrix, the same way I itend to apply the transformations of the nodes in my scene graph. glPushMatrix(); glLoadMatrix(m_trans.getData()); glPopMatrix();
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!