Tag Info

New answers tagged

0

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 ...


7

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 really matter, and will vary based on platform and application. Firstly I assume you should reduce uploads and updates as much as you can, for example use instancing. Secondly, note that GPUs can’t transfer buffers and render at the same time, so all OpenGL commands in the command queue are processed ...


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 ...


1

You don't specify what rendering method you want to use. Standard rasterisation of a 3D mesh? Or do you have a volume representation of the model and your renderer uses that directly? If you render a volume, check this: http://http.developer.nvidia.com/GPUGems/gpugems_ch39.html especially 39.2. The effect in the picture you provide is mainly subsurface ...


1

After your glClear call you can render a full-screen quad with your texture (loaded like you would any other). You may want to disable writing to the depth buffer to avoid odd rendering issues.


0

You already got your position and your rotation, just take those values from the spaceship and create a bullet from them. If you dont want them to start in the middle of your spaceship, move them a few times in velocitys direction.


0

For first picture: We are creating projection matrix. For example, the parameters used are: Left1, Right1, Bottom1, Top1, Near1, Far1. Here, Aspect_Ratio_1A = (Right1 - Left1) / (Top1 - Bottom1); Then we are doing a view port transformation. For example, the parameters used are: Width1, Height1. (I am not mentioning shift parameters for simplicity). Here, ...



Top 50 recent answers are included