amtriMember
Content count124
Joined
Last visited
Community Reputation189 Neutral
About amtri
- RankMember
OpenGL Compiling and running on different OpenGL versions
amtri replied to amtri's topic in Graphics and GPU ProgrammingHi cgrant, I think my confusion right now is just one question: regardless how the code was compiled and on what platform, and with what version of OpenGL, is GL_VERSION (major and minor) obtained at runtime reliable ways (at runtime!) do bracket the source with "if" statements to skip over code that compiled properly but should not be called because the runtime version of opengl does not support it? In other words, if my running machine only supports GL 1.1, can I reliably count on the fact that glGetString(GL_VERSION) will tell me that the runtime version is 1.1 and that I should skip some code that uses functionality in GL > 1.1? I'm just hoping that glGetString(GL_VERSION) has no relation to the version used for compiling the code. Thanks.
OpenGL Compiling and running on different OpenGL versions
amtri replied to amtri's topic in Graphics and GPU ProgrammingThanks to all for the responses. So basically this is what I'm planning on doing: 1) When compiling I'll use #ifdef GL_VERSION_X_Y to make sure the compilation works properly. 2) When running it, let's say that glGetString(GL_VERSION) is supported. I understand that GLEW may have a bug in this function; but if I have a reliable way of parsing this string to get the major and minor version numbers, then these will be the ones available at runtime. Let's say I define an integer iversion = 10*major + minor. Then I can use #ifdef GL_VERSION_3_1 if(iversion >= 31) { /* my happy OpenGL 3.1 code here */ } #endif Of course, this is all predicated on two facts: (1) I can construct iversion reliably; and (2) iversion created at runtime by extracting the version through gl calls will give me the supported runtime version of gl - regardless of how it was compiled. Am I correct?
OpenGL Compiling and running on different OpenGL versions
amtri replied to amtri's topic in Graphics and GPU ProgrammingOsbios, Messy all right... Following the link that Waterlimon posted I learned that glGetString(GL_VERSION) is deprecated and has been removed in 3.1. So in order to find out the version I'm using at runtime I need to first know the version (!) so I know which function to call. I can certainly use #ifdef GL_VERSION_3_1 to decide which function to call depending on the compiler being used. But then I need to retrieve the runtime version to decide what to do. For the moment we use no extensions, only the #ifdef GL_VERSION_X_Y at compile time, and glGetString(GL_VERSION) at runtime. I'm sure in the near future this will need to change...
OpenGL Compiling and running on different OpenGL versions
amtri replied to amtri's topic in Graphics and GPU ProgrammingHi mhagain, Thanks. Unfortunately, what we distribute is a library that gets embedded into an end-user application that may go to thousands of end users. And I have no control over what end users are still using (you'd be surprised!). So I have to assume the worst - even if that means people may still be at GL 1 (ok... maybe not that far back). But my source is full of #ifdef GL_VERSION_X_Y so that the end-user application can be compiled regardless of the version of GL they choose to use, and their end users can run it also regardless of what they have on their machine.
OpenGL Compiling and running on different OpenGL versions
amtri replied to amtri's topic in Graphics and GPU ProgrammingOne more thing - although I'm not sure this is the place for the question: I'm using GLEW on Windows, and include the GLEW DLL with the distribution. Suppose I build with the latest version of GLEW then I try to run on a machine that is so old that the graphics card is unable to support the version I include in my distribution. Would glewInit() fail? Or - because the DLL is from the latest version of GLEW - could I see that glGetString returns a version I believe would work (because it is my GLEW DLL they are using), but the call could still fail? In other words, I'm trying to protect myself from a crash. I have no problem reporting that a feature is not supported, but I cannot have the application crash. If glewInit() fails that's no problem because I will report this as an error. Thanks again.
OpenGL Compiling and running on different OpenGL versions
amtri replied to amtri's topic in Graphics and GPU ProgrammingHi Waterlimon, Thanks! Very clear. So, if I understand this correctly, I can build my application on, say, OpenGL 4.2. Then, at runtime, use glGetString (GL_VERSION), parse the string to determine the version, and avoid calling functions that probably won't be available. For example, #ifdef GL_VERSION_4_2 /* use 4.2 functionality here */ if(parsedversion(glGetString(GL_VERSION)) >= 42) { /* use the functionality here */ } #endif where "parsedversion" is some simple function that just parses the string with the version and generates an equivalent integer I can use for comparison purposes. Of course, I could have a "} else {" statement for a fall back approach to the functionality in case 42 is not available on the running machine. But, at this point, all I want is to make sure it won't crash. If everything is about call a function with a null pointer, then the above code should prevent the crash. Correct? Thanks!
OpenGL Compiling and running on different OpenGL versions
amtri posted a topic in Graphics and GPU ProgrammingHello, I'm trying to understand a basic principle on how OpenGL works when the compilation/linking is done with one version of OpenGL, but the program actually runs on a different version. I understand that if the runtime version of OpenGL is greater than the one it was built in this is not a problem: OpenGL is backward compatible so the program will run on a machine where a newer version of OpenGL is installed. My problem is the other way around. My program is heavily dependent on advanced shader technology. So I have function calls such as glUniform... throughout the code. So let's assume I built my program on a machine with the latest version of OpenGL. Now I'm going to take it to a machine running an older version. Quite possibly, a function such as glUniform... is not even present there. Given that nobody distributes software with OpenGL - either DLLs on Windows or shared libraries on Linux - will my program simply crash if I run it on a machine with an older version of OpenGL? I'm used to building applications that rely on other libraries - but their shared libraries are usually shipped along with the application. But I don't think OpenGL follows this practice: people usually have OpenGL on their machines and use their own version. Can somebody explain to me how this works in the general case? For example, can I just query OpenGL at runtime for the version number and simply skip calls that rely on newer versions? Will the application even load properly? Thanks.
- Stainless, Isn't CUDA specific to NVIDIA graphics? Or am I missing something here? I'm supposed to assume that the only library I have is the original h264 library. Having to rely on CUDA would restrict usage to those using NVIDA graphics. Am I correct?
- Thanks fastcall22! I'll take a look at that thread. Much appreciated!
How to encode h264 video
amtri posted a topic in Graphics and GPU ProgrammingHello, I have been asked to take a series of images defined as simple bitmaps and encode them into a h264 file. I did manage to download and build the h264 libraries, but I'm having a tough time sorting through the documentation or examples to come up with a simple way of doing this through their API (I am required to use the h264 API directly). Can somebody point me to some simple examples on how to do this? Thanks.
- Yet another update: I changed the texture type to GL_TEXTURE_RECTANGLE. This way I can directly use gl_FragCoord.xy when passing data to the textures. I'm using the defaults, so I assume gl_FragCoord.xy will have values like 0.5, 1.5, 2.5, etc. I store all my display data on display lists. I draw my display list once and save the color and depth buffer by create a frame buffer with GL_TEXTURE_RECTANGLE textures for both - one color, and one depth. The filters on both textures are set to GL_NEAREST. I query the depth texture using float depth = texture (depthtex,gl_FragCoord.xy).r; My expectation is that this call should always find the exact same texel in my texture; so it writes the color and depth on one pass and reads with the exact same coordinates on the next path. But, unfortunately, this is not the case. I "solved" my problem by using a tolerance such as if(depth >= gl_FragCoord.z - 0.00001) discard; on the second time I draw. The image looks perfect - pointing to the fact that this was indeed my problem. But 1) Why do I not get the exact same values on the second pass as the first pass, or... why does my comparison fails at times?\ 2) Can I get better results by using different texture parameters? Thanks.
- After some more reading I suspect my problem has to do with the fact that I created a 2D texture to store the depth and then I'm comparing the depth value from a previous pass (stored in the texture) with gl_FragCoord.z. But in order to retrieve the previous value I need to pass to texture2D the texture coordinates between 0 and 1, and this rounding-off depending on screen size may just be returning to me the incorrect pixel. And with depth values probably extremely close to each other the comparison is failing, thus giving me the bad image I'm seeing. This is all speculation, but if I'm right now I have more concrete questions that I'm hoping somebody can help me with: 1) Is there a way to query a sampler2D in the fragment shader given the center pixel location values - gl_FragCoord.xy? Of course, these will not go from 0 to 1, but from 0 to width and 0 to height. Given that gl_FragCoord will have values such as (1.5,3.5), I can easily pick the exact pixel. But if I need to map gl_FragCoord to texture coordinates between 0 and 1 I'm bound to run into this round-off issue. 2) My depth peeling algorithm requires multiple passes through my display list. This means that, at the same time, I need to both retrieve the depth and save it on another texture on pass, AND I need to accurately compare the depth to gl_FragCoord.z. I am using only sampler2D. Maybe I should be using sampler2DShadow instead to store my depth value. But from what I understand, querying the sampler2D using texture coordinates I get the floating point depth back; and querying a sampler2DShadow with a vec3 value returns only 0 or 1, depending on the result of the comparison. What exactly should I be using in my fragment shader so I can both compare and store the depth value accurately? 3) Depending on the answer to the question above, what parameters should I be setting in the depth texture on the client side? Thanks.
Depth peeling and z-clipping
amtri posted a topic in Graphics and GPU ProgrammingHello, I have a shader where I create several frame buffers and perform N passes through my display list. In the first pass I simply store the image and depth; in the second and all subsequent passes in the fragment shader I compare the current depth with the previously saved one and discard if it's in front of it. Then I blend all images in a final post-processing phase at swap time. This all works fine, except for when there's z-clipping going on. I saved both the color and depth textures associated with each frame buffer and save all of them to a bmp file so I can see what's going on. I have just a few intersecting cones being displayed. In the area where z-clipping occurs both the depth and the color textures seem to have garbage defined on them. I'm wondering whether there's something I'm not aware of regarding the data coming in. For example, I assume that gl_FragCoord.z is always between 0 and 1, and anything that's being clipped won't even go through the fragment shader. Is this the case? Or is z-clipping done after the fragment shader? In this case, should I expect gl_FragCoord.z < 0 or > 1 to be allowed? I'm attaching the saved color texture. The solid colors are what I expect to see. The fuzzy area is exactly where the z-clipping plane is passing through. Any thoughts? Thanks.
clipping plane with shader
amtri posted a topic in Graphics and GPU ProgrammingHello, I have clipping planes working in my shader using gl_ClipDistance. I pass the equation of every clipping plane to my vertex shader and compute the dot product with my untransformed coordinates. It works fine. Now I ran into a machine where the call glGetString (GL_SHADING_LANGUAGE_VERSION) returns 130. Yet, gl_ClipDistance is an undefined variable. This brings up my first question: 1) Shouldn't gl_ClipDistance always be defined for GLSL version 130? I'm using a Linux 64-bit machine with glew 1.10.0. But I want to get this working, so I decided to alternatively use gl_ClipVertex instead on that machine. The problem is I'm getting no image - kind of like everything is always being clipped out. Given that my glClipPlane is setting the plane equation in untransformed coordinates (i.e., same as gl_Vertex), I'm simply setting gl_ClipVertex = gl_Vertex. In my gl_ClipDistance implementation I'm taking the dot product of gl_Vertex with the 4 numbers that define the equation in glClipPlane. It works fine. But somehow I think my clipping plane equations are not being properly passed down. I even tried setting "#version 120" in the shader, but with no effect. Can anybody shed some light onto this? Thanks.
z-buffer discontinuity in shaders
amtri replied to amtri's topic in Graphics and GPU ProgrammingOne more piece of information: I am drawing the 1D texture first, then the 2D texture. If I reverse the order, then my 2D texture works fine, but my 1D texture does not. And I know for a fact that my uniform flag indicating which texture I'm using is being passed down correctly, and it is using sampler1D for the 1D texture and sampler2D for the 2D texture. But, for some reason, after the first texture is drawn - either 1D or 2D - the second one in the same unit is not drawn. Not clear why this is the case...