Tag Info

New answers tagged

0

Error undefined reference means that linker can't find function's definition. Probably, you should link X11 library to your program by console parameter -lX11. So, it should be g++ -std=c++11 test.cpp -o test -lglfw3 -lX11. I think you should link OpenGL library too (by -lGL).


3

Your main issue is that you need to fix your normals. If you want to calculate smooth normals correctly please check my answers here and here. Also make sure that your normals are normalized. Your second issue is your attenuation values, I often get better results with one attenuation type. So try to use one type of attenuation and try to modify its value ...


0

From the looks of it, you need to throw glDepthMask out. GL11.glEnable(GL11.GL_DEPTH_TEST); // Enable depth testing GL11.glEnable(GL11.GL_BLEND); // Enable blending GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); // Common blending formula for transparency rootObject.render(ambient); // Background GL11.glBlendFunc(GL11.GL_ONE, ...


2

That simple lighting does not know anything about other objects in scene, nor shadows they cast. It just does the lighting knowing the light position and surface normal (and eye position for specular). That's it. No occlusion info, no light refraction, no reflection, no anything, just lighting. If you need object shadows, there are separate techniques for ...


0

You could use an user-defined conversion, something like this: struct GpuVec3 { public: GpuVec3() {} GpuVec3& GpuVec3::operator=(const vec3& other) { v.x = other.x; v.y = other.y; v.z = other.z; v.w = 1.0f; return *this; } operator glm::vec3() const { return v.xyz; } private: vec4 ...


1

I think you would do to keep your GPUVec3 and your vec3 as two separate classes, not one containing the other. Here's an example: struct vec3 { float x,y,z; }; struct GPUVec3 { float x,y,z, pad; GPUVec3() { } GPUVec3( float x, float y, float z ) { } GPUVec3( const vec3 & v ) { } operator vec3 const & () const { return ...


1

Why are you moving the viewport? You should only really touch it when the screen resizes. because you move the viewport everything outside it will not be drawn. instead adjust the view matrix to move the "camera" to where the player is this allows you to have larger levels as well.


0

For the sad weary soul a decade from now who stumbles upon this question wishing for it to be answered: void main(void){ vec3 p1 = mix(tcPosition[0], tcPosition[3], gl_TessCoord.x);//may have to rearrange these numbers depending on your implementation vec3 p2 = mix(tcPosition[1], tcPosition[2], gl_TessCoord.x); vec3 pos = normalize(mix(p1, p2, ...


1

I'm not sure, but you probably should move code that sets color of light to update frame. As I understand you initialize light color only once at start of program, but it needs to be updated each frame, in accordance with this question.


2

The normals facing away from the camera are shaded black in your setup. Add more lights into the scene that are shining on parts you want lit up, or set up the lighting with a brighter minimum brightness.


1

This should be a comment but I cant make them :(. Anyhow it looks like a normals problem with your model. If you look at the bottom flower in the first picture the lighting is wrong and it looks like the light is coming from behind and above the flower instead of in front it. Try to set the color of each pixel to the value of normal to see if the normals ...


1

Tobias, If you declare your vec3 class in C++ as having 16 byte alignment, you will have the matching offset. struct vec3 { float x,y,z; } __attribute__ ((aligned(16))); However this will align it everywhere. You might want a GPUVec3 which is aligned, and has copy constructor from your general vec3 so you don't burn that extra float everywhere. I ...


0

The animation of skinned characters is usually performed using vertex shader constants. The model matrix is usually ignored, or used to define the local-to-world of the entire bone rig. Each bone is uploaded into a fixed, known constant offset. That same offset is cooked into the vertex data so that each vertex can extract the correct shader constant. In ...


-1

Sounds like an alignment or memory size issue. Perhaps with this one increased float your memory needs are being bumped up to some magic number that slows down the MAC (I don't use MACs myself) but most likely it is causing an alignment issue. Consider a C++ type structure in pseudo code: struct myStruct { char x; int y; } If this structure is ...


8

You already know what you have to do, I'll just summarize it. There are three ways to solve your problem: Go ahead and make a conditional like you're saying, either by sampling the texture or by creating a separate uniform for this purpose. As you probably know, adding branching on a shader is almost never a good idea, and much less so in the fragment ...


2

so, to rework from comments: this is Z-fighting. The math is very well explained here: http://chaosinmotion.com/blog/?p=555, and the ways to solve it here: https://www.opengl.org/wiki/Depth_Buffer_Precision, but the gist is that Z-buffer is discrete, non-linear, and depends on the ratio of farplane/nearplane. discrete: the distance between near and far ...


1

Can't speak to the exact implementation details (and if I could it would be off-topic), but here's some obvious ingredients to put together: The camera is using an orthographic projection. You can tell this because a vertical wall is exactly vertical on-screen no matter where it is — if the camera were perspective then they would be "leaning outward" from ...


4

This is a pretty late reply, but some new options have shown up recently to address this. Khronos released a reference compiler called glslangValidator that can perform syntax validation (and more) on GLSL shader files. If there are any issues with your shader, it will print them out with line number information. You can set up a custom pre build step or ...


2

This is an old question, so I'm guessing that tom37 may have moved on by now, but I think I have an answer for anyone else with the same problem. For reference, here is a view of a surface grid using a perspective camera. Now let's say that we want to render a portion of this current view, but to the entire screen. Let's render the top-left quarter of ...


0

Not that I'm aware of (you're asking if there's some sort of glsl function that would do the conversion, right?) It's a pretty simple conversion though, just three lines; here it is in pseudocode: r = sqrt(x*x+y*y+z*z); theta = atan2(y,x); phi = atan2(sqrt(x*x+y*y),z);


1

A quote from the document you pasted: 15.070 If I draw a translucent primitive and draw another primitive behind it, I expect the second primitive to show through the first, but it's not there? Is depth buffering enabled? If you're drawing a polygon that's behind another polygon, and depth test is enabled, then the new polygon will typically ...


1

First you get the uniform's location: GLint location = glGetUniformLocation(programId, "uniform name"); Once you have the location you can send the entire value of the matrix via glUniformMatrix4fv: const GLFloat matrix[] = { ...16 values of the matrix here... }; glUniformMatrix4fv(location, 1, GL_FALSE, matrix); Thus, to change a single element, ...


0

using glUniformMatrix4fv: float[16] matrix = {/*16 individual values*/}; glUniformMatrix4fv(location​, 1, GL_FALSE, matrix ​); this will overwrite all 16 values, if you want to keep the old ones you can keep them yourself or query them with glGetUniform


2

One way of doing this is to when you are loading the model and creating the vertex layout. you could calculate a second set of normals. which would be the flat normals. Do so by taking the connecting triangles. and then put it into all the vertices. if there is more than one connecting pollygon, you could insert some indexing to make it easier to handle ...


3

You need two different models, because flat-shaded and smooth-shaded models normals are different. One of the ways is to generate 2 separate models and replace them with one another on demand. Another way is to make a single model prepared for flat shaded render (all vertices unique) and replace only normals when switching to flat/smooth shading. For ...


1

When rendering to the screen you can simply not include the geometry to make the walls thick.


2

This is a complex question with a lot of small details that really matter, the performance will vary based on platform and application. So you should profile for possible bottlenecks before investing in optimizations. That said, firstly, I assume you should reduce uploads and updates as much as you can, for example use instancing. Secondly, note that GPUs ...


0

Thanks to Lennart Rolland, I found out that the third-party font library I was using (QFont) had a bug in the way it manages its matricies. By moving my quad around in the drawing code, I was able to see where it got mangled. Thanks again for the help!


0

It is unclear exactly what is or is not happening but I am guessing that no texture shows up. First off, you should enable GL_TEXTURE_2D before actually using functions related to 2D textures. Next off, you can replace a lot of your loading with SOIL_load_OGL_texture. You also load it as a RGB texture but then proceed to use it as if were a RGBA texture ...


0

After open gl 3.2 you have to create vertex and fragment shaders. In your code example is see glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, image); uses GL_RGBA and SOIL is loaded using SOIL_LOAD_RGB. One is using alpha the other isn't.


1

I second instancing. For the sake of extra information: Converting quads to world-space on the CPU. If you can support it, you could also offload that work to the GPU through a geometry-shader. A couple arrays, 1 for the vertices of each quad, 2 for the transform marix of each quad, and then compute the world coordinates based on that (or some similar ...


1

You definitely want to use instancing. Your quads are instances: constant data (e.g. 4 vertices, bound texture) but with a few different parameters (e.g. world space matrix). Your world space matrices will be the instance data: one for each instance. It's a quite elegant and standard solution. You can have all sorts of data as instance data, in the above ...


0

It is very likely that your bmp loader does not load the alpha channel and fills it with a default value, as BMP with alpha channel is non-standard. Try using a .png file instead. From wikipedia: "An integrated alpha channel has been introduced with the undocumented BITMAPV3INFOHEADER and with the documented BITMAPV4HEADER (since Windows 95) and is used ...


0

Well, this is awkward. I overlooked the fact that the Teapot model has FAR more vertices than 255 (the size of GLubyte). I changed my call to glDrawElements and my indices_ vector to use unsigned integers, problem solved!


0

You have to define that function pointer yourself. It doesn't exist in the OpenGL implementation that ships with Windows and this is why you have a problem on that line labeled // Not recognised. At the very least, you need something to the effect: PFNWGLCREATECONTEXXTATTRIBSARBPROC wglCreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC) ...


0

Alright, so I ended up cutting the image in half down the center and just loading two images, and then I used four triangles. This may not be the most elegant solution, but it works just fine. I'm guessing it had to do with the dimensions of the image. (I also changed the parameters for the texture coordinates and all the vertices so that it is more straight ...


0

glUniform*() only affects the currently bound program. Therefore one must call glUseProgram() before making any calls to glUniform*().


0

I've found that you get better results if you use images where the height/width are powers of 2. ie. 16, 32, 1024 etc. Maybe take a look at the Texture class documentation and see if it specifies anything about that. It may be doing it's best to buffer the data but it gets garbled because of the dimensions. Also, somewhat less importantly, glBegin and ...


0

You can render piglet.text.label into a frame buffer object, but you will need to manage the FBO and rendering the label into it yourself. Pyglet does not provide primitives for manipulating and rendering to FBOs. However, assuming that you are considering this for performance reasons, I would generally advise that you use batching instead. Pyglet includes ...


0

For starters, try replacing "x-width" with "x" and "y-height" with "y". Also, in order to debug it better, try and render only one triangle at a time.


0

this looks suspect: indicesList.add((byte)(i+j)); I'd expect the index to be something like: indicesList.add((byte)(size*i+j)); but if size*size>255 then you need to upgrade the indicesList to contain a short or int, otherwise they just won't fit.


0

The documentation explicitly says that the sizes you provide to GLUT are hints to the windowing system. The actual size of the window has to be determined either via the reshape callback or by querying for the actual client area size, if available. Your orthographic projection is thus probably not 1:1 mapping to pixels.


1

Typically, the MVP matrix (along with any other matrices you might be using) are specified using uniforms, for example: #version 330 in vec3 iPosition; // input from vertex attribute out vec3 vPosition; // output to fragment shader // other inputs/outputs for colors, texture coordinates, etc. as needed uniform mat4 uMVP; void main() { vPosition = ...


2

You have this code: GL.BufferData(BufferTarget.ArrayBuffer, new IntPtr(vertices.Length), vertices, BufferUsageHint.StaticDraw); This tells OpenGL to only upload as many bytes as there are elements in the array. That's why you see only small portion of the data on screen. You need to tell OpenGL how many bytes you actually want to buffer. ...


6

You're not missing anything. The normal matrix exists in case the upper-left 3x3 of your regular model-view transformation is unsuitable for transforming normals (that is, contains non-uniform scale or other craziness). If you know the upper-left 3x3 is always suitable for use in the transformation of normals, there's no reason to bother with a separate ...


0

As pointed out by @UnholySheep, I was linking the normal PhysX libraries, but the CHECKED versions of them must be linked for the PhysX Visual Debugger to work, and all the "error" messages that show up are perfectly normal when the PVD can't connect, which was the case.


7

You need to translate them before scaling them. Otherwise, the entire coordinate space is scaled. For example: // Scale the coordinate space by two. Matrix4f.scale( 2, 2, 2 ); // Now because of the scale this is the same as translating by 2 in every axis. Matrix4f.translate( 1, 1, 1 ); // Actually means Matrix4f.translate( 2, 2, 2 ) here. When you ...


3

Assuming that location is the uniform location you've already retrieved from the shader, and vec is your vector, then in C++11 you can do: glUniform3fv(location, vec.size(), reinterpret_cast<GLfloat *>(vec.data())); Prior to C++11: glUniform3fv(location, vec.size(), reinterpret_cast<GLfloat *>(&vec[0])); The "old" method will work in ...


0

Assuming your Vector3f class is laid out linear in memory. std::vector<Vector3f> m_verts; float* address = &m_verts[0].x; This will get the address of the x value of the first element, so long as your data is laid out linearly, and your sizeof(Vector3f) == size(float) * 3 you should be fine.


8

Your interviewer was talking, with his own words, about bindless API. nVidia made nice presentations recently about all that, which they call direct state access (1, 2). This does not replace VBOs. EDIT: Actually, let's consider Trevor Powell's suggestion: This seems like some people could definitely decide to drop VBOs, in favor of attribute-less ...



Top 50 recent answers are included