Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

111 Neutral

About Aumnayan

  • Rank
  1. I added the sampler1D colorTexture, the color offset and tmp calculations and changed the color from color = vColor. I'm simply not seeing why this wouldn't be linking. If I change color = tmp.rgba; to color = vColor; it links appropriately. [source lang="cpp"]GLbyte TerrainVertexShaderStr[] = "uniform sampler1D colorTexture; \n" "in vec4 vPosition; \n" // Vertex Position "in vec3 vNormal; \n" // Normal "in vec4 vColor; \n" // The RGBA color "in vec2 vTexCoord; \n" // Texture Coordinate "out vec2 texCrd; \n" "out vec4 color; \n" "void main () { \n" " texCrd = vTexCoord; \n" " float color_offset; \n" " vec4 tmp; \n" " color_offset = (gl_Vertex.y + 400.0f) / 5120.0f; \n" " tmp = texture1D(colorTexture, color_offset); \n" " color = tmp.rgba; \n" " gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; \n" "}"; GLbyte TerrainFragmentShaderStr[] = "uniform sampler2D grndTexture; \n" "in vec4 color; \n" "in vec2 texCrd; \n" "void main () { \n" " vec4 tcolor = texture(grndTexture, texCrd); \n" " gl_FragColor = color * tcolor; \n" "}";[/source]
  2. Aumnayan

    Simple vertex shader

    Okay, I've never spent to long with playing with the initialization code and tend to copy/paste from previous applications so I don't have how to use it burned into my head. Do you know what version of GL and GLSL you're using? If it's a latter one (after gl_ModelViewProjectionMatrix has been depreciated) it could be possible that you're GLSL compiler has left the prototype of the variable but the declaration of it was removed. This would allow the compiler to complete but cause the linker to fall on it's backside. Try taking it out, and see if it compiles/links. Even if it dosn't do anything that information will help you get to the bottom of this.
  3. Aumnayan

    Simple vertex shader

    Why is you shadersrc an array of character pointers? If I remember right, this grantees that the POINTERS are in concurrent memory space, but the strings themselves can technically live anywhere in memory (okay, okay, not anywhere but you get the point). They aren't guaranteed to evaluate to <string1><string2>..<string4> in memory and can have garbage in between depending on how the OS optimizes laying out the memory. I assume your nos calculation evaluates to 4? Try modifying it such that [source lang="cpp"]const GLchar shadersrc[] = "void main()\n" "{\n" "gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n" "}"; nos = sizeof(shadersrc); [/source] <edit> I could of course be wrong in the use of glShaderSource since I don't have any references in front of me.
  4. Aumnayan

    Normal Calculations

    I apologize. After I made the changes you suggested, my scene now looks like: There are still several areas to work on, but I don't believe what's remaining has to do with the normal calculations. I appreciate you're help.
  5. Aumnayan

    Normal Calculations

    Thanks L. Spiro, that is what I was looking for. This is primarily a tool to help me learn the in's and outs of opengl, so I'm not horrible concerned with performance, which I can come back to if it ever envolves into something more then a science experiment. To be clear, that particular bit should read: [source lang="cpp"]. . . obj1 = crossVec3(&obj1, &obj2); obj1 = normalizeVec3(&obj1); normal = addVec3(&normal, &obj1); } } normal = normalizeVec3(&normal); . . .[/source] correct?
  6. I'm working on various aspects of shading and am experiencing some results that I didn't expect. Right now, I just want to eliminate the normals as the potential cause, however since I'm fairly new to openGL I'm having a hard time doing this with any amount of certanty. If someone is willing to take a look at my normal generation code and give me their oppinion/point out problems, I would appreciate it. The verts are stored in one large VBO at the moment, then drawn through a glDrawRangeElements call using GL_TRIANGLES. I'm unsure if/how the order matters, however the triangles and their verts are arranged in the following order: triangle_1 = v1, v2, v0 triangle_2 = v2, v3, v0 triangle_3 = v3, v4, v0 triangle_4 = v4, v1, v0 [source lang="cpp"]void build_TriNormals (SVN_TERRAIN_VERTEX *svnVerts, int svnStride) { int i, j, k; SVN_TERRAIN_VERTEX *v[6]; for (i = 0; i < svnStride; i++) { for (j = 0; j < svnStride; j++) { // v2 // | // v1 - v0 - v3 // | // v4 v[0] = &svnVerts[(i * svnStride) + j]; if (v[0]) { v[1] = (!j) ? NULL: v[0] - 1; v[2] = (i == svnStride - 1) ? NULL: v[0] + svnStride; v[3] = (j == svnStride - 1) ? NULL: v[0] + 1; v[4] = (!i) ? NULL: v[0] - svnStride; v[5] = v[1]; SVN_VEC3 normal; memset((char*) &normal, 0, sizeof(SVN_VEC3)); for (k = 1; k < 5; k++) { if (v[k] && v[k + 1]) { SVN_VEC3 obj1, obj2; obj1 = subVec3((SVN_VEC3*) v[k], (SVN_VEC3*) v[0]); obj2 = subVec3((SVN_VEC3*) v[k + 1], (SVN_VEC3*) v[0]); obj1 = crossVec3(&obj1, &obj2); normal = addVec3(&normal, &obj1); } } normal = normalizeVec3(&normal); v[0]->Xnorm = normal.x; v[0]->Ynorm = normal.y; v[0]->Znorm = normal.z; } } } } SVN_VEC3 normalizeVec3(SVN_VEC3* vec) { SVN_VEC3 retVal; float length; length = sqrt(pow(vec->x, 2) + pow(vec->y, 2) + pow(vec->z, 2)); retVal.x = vec->x / length; retVal.y = vec->y / length; retVal.z = vec->z / length; return retVal; } SVN_VEC3 crossVec3(SVN_VEC3 *left, SVN_VEC3 *right) { SVN_VEC3 retVal; retVal.x = (left->y * right->z) - (left->z * right->y); retVal.y = (left->z * right->x) - (left->x * right->z); retVal.z = (left->x * right->y) - (left->y * right->x); return retVal; } SVN_VEC3 crossVec3(SVN_VEC3 *left, SVN_VEC3 *right) { SVN_VEC3 retVal; retVal.x = (left->y * right->z) - (left->z * right->y); retVal.y = (left->z * right->x) - (left->x * right->z); retVal.z = (left->x * right->y) - (left->y * right->x); return retVal; }[/source]
  • Advertisement

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!