New answers tagged

19

There are two main benefits: First, if you downsample by more than a factor of two, some pixels in the original image will have no impact on the result image. Using GL_LINEAR, each destination pixel will only sample from at most 4 pixels from the source image; the other pixels simply get discarded. By downsampling by a factor of two, you ensure that each ...


1

It seems each time you call getHeight(x,z) you get different results, regardless of whether the (x,z) is the same or not, so the generated normals don't match the terrain surface. Normals will match the actual terrain if you compute them from the generated terrain, and not from what getHeight returns. However, it makes sense to also fix getHeight so it ...


-1

try using something >= your near (i.e. >= 0.1) for your window_z instead of 0? glm::vec3 wincoord = glm::vec3(mx, 480 - my, /**/0.1f/**/);


1

The screen coords go from {-1,-1} to {1,1} but you are most likely feeding it {0,0} to {1,1} - hence the fact that only one-quarter of the screen gets rendered. So just to be clear - point {0,0} is not the top-left (or bottom-left, depending on your co-ordinate system) point; it's the center. This also explains the texture coord tranformation that you are ...


2

I don't know cocos2d, but the general approach to use for this effect is simply to just render the scene at a lower resolution into an offscreen render buffer (VBO, in OpenGL terminology), and then copy that low-resolution image to the screen, with smoothing turned off. (in OpenGL terms, that'd be performing the copy using GL_NEAREST instead of GL_LINEAR). ...


0

In glsl, the texture function returns a vec4, thus you provide too much arguments to the vec4. It should be color = texture(sampler, texCoord); To avoid issues like this, always print out what glGetError returns. Second problem: Guess what GL.ShaderSource takes in as arguments. A shader, and you provided a shader program to it.


-2

Line 5 and 6 of LoadShaderProgram() contain a copy/paste error. GL.ShaderSource(program, VSSource); GL.ShaderSource(program, FSSource); Should be instead: GL.ShaderSource(vshader, VSSource); GL.ShaderSource(fashader, FSSource);


0

The answer turns out to be rather easy, altho lengthy, Instead of cleaning up faces (now called points) and preparing the list for gldrawarrays, I instead create a new list of unique faces/points as a base reference: Ill just post the entire function: void objload4(string filename, vector<glm::vec3>&vertices, vector<glm::vec2>&texcords, ...


4

It's important to note that glxinfo -v only reports the supported values for the default OpenGL framebuffer, the one that represents the visible screen itself. It's common for other configurations (ones not reported by glxinfo) to be supported in offscreen framebuffer objects (FBOs). As you've noticed, most video cards do not support a 32-bit depth buffer ...


4

There are a number things that could cause these problems. Here are some things to try: Bad vertex coordinates. One way to debug it is to print your coords to the console and check for things like NaN, Inf, etc. But it could also be that you're just uploading some wrong, but not obviously bad coordinates. One way to debug this is to bisect your data. Send ...


2

No. The size of the array has to be a constant. Specifically from the GLSL specification: 4.1.9 Arrays ... When an array size is specified in a declaration, it must be an integral constant expression (see Section 4.3.3 “Constant Expressions” ) greater than zero.


0

The problem is your multiplication code. When you do: m00 = m00 * matrix.m00 + m10 * matrix.m01 + m20 * matrix.m02 + m30 * matrix.m03; You change m00, so you are not allowed to reuse it later in that function. Same for m01 and all the other ones. Use temporary values instead: float temp_m00 = m00 * matrix.m00 + m10 * matrix.m01 + m20 * matrix.m02 + m30 * ...


0

Your z rotation is messed up, it should be negative at (0; 1), and positive at (1; 0)


2

I have solved this exact problem for my master's thesis over a year ago and have already talked about it here. Yesterday, I released an open source program with my multi-channel distance field construction algorithm, msdfgen, which you can try out right now. It is available on GitHub: https://github.com/Chlumsky/msdfgen If you are interested in how it ...


3

The first issue is that you are re-creating and destroying the buffers, reloading the texture, and recompiling the shader on every single draw loop. This is the source of the huge CPU usage. As for the memory going up, there could be a memory leak in the scripting language you are using. Not recreating everything on every loop will probably reduce the ...


0

In my own project I suddenly came to the same conclusion - the parent scale shouldn't be passed down to the children's transformation matrix. And I thought it was weird too. I figured, if you want to stay consistent throughout your code, either you pass through all of it, or you pass through nothing. However, seeing how you came to the same conclusion is ...


4

OpenGL already handles the division by W part, you don't need to do anything about that. So, this is what a perspective projection matrix should look like: FOV is the vertical angle of the frustum. Near and far are the distance from the camera to the cutting planes. Nothing gets rendered beyond those. Make sure fo set the near plane to a small value, ...


1

Your whole matrix is incorrect. For example, this is one of the ways it should look like: So, in code: dest.m00 = 1.0f / (tanHalfFOV * aspectRatio); dest.m10 = 0; dest.m20 = 0; dest.m30 = 0; dest.m01 = 0; dest.m11 = 1.0f / tanHalfFOV; dest.m21 = 0; dest.m31 = 0; dest.m02 = 0; dest.m12 = 0; dest.m22 = -(far + near) / range; dest.m32 = -2 * far * near / ...


1

http://www.songho.ca/opengl/gl_projectionmatrix.html Note the perspective projection matrix is a transform like any other. The difference compared to orthogonal matrix is that the xy-displacement is dependent on the z coordinate. If you figure out what a perspective is and have a good idea about what shearing transforms do perspective projection matrices ...


3

There are two common ways to animate something. One of them is what you described: morphs or per-vertex animation. You have number of different models representing each frame in your animation, and you interpolate the position of the vertices individually between the previous frame and the next to achieve smooth animation. This technique is usually applied ...


0

figured out what the problem was I was using glUseProgram after I was doing uniforms instead of doing that before.


1

To do that you simply call glDisable(GL_DEPTH_TEST); before drawing your GUI and after drawing your scene/screen. That way, you draw your GUI on top of the scene and is unaffected by depth test. For the shader, i think a basic shader will do. I hope i remember it correctly.


1

You get invalid operation, because you don't use the uniform "projection" in the shader, thus OpenGL deletes it to save memory. This can be solved by simply referencing it with projection;, you don't need to use it. Like this: #version 330 core layout (location = 0) in vec3 position; uniform mat4 modelviewMatrix; uniform mat4 projection; void main() ...


3

Yes and no. Yes, generally: the convolution operation is usually very computationally heavy and if you are sampling 7x7 area, that is 49 times more samples than you would usually do. No, in your case: One important thing about FPS is that it is inverse of a function. Because with 5000 FPS the time to render a frame is 0.20 ms and with 1500 FPS it is 0.66 ...


1

Maybe you mean glUseProgram()? I can't find something related to glUseShader, so if i'm wrong then sorry. But if this is the case then basically you use it when you want to use the shader itself. This is an example from my current opengl project (EDIT: Oh, by the way, this example code is on the main rendering loop): GL30.glBindVertexArray(vao); // Binding ...


1

To render a cross-hair, all you would need to do is render a piece of geometry using just a screen-space transformation, followed by the projection matrix. Mapping the identity matrix as your view will do this for you. A view matrix allows us to transform vertices into view space; removing this step allows us to go directly from model-space to screen-space. ...


0

Looks like that by luck I found the solution to the problem. I really don't like the glm documentation, was my understanding that glm doc was intentionally skinny since it matches corresponding glsl and glut. Anyway documentation is a mess. doc v 0.92 doesnt specify what unit to use, the gluPerspective uses degree, so that's why I used degrees. doc v0.94 ...


1

Windows: Imho, one should completely avoid fullscreen mode. There is no longer any performance advantage with it, those days are gone. If you want to cover the entire screen, just create a borderless and captionless window with fullscreen dimensions. This gives you advantages: Only one set of code: If going directly fullscreen at program start, one ...


3

I would implement a model matrix as suggested in the comments. Calculate the new position, (x1 y1): Vector2f newPosition = interpolatePosition(oldPosition); Then apply that as a translation to the model matrix: Matrix4f modelMatrix = new Matrix4f().translate(newPosition); Then pass the model matrix into the shader as a uniform: GLuint matrixUniform = ...


0

I don't know if you solved the problem, but since I am working with SH I can tell you that the best way to project a cubemap so far is that of Peter Pyke Sloan. Here his paper on SH, he basically sums each contribute from each pixel weighted by some value obtained from its uv (st in opengl) coordinates. And then all coefficients are normalized by a value ...


1

When 2 objects share the same z coordjnate and are painted over one another, you get an effect called z fighting (I once heard it being called z achne), parts of each model gets visible, but they generate a strange texture. This eventually happens less closer to the eye, because the depth buffer keeps a longer range of bits for them than the parts far back. ...


4

void glShaderSource(GLuint shader, GLsizei count, const GLchar **string, const GLint *length); Okay, I guess you didn't understand what these values mean. string is an "array"(pointer is more correct since a pointer is not an array) of "char const*" (I advice you to put all your code in one and only one char const *. length is an "array" of ...


0

The 5th "stride" argument in all of your 4 glVertexAttribPointer calls is specified as 3 * sizeof(GLfloat), while in your case it should be 0, as you are using separate buffers per vertex attribute (see https://www.opengl.org/sdk/docs/man/html/glVertexAttribPointer.xhtml). That argument is non-zero for cases when you interleave those attributes in a single ...


0

opengl-tutorial has: a tutorial http://www.opengl-tutorial.org/intermediate-tutorials/billboards-particles/billboards/ focused on energy bars OpenGL 3.3+ WTF licensed code that just works: https://github.com/opengl-tutorials/ogl/blob/71cad106cefef671907ba7791b28b19fa2cc034d/tutorial18_billboards_and_particles/tutorial18_billboards.cpp Screenshot: ...


1

I found solution: glEnableClientState(GL_NORMAL_ARRAY); glNormalPointer(GL_FLOAT, 0, normalsArr); above code tells OpenGL to consider normals


0

They're usually just big planes cknsisting of smaller planes, and each vertex has a separate heoght attached to them. For heights, people usually use heighmaps or pseudo random noise generation using Perlin or Simplex noise. Some other games only use a small amount of pre-generated terrain, then scale it up to the size of the whole terrain, and lastly put ...


0

Your bullet list reads increasingly more efficient as you go. This should probably be taken as a hint on how to realistically get this done. The last thing you really want to be doing is modifying vertex data in the middle of a frame, you will stall the render pipeline if you do not have enough unfinished frames queued up by the driver already. Having all ...


4

Is it ok to use OpenGL 2.1 or should I use OpenGL 3.3+ Unless you need your game to run on something eight to ten years old, use at least OpenGL 3.1. The main reason is that fixed-function APIs are just that; fixed. You can use the rendering functionality that they provide, and no more. Also, mobile devices don't support fixed-function OpenGL, so ...


6

Use OpenGL 3.0 to 3.2, 3.3 and above isn't supported by some machines. You seem to be mixing OpenGL 2.1 with immediate mode. There are better ways to draw in OpenGL 2.x than immediate mode (e.g. VBOs) Your questions: You should definitely use OpenGL 3.3 if you can choose. No, but shaders can do it more effectively (in most cases) We can't recommend ...


1

I found a paper from Epic Games on how they do their area lights - relevant info starting on page 16. Essentially, you find the shortest distance to the line segment that defines your light source, and use that as the source of a light - in their case, a point light, but you could easily use your spotlight instead. They also use a calculation for the ...


7

I would guess that they've scaled and shifted their outputs into the range from 0f to 1f (0-255) for the purpose of that greyscale height visualisation. They probably omitted that adjustment from the formula because it's not critical to the shape they're describing with the normal map. Try multiplying the result by something in the neighbourhood of 0.5f ...


-1

http://www.geforce.com/hardware/desktop-gpus/geforce-gtx-670/specifications Nvidia homepage says only 4.2 is supported. Check the error logs and for any other opengl error and fix them if any.


1

Main Question: Is there a specific way of setting up and rendering OpenGL for NVIDIA Graphics so that it renders properly, and not a black screen? NVIDIA graphics cards are no different from any other cards seen from an OpenGL perspective. Different behavior on different platforms may exist as a result of: - Different capabilities. Some cards may ...


0

OpenGL does not allow for indexing position, uv and normals separately. There can be only one index buffer. Your best bet is to allow redundant position data. Some reuse by using indexing may be possible (and yield better quality) where faces share an averaged normal and uv.


0

I believe your problem can be solved by simply creating a Vertex Array Object for OpenGL to utilize before you create your Vertex Buffer Object. You're required to use VAOs past OpenGL 3.1 core. // In ObjectRenderInfo create your VAO GLuint vertexArrayId; glGenVertexArrays(1, &vertexArrayId); glGenBuffers(1, &vbo); ... It may help you avoid ...


0

I don't know why, but cloning mModelMatrix2 into mTempMatrix2 and using that as the operand in Matrix.multiplyMM instead of directly using mModelMatrix2, solved the problem float[] mTempMatrix2 = mModelMatrix2.clone(); Matrix.multiplyMM(mModelMatrix2, 0, mTempMatrix2, 0, mRotationMatrix, 0); If somebody can post a comment and explain me why it ...


-1

How about drawing a quad strip for each row in your grid of quads? I guess it depends on how you're representing your data. One way could be to have a 2D array of 3D coordinates for the grid's vertices. To start, the Y component can be zero and then you can assign random Y values while maintaining the X and Z values intact. Then you would draw a ...


1

I understood by myself how to retrieve the frame rendered and now I have this method : void Renderer::getVideoStream(){ glReadBuffer(GL_BACK); int width = m_window->width(); int height = m_window->height(); vector< unsigned char > buf( width * height * 3 ); glPixelStorei( GL_PACK_ALIGNMENT, 1 ); glReadPixels( 0, 0, ...


1

Unity's ArasP has written an optimizer that could possibly do what you need: https://github.com/aras-p/glsl-optimizer You could also save the driver's compiled shader binary using OpenGL extension GL_ARB_get_program_binary on the first run and use it on subsequent runs to reduce loading hitches. The binary is hardware and driver dependent so you can't ship ...



Top 50 recent answers are included