Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

122 Neutral

About pseudosig

  • Rank
  1. Also, I'm purposefully not showing screen shots since the code I'm working on is for my work, and it would reveal more about the nature of what I'm working on (unfortunately).
  2. It has the same effect, in that it just colors my shader stuff red. The unexpected thing I'm observing when both are on, is that my regular textured/pipelined code becomes just white. The geometries are there (and correct)... but it's like no texture is getting applied to the geometry. I'm pretty certain my GLSL shader is correct... I just think my OpenGL C++ code that sets up GL state for my shader is incorrect. Am referencing textures correctly in binding them and using glActiveTexture() with it? Things like that.
  3. I just have a fragment shader and here it is: #version 120 uniform sampler2D data_map; uniform sampler1D table1; uniform sampler1D table2; uniform sampler1D table3; uniform sampler1D table4; void main() { vec4 cur_color = vec4(0.0, 0.0, 0.0, 0.0); vec2 uv = gl_TexCoord[0].st; vec2 f; float tex_width = 4096.0; float tex_heigh = 2048.0; float ddx = 1.0 / tex_width; float ddy = 1.0 / tex_heigh; int cur_val = int(texture2D(data_map, gl_TexCoord[0].xy + vec2(0.0, 0.0)).r*255); int data_val = int(texture2D(data_map, gl_TexCoord[0].xy + vec2(0.0, 0.0)).g*255); // Vertical blur cur_color += (1.0/32.0) * texture2D(data_map, gl_TexCoord[0].xy + vec2(0.0, ddy*-3.0)); cur_color += (2.0/32.0) * texture2D(data_map, gl_TexCoord[0].xy + vec2(0.0, ddy*-2.0)); cur_color += (7.0/32.0) * texture2D(data_map, gl_TexCoord[0].xy + vec2(0.0, ddy*-1.0)); cur_color += (12.0/32.0) * texture2D(data_map, gl_TexCoord[0].xy + vec2(0.0, 0.0)); cur_color += (7.0/32.0) * texture2D(data_map, gl_TexCoord[0].xy + vec2(0.0, ddy*1.0)); cur_color += (2.0/32.0) * texture2D(data_map, gl_TexCoord[0].xy + vec2(0.0, ddy*2.0)); cur_color += (1.0/32.0) * texture2D(data_map, gl_TexCoord[0].xy + vec2(0.0, ddy*3.0)); // Horizontal blur cur_color += (1.0/32.0) * texture2D(data_map, gl_TexCoord[0].xy + vec2(ddx*-3.0, 0.0)); cur_color += (2.0/32.0) * texture2D(data_map, gl_TexCoord[0].xy + vec2(ddx*-2.0, 0.0)); cur_color += (7.0/32.0) * texture2D(data_map, gl_TexCoord[0].xy + vec2(ddx*-1.0, 0.0)); cur_color += (12.0/32.0) * texture2D(data_map, gl_TexCoord[0].xy + vec2(0.0, 0.0)); cur_color += (7.0/32.0) * texture2D(data_map, gl_TexCoord[0].xy + vec2(ddx*1.0, 0.0)); cur_color += (2.0/32.0) * texture2D(data_map, gl_TexCoord[0].xy + vec2(ddx*2.0, 0.0)); cur_color += (1.0/32.0) * texture2D(data_map, gl_TexCoord[0].xy + vec2(ddx*3.0, 0.0)); // Mix both verticle and horizontal blurs cur_color *= 0.5; cur_color.r += (5.0/255.0); //cur_color = texture2D(data_map, gl_TexCoord[0].xy + vec2(0.0, 0.0)); float idx = cur_color.r; if(idx*255 > 67 && cur_val > 0) { if(data_val < 2.0) gl_FragColor = texture1D(table1, idx); else if(data_val < 3.0) gl_FragColor = texture1D(table3, idx); else if(data_val < 5.0) gl_FragColor = texture1D(table4, idx); else gl_FragColor = texture1D(table2, idx); } else gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0); }
  4. I'm having a problem with mixing GLSL fragment shaders with using textures in the usual way (the standard pipeline). Function Defs in C++: void LoadGLShaderProgram() { m_frag_program = glCreateProgramObjectARB(); GLhandleARB fragment_shader; fragment_shader = glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB); glShaderSourceARB(fragment_shader, 1, &fsrc, NULL); glCompileShader(fragment_shader); glAttachObjectARB(m_frag_program, fragment_shader); glLinkProgramARB(m_frag_program); char log[5000]; int len; glGetInfoLogARB(m_frag_program, 5000, &len, log); qDebug("%s", log); m_dat1_sampler_2d_loc = GetUniLoc(m_frag_program, "data_map"); m_dat2_sampler_2d_loc = GetUniLoc(m_frag_program, "table1"); m_dat3_sampler_2d_loc = GetUniLoc(m_frag_program, "table2"); m_dat4_sampler_2d_loc = GetUniLoc(m_frag_program, "table3"); m_dat5_sampler_2d_loc = GetUniLoc(m_frag_program, "table4"); } void DrawWithShader() { glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, m_data1_txtr_ref); glUniform1i(m_dat1_sampler_2d_loc, 0); glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_1D, m_data2_txtr_ref); glUniform1i(m_dat2_sampler_2d_loc, 1); glActiveTexture(GL_TEXTURE2); glBindTexture(GL_TEXTURE_1D, m_data3_txtr_ref); glUniform1i(m_dat3_sampler_2d_loc, 2); glActiveTexture(GL_TEXTURE3); glBindTexture(GL_TEXTURE_1D, m_data4_txtr_ref); glUniform1i(m_dat4_sampler_2d_loc, 3); glActiveTexture(GL_TEXTURE4); glBindTexture(GL_TEXTURE_1D, m_data5_txtr_ref); glUniform1i(m_dat5_sampler_2d_loc, 4); glBegin(GL_QUADS); glTexCoord2f(0.0, 0.0); glVertex3f(m_view.m_upper_left.m_x, m_view.m_lower_right.m_y, 0.1f); glTexCoord2f(1.0, 0.0); glVertex3f(m_view.m_lower_right.m_x, m_view.m_lower_right.m_y, 0.1f); glTexCoord2f(1.0, 1.0); glVertex3f(m_view.m_lower_right.m_x, m_view.m_upper_left.m_y, 0.1f); glTexCoord2f(0.0, 1.0); glVertex3f(m_view.m_upper_left.m_x, m_view.m_upper_left.m_y, 0.1f); glEnd(); // end quads } void LoadTextures() { if(!m_data1_txtr_ref) { glActiveTexture(GL_TEXTURE0); glGenTextures(1, &m_data1_txtr_ref); glBindTexture(GL_TEXTURE_2D, m_data1_txtr_ref); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexImage2D(GL_TEXTURE_2D, 0, 4, m_data1_image.width(), m_data1_image.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, m_data1_image.bits()); } if(!m_data2_txtr_ref) { glActiveTexture(GL_TEXTURE1); glGenTextures(1, &m_data2_txtr_ref); glBindTexture(GL_TEXTURE_1D, m_data2_txtr_ref); glTexParameterf(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameterf(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexImage1D(GL_TEXTURE_1D, 0, 4, m_data2_image.width(), 0, GL_RGBA, GL_UNSIGNED_BYTE, m_data2_image.bits()); } if(!m_data3_txtr_ref) { glActiveTexture(GL_TEXTURE2); glGenTextures(1, &m_data3_txtr_ref); glBindTexture(GL_TEXTURE_1D, m_data3_txtr_ref); glTexParameterf(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameterf(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexImage1D(GL_TEXTURE_1D, 0, 4, m_data3_image.width(), 0, GL_RGBA, GL_UNSIGNED_BYTE, m_data3_image.bits()); } if(!m_data4_txtr_ref) { glActiveTexture(GL_TEXTURE3); glGenTextures(1, &m_data4_txtr_ref); glBindTexture(GL_TEXTURE_1D, m_data4_txtr_ref); glTexParameterf(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameterf(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexImage1D(GL_TEXTURE_1D, 0, 4, m_data4_image.width(), 0, GL_RGBA, GL_UNSIGNED_BYTE, m_data4_image.bits()); } if(!m_data5_txtr_ref) { glActiveTexture(GL_TEXTURE4); glGenTextures(1, &m_data5_txtr_ref); glBindTexture(GL_TEXTURE_1D, m_data5_txtr_ref); glTexParameterf(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameterf(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexImage1D(GL_TEXTURE_1D, 0, 4, m_data5_image.width(), 0, GL_RGBA, GL_UNSIGNED_BYTE, m_data5_image.bits()); } } And here's my drawing code using the above defined methods: void Draw() { if(!m_loaded) { LoadGLShaderProgram(); } else { glUseProgramObjectARB(m_frag_program); //Use our fragment shader LoadTextures(); DrawWithShader(); glUseProgramObjectARB(0); // Switch to standar pipeline DrawOtherStuff(); } } My problem is this: if I draw "just" my shader stuff or I just draw my DrawOtherStuff, they behave exactly as expected. But if I draw them both, I get unexpected results (graphically) with DrawOtherStuff(), but my shader code draws just fine. If I have to, I can post what's going on in DrawOtherStuff, but to not clutter my post initially, I'm first posting where I think things are going wrong (in my shader). Does anyone see something I'm bone-heading here? Thanks in advance...
  5. pseudosig

    GLSL Newbie issues

    Thanks! This got me where I needed to be.
  6. pseudosig

    GLSL Newbie issues

    Quote:Original post by fcoelho Can you actually bind two different textures to the same texture unit - even though they are bound to different targets - and access them independently in the shader program as you do? Since I'm a newbie at glsl, I'm not sure. Let me ask you this, how should one access two textures in a shader program and work on their colors values independently? I've ordered the orange book, and have been looking online for multi-texture examples, but for whatever reason, I'm not finding what I need. If you do know how to access two textures (in my case 2D and 1D), can someone maybe show a code snippet on how that should look in c++/c and in glsl? Thanks....
  7. pseudosig

    GLSL Newbie issues

    Quote:Original post by Kasya you are returning texture1D in a vec4. And gl_FragColor is also vec4. That can cause the problem. texture1D is supposed to return a vec4, which is a 4 element vector for RGBA? I guess I don't understand what the problem is with that... ?
  8. I'm trying to write a GLSL fragment shader that works on a 2D texture that represents some data in the red channel of an RGBA texture. My data has 256 possible values (hence working in a single color channel), and I bilinear smooth that data (after the smoothing, my values still remain in the red channel). I then try to do a lookup into a 1D texture (that has 256 RGB color values) that maps my smoothed data to my visual color representation of that data. Here's my sample shader: uniform sampler2D data_map; uniform sampler1D color_table; vec4 texture2D_bilinear(sampler1D lkup, sampler2D data, vec2 uv) { ivec2 dim = ivec2(1024, 1024); float textureWidth = dim.x; float textureHeight = dim.y; float texel_size_x = 1.0 / textureWidth; float texel_size_y = 1.0 / textureHeight; vec2 f; f.x = fract( uv.x * textureWidth ); f.y = fract( uv.y * textureHeight ); vec4 t00 = texture2D( data, uv + vec2( 0.0, 0.0 )); vec4 t10 = texture2D(data , uv + vec2( texel_size_x, 0.0 )); vec4 tA = mix( t00, t10, f.x); vec4 t01 = texture2D( data, uv + vec2( 0.0, texel_size_y ) ); vec4 t11 = texture2D( data, uv + vec2( texel_size_x, texel_size_y ) ); vec4 tB = mix( t01, t11, f.x ); vec4 bilinear = mix( tA, tB, f.y ); // Use the smoothed red value of bilinear // to find the appropriate RGB color stored // in my 1D texture. This is where everything goes // wrong. float idx = float(bilinear.r); return texture1D(lkup, idx); } void main (void) { gl_FragColor = texture2D_bilinear( color_table, data_map, gl_TexCoord[0].st); }; I know the bilinear smoothing works, b/c if I do a "return bilinear", instead of "return texture1D(lkup, idx)", I truly get a smoothed red texture as I expect. I think I'm just not referencing my 1D texture correctly, or something I'm completely not understanding altogether. Here's what my c++ code looks like: m_qfrag_program.bind(); glEnable(GL_TEXTURE_2D); glEnable(GL_TEXTURE_1D); glBindTexture(GL_TEXTURE_1D, m_color_lookup); glBindTexture(GL_TEXTURE_2D, m_data_texture); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glBegin(GL_QUADS); glTexCoord2f(0.0, 0.0); glVertex3f(-1.0, -1.0, 0.1f); glTexCoord2f(1.0, 0.0); glVertex3f(1.0, -1.0, 0.1f); glTexCoord2f(1.0, 1.0); glVertex3f(1.0, 1.0, 0.1f); glTexCoord2f(0.0, 1.0); glVertex3f(-1.0, 1.0, 0.1f); glEnd(); glDisable(GL_TEXTURE_2D); glDisable(GL_TEXTURE_1D); m_qfrag_program.release();
  9. I've spent some time digging and I'm not pulling what I need. Is there a general way in opengl to have multiple views of shared rendering data? What I mean is something like this. In window A, I have 3 Textures being rendered. In window B, I'm rendering only two of those textures, but with the same model data. Do I in essence have to load 5 of the six textures twice, one for each opengl rendering context? And the same for models? Can I share model's vertices across different views, but not necessarially render the same scene in each view? Thanks in advance...
  10. pseudosig

    Collision Question

    Quote:Original post by hovermonkey I'm not a license (or physics library) expert but I think here are two to start with: http://sourceforge.net/projects/opende - BSD-style license http://sourceforge.net/projects/bullet - ZLib license thanks... these look promising :)
  11. pseudosig

    Collision Question

    I've done some searching in the gamedev forums regarding collsion detection. Of the more helpful posts, their post dates were sort of old. So I thought I would just ask anyways... What are the current algorithms these days for robust collision detection? More specifically, how can one efficiently detect precise collisions between two 3D models that are composed of triangle meshes of general topology (i.e. triangle mesh that can be a donut, human face, etc)? Are there free collision libraries out there that one can include in their CLOSED c++ source code? I've found some nice collision libraries, but most are for open source only. Thanks in advance...
  12. I'm trying to write a simple wavefront obj decoder and I have come to a block. Here's a sample from my obj file: Quote: #384 vertices, 764 faces v 0.81895431 0.99238976 -0.81895431 v 0.88494427 0.96555492 -0.81914344 ... .. vt 0.26794330 0.59115951 vt 0.26829364 0.59066995 ... .. vn 0.28871099 0.91284825 -0.28871099 vn 0.45619804 0.84870605 -0.26754697 ... .. f 1/55/1 381/56/381 2/49/2 f 2/49/2 4/51/4 1/55/1 ... .. Where I'm having issue is in understanding what to do with the last two lines for rendering. Obj files define the last two lines like so: f v0/vt0/vn0 v1/vt1/vn1 v2/vt2/vn2, where v=vertext, vt=vertex texture coord, vn=vertex normal. When my arrays match in their indexes (i.e. v0=vt0=vn0, v1=vt1=vn1, v2=vt2=vn2), I can efficiently draw them like so: glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_NORMAL_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glVertexPointer(3, GL_FLOAT, 0, vertex_array); glNormalPointer(GL_FLOAT, 0, normal_array); glTexCoordPointer(2, GL_FLOAT, 0, texture_array); glDrawElements(GL_TRIANGLES, vert_and_norm_size, GL_UNSIGNED_BYTE, index_array); glDisableClientState(GL_TEXTURE_COORD_ARRAY); glDisableClientState(GL_NORMAL_ARRAY); glDisableClientState(GL_VERTEX_ARRAY); But my Object file only has the vertex array and vertex normal array matching in their indexes, and the texture coord array has different indexes: f 1/55/1 381/56/381 2/49/2 f 2/49/2 4/51/4 1/55/1 So the above code snippet won't work because "index_array"'s indexes won't match for the texture array. So my question is this: How can I best render my object when the indexes of my arrays aren't the same? Is there a methodology in opengl that I can have multiple index arrays, one for my vertex array, normal array, and texture array? Or something completely different altogether?
  13. pseudosig

    VBO's and Vertex Arrays

    Thanks... I figured it was something simple like that! That did the trick :)
  14. I'm coding an application that renders some objects with vertex buffer objects and other objects with just vertex arrays (w/out vbo's). The application renders the VBO's correctly when I only render those objects, and when I render only the objects that are vertex arrays, it renders those correctly too. It's not until I try to render both that my vertex array objects (i.e. the ones that are not vbo's) get all messed up... just lines everywhere! Are there known conflicts with these two... i.e. are they supposed to be mutually exclusive? I doubt this is the case, but I'm curious.. Here's some sample code: // Create VBO's m_index_vbo = new GLuint[m_data_height - 1]; // Register the VBOs glGenBuffersARB_(1, &m_vertex_vbo); glBindBufferARB_(GL_ARRAY_BUFFER_ARB, m_vertex_vbo); glBufferDataARB_(GL_ARRAY_BUFFER_ARB, sizeof(float) * m_vertex_cnt * 3, m_vertex_array, GL_STATIC_DRAW_ARB); // 1D texture glGenBuffersARB_(1, &m_texture_vbo); glBindBufferARB_(GL_ARRAY_BUFFER_ARB, m_texture_vbo); glBufferDataARB_(GL_ARRAY_BUFFER_ARB, sizeof(float) * m_vertex_cnt, m_texture_array, GL_STATIC_DRAW_ARB); for(int jdy = 0; jdy < m_data_height - 1; jdy++) { glGenBuffersARB_(1, &m_index_vbo[jdy]); glBindBufferARB_(GL_ELEMENT_ARRAY_BUFFER_ARB, m_index_vbo[jdy]); glBufferDataARB_(GL_ELEMENT_ARRAY_BUFFER_ARB, sizeof(GLuint) * (m_data_width + 1) * 2, m_index_array[jdy], GL_STATIC_DRAW_ARB); } m_are_vbos_registered = true; .... ... .. // Draw the VBO's glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glPushMatrix(); glCullFace(GL_FRONT); glEnable(GL_TEXTURE_1D); if(m_are_vbos_registered) { glBindBufferARB_(GL_ARRAY_BUFFER_ARB, m_vertex_vbo); glVertexPointer(3, GL_FLOAT, 0, 0); glTexParameterf( GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); glTexParameterf( GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); glTexParameterf( GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexImage1D( GL_TEXTURE_1D, 0, 3, m_qimage_texture.width(), 0, GL_RGBA, GL_UNSIGNED_BYTE, m_qimage_texture.bits() ); glBindBufferARB_(GL_ARRAY_BUFFER_ARB, m_texture_vbo); glTexCoordPointer(1, GL_FLOAT, 0, 0); for(int jdy = 0; jdy < m_data_height - 1; jdy++) { glBindBufferARB_(GL_ELEMENT_ARRAY_BUFFER_ARB, m_index_vbo[jdy]); glDrawElements(GL_TRIANGLE_STRIP, (m_data_width + 1) * 2, GL_UNSIGNED_INT, 0); } } glDisable(GL_TEXTURE_1D); glDisableClientState(GL_TEXTURE_COORD_ARRAY); glDisableClientState(GL_VERTEX_ARRAY); .... ... .. // Draw just using vertex array glEnableClientState(GL_VERTEX_ARRAY); glColor3f(1.0,0.0,0.0); for(int idx = 0; idx < m_state_vertex.size(); idx++) { glVertexPointer(3, GL_FLOAT, 0, m_state_vertex[idx]); glDrawArrays(GL_LINE_STRIP, 0, m_state_vertex_count[idx]); } glColor3f(1.0,1.0,1.0); glDisableClientState(GL_VERTEX_ARRAY);
  15. pseudosig

    Blending Question

    Thanks. One more thing then, I currently have an array of texture coordinates... (Code snip) glNormalPointer(GL_FLOAT, 0, m_surf_normals); // my triangle vertices... glVertexPointer(3, GL_FLOAT, 0,m_vert_ary); glTexCoordPointer(2, GL_FLOAT, 0, m_tex_cords); glDrawArrays(GL_TRIANGLES, 0, m_triangle_count*3); Each texture coord is applied to a triangle. How can I vary the transparency of each triangle when using gl*Pointer functions? Thanks again, pseudosig
  • 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!