How to get an uniform location of a Cg shader with OpenGL?

I've dabbled with basic shader programming before, using the GLSL way. Now I've come back to it, using Cg shaders. Following the tutorial at Josh Beam's website I've achieved the desired functionality, was able to change my shader around, however I couldn't manipulate the uniforms in it on the OpenGL side.GLuint handle;::glGenProgramsARB(1, &handle);::glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, handle);::glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, strlen(pSource), pSource);while(true){ ::glEnable(GL_FRAGMENT_PROG...Read more

point rendering in openGL and GLSL

Question: How do I render points in openGL using GLSL?Info: a while back I made a gravity simulation in python and used blender to do the rendering. It looked something like this. As an exercise I'm porting it over to openGL and openCL. I actually already have it working in openCL, I think. It wasn't until i spent a fair bit of time working in openCL that I realized that it is hard to know if this is right without being able to see the result. So I started playing around with openGL. I followed the openGL GLSL tutorial on wikibooks, very inform...Read more

OpenGL - draw pixels to screen?

I want to draw a 2D array of pixel data (RGB / grayscale values) on the screen as fast as possible, using OpenGL. The pixel data changes frequently.I had hoped that I would find a simple function that would let me push in a pointer to an array representing the pixel data, since this is probably the fastest approach. Unfortunately, I have found no such function.What is the best way to accomplish this task?...Read more

glsl - using cl-opengl with shaders

I tried to convert code from this modern opengl tutorial into cl, but if I start my program, a new window without something in it is opened, and I have to restart the whole window-manager, so it is difficult to debug.my code (using sdl2 instead of glut):(defun to-gl-array (seq type &aux (length (length seq)) (array (gl:alloc-gl-array type length))) (dotimes (i length) (setf (gl:glaref array i) (aref seq i))))(defvar *vs* (gl:create-shader :vertex-shader))(defvar *vs-source* "...Read more

OpenGL transparency of black background

I'm working with sprite animation (OpenGL + C++).I have some trouble working with blending.I'm trying to load an image with a black background and draw it over another texture without a block of black appearing around the image. The image has Alpha channel and blending is enabled.I tried playing with different blending functions. I either end up with a blocky image or a translucent image.I know I can do it if I replace the black background with a transparent color instead using an image editing software, but I would like to get this working wit...Read more

Coordinates in openGL

I am having trouble finding the right coordinates in openGL.For e.g.: - If the h and w are height and width of the window, then I want to draw a line of length w/2 at a distance h/4 from bottom. How would I do this in openGL?I don't find any references telling the maximum and minimum values of coordinates. My computer screen is 1024*768 so technically the limit should be:-x coordinate: -512 to 512y coordinate: -384 to 384z coordinate: -inf to 0But this doesn't work. Why? I need to know how coordinate system is working for openGL....Read more

opengl - How do I compose a rotation matrix with human readable angles from scratch?

The one thing that has always hindered me from doing 3D programming is failing to understand how math works. I can go along with math fine in programming flow using methods and functions, then its all clear and logical to me, but in mathematical notation, I just can't make heads or tails from it.I have been reading websites, a watching videos of institutes trying to explain this, but they all use mathematical notation and I simply get lost in it, my mind won't translate it to something understandable. I might have a defect there.Also, Just usin...Read more

glsl - How to render depth linearly in modern OpenGL with gl_FragCoord.z in fragment shader?

I read lots of information about getting depth with fragment shader.such ashttp://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=234519but I still don't know whether or not the gl_FragCoord.z is linear. GLSL specification said its range is [0,1] in screen sapce without mentioning it's linear or not.I think linearity it is vital since I will use the rendered model to match depth map from Kinect.Then if it is not linear, how to linearlize it in the world space?...Read more

gpu - How does OpenGL work at the lowest level?

I understand how to write OpenGL/DirectX programs, and I know the maths and the conceptual stuff behind it, but I'm curious how the GPU-CPU communication works on a low level.Say I've got an OpenGL program written in C that displays a triangle and rotates the camera by 45 degrees. When I compile this program, will it be turned into a series of ioctl-calls, and the gpu driver then sends the appropriate commands to the gpu, where all the logic of rotating the triangle and setting the appropriate pixels in the appropriate color is wired in? Or wil...Read more

opengl - Rotating a Group of Vectors

I am trying to rotate a group of vectors I sampled to the normal of a triangleIf this was correct, the randomly sampled hemisphere would line up with the triangle.Currently I generate it on the Z-axis and am attempting to rotate all the samples to the normal of the triangle. but it seems to be "just off"glm::quat getQuat(glm::vec3 v1, glm::vec3 v2){ glm::quat myQuat; float dot = glm::dot(v1, v2); if (dot != 1) { glm::vec3 aa = glm::normalize(glm::cross(v1, v2)); float w = sqrt(glm::length(v1)*glm::length(v1) * glm::len...Read more

opengl - Normal mapping gone horribly wrong

I tried to implement normal mapping in my opengl application but I can't get it to work.This is the diffuse map (which I add a brown color to) and this is the normal map.In order to get the tangent and bitangent (in other places called binormals?) vectors, I run this function for every triangle in my mesh:void getTangent(const glm::vec3 &v0, const glm::vec3 &v1, const glm::vec3 &v2,const glm::vec2 &uv0, const glm::vec2 &uv1, const glm::vec2 &uv2,std::vector<glm::vec3> &vTangents, std::vector<glm::vec3> &a...Read more

What is state-of-the-art for text rendering in OpenGL as of version 4.1?

There are already a number of questions about text rendering in OpenGL, such as:How to do OpenGL live text-rendering for a GUI?But mostly what is discussed is rendering textured quads using the fixed-function pipeline. Surely shaders must make a better way.I'm not really concerned about internationalization, most of my strings will be plot tick labels (date and time or purely numeric). But the plots will be re-rendered at the screen refresh rate and there could be quite a bit of text (not more than a few thousand glyphs on-screen, but enough ...Read more