FAQ Database Discussion Community


glDrawElements doesn't draw the second time it's called, using the same vertex array object and the same shader program

c#,opengl,opentk
I'm very new to opengl and I'm getting this really unexpected behavior. I'm implementing a basic scene graph and trying to add the ability to reuse shaders and mesh data. I have a GeometryData object which contains the references to the vertex array object, vertex buffer, and index buffer. It...

OpenGL deferred rendering: point light implementation

c#,opengl,glsl,opentk,deferred-rendering
I'm trying to write a deferred renderer using C# and OpenGL (with OpenTK). But don't understand how should I implement the normal calculation for a point light. The point light fragment shader: vec2 texCoord = gl_FragCoord.xy / ScreenSize; vec3 pixelPos = texture2D(PositionBuffer,texCoord).xyz; vec3 pixelNormal = normalize(texture2D(NormalBuffer, texCoord).xyz); vec3 diffuseColor =...

How can I avoid poor program performance from a TRY statement?

c#,opengl,try-catch,game-engine,opentk
I am currently developing a basic voxel (cuboid) game engine, and I have encountered a performance issue. Every frame the game: Finds player's viewing direction → Checks every co-ordinate in the player's direct view path → Finds closest occupied space → Draws a wireframe around this block. I am using...

Normals are inverted

opengl,glsl,shader,opentk
I am computing my modelview matrix, and normal matrix in my main program: private void setMV() { modelViewMat = Matrix4.Mult(modelMat,viewMat); // model * view because opentk is row major order GL.UniformMatrix4(uModelViewIndex, false, ref modelViewMat); // normal matrix = transpose(inverse(modelView)) normalMat = Matrix4.Invert(modelViewMat); normalMat = Matrix4.Transpose(normalMat); GL.UniformMatrix4(uNormalIndex, false, ref normalMat); }...

Save an OpenGL mesh from the current viewing point

opengl,rendering,mesh,opentk
I have an OpenGL visualizer (using OpenTK). It's supposed to open a mesh file in the PLY format, and display it. The user is able to move around the object, rotate or scale it. At the end, the user should be able to save the mesh into a PLY file...

Can I use both deprecated OpenGL and modern OpenGL in a single rendering window?

opengl,opentk
I am developing a project using modern OpenGL through OpenTK. I want to use Gwen dot net GUI library in my project. Unfortunately, Gwen dot net uses old OpenGL for its widget rendering. I have tried merging both modern OpenGL and Gwen dot net and so far, have been unsuccessfull....

How To Draw A Frustum in OpenGL

c#,opentk
I created a frustum class using C# and OpenTK, and it works perfectly. However, I want to be able to draw the bounds of the frustum for debugging purposes. I have no idea how to get the vertex data from the Matrix data for drawing though. I was just wondering...

Switching from perspective orthographic projection in OpenGL

c#,opengl,opentk
I'm really new to OpenGL and trying to learn from the 'modern' OpenGL tutorials. I'm using C# and OpenTK. I'm setting my projectionMatrix with this code: _projectionMatrix = Matrix4.CreatePerspectiveFieldOfView(MathHelper.PiOver3, GetAspectRatio(), 0.1f, 100f); After I set it, I upload it to the shaders, use for transformations, etc. Everything is working well...

Rendering using VBOs/VAOs in OpenGL4

c#,opengl,opentk,opengl-4
I'm trying to update some old-style OpenGL code to modern OpenGL4. I have a huge textured and pre-tessellated cube model to render. Instead of that, I'm now getting this: That's a field of semi-arbitrary black triangles on a white background. My VAO/VBO build code: // Normal buffer GL.GenBuffers(1, out VBONormals);...

OpenGL ray casting (picking): account for object's transform

opengl,opentk,raycasting,mouse-picking
For picking objects, I've implemented a ray casting algorithm similar to what's described here. After converting the mouse click to a ray (with origin and direction) the next task is to intersect this ray with all triangles in the scene to determine hit points for each mesh. I have also...

Don't serialize properties with no setter

json.net,opentk
I need to serialize objects (OpenTK.Vector2) containing properties with a getter but no setter. I would like these properties to be ignored in general, otherwise I end up with hugely inflated JSON from an object that has two relevant pieces of data (X and Y). The code: JsonSerializerSettings settings =...

Getting the accurate character from keys pressed

c#,opentk
I'm working with an OpenTK window and I am trying to create a hand-made text-box for a GUI. The issue I'm running into here is getting proper keyboard input. For example, when the user types Shift + 1, the character that appears in the text-field is an exclamation mark. The...

Can't get stencil buffers to work in OpenTK, simple 2D quads

c#,opentk,stencil-buffer
I've been trying with no success to get stencil testing to work in my OpenTK 2D game - I want to only draw parts of a texture below values of say 1 in a stencil buffer. Have spent ages reading up on stencils and how they work but can't find...

How to get rid of weird OpenTK render?

c#,opengl,graphics,opentk
I am fully aware that I can load textures in OpenTK. But when I tried to render a picture using only points it shows really weird lines when ClientSize.Width is EXACTLY equal to the width of the picture being rendered. Like this: And if I resize (enlarge) the ClientSize.Width of...

Why does this call of glEnableVertexPointer and glVertexPointer cause InvalidValue?

c#,opengl,shader,game-engine,opentk
I am creating a game engine that includes basic game needs. Using glslDevil, it turns out my bind VBO method throws an InvalidValue error. A call of glVertexPointer and a call of glEnableVertexPointer cause the issue. The vertex attribute index is causing the issue. The index is 4294967295 which is...

OpenGL what does zNear zFar mean?

opengl,opentk,opengl-4
I understand that zNear, zFar mark the clipping bounds of a scene. But OpenTK restricts the values to be greater than zero. Does this mean all my objects should be drawn on positive Z axis so that its not clipped ?