w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
  Home » OPENGL » Page 1
How do I specify Normals using GL_INT_2_10_10_10_REV in a VBO array?
You'll need to pack them in a bitfield that looks something like: struct norm{ int a:2; int Z:10; int y:10; int X:10; //order may need to be different } ensure the field you put in are scaled to -512 to 511

Categories : Opengl

Shader creation Opengl
There are two errors in your vertex shader. First, you are declaring texCoord twice. attribute vec2 texCoord; varying vec2 texCoord; Then you are trying to use a varying called texCoord0, without ever declaring it. texCoord0 = texCoord; Your vertex shader should look like this: #version 120 attribute vec3 position; attribute vec2 texCoord; varying vec2 texCoord0; void main(){ gl_Po

Categories : Opengl

openGL: gl_instanceID for fragment shader
just pass it through: varying int instanceID main(){ gl_Position = //... instanceID = gl_instanceID; } and use like any other parameter you output from the vertex shader.

Categories : Opengl

Why is vertex position being taken from colour buffer instead of position buffer?
Because you need to have the right buffer bound (BindBuffer) before calling VertexAttribPointer. // Configure vertex buffer let pos_attr = "position".with_c_str(|ptr| gl::GetAttribLocation(program, ptr)); println!("{}", pos_attr); gl::EnableVertexAttribArray(pos_attr as GLuint); gl::BindBuffer(gl::ARRAY_BUFFER, vbo); gl::VertexAttribPointer(pos_attr as GLuint, 2, gl::FLOAT,

Categories : Opengl

Under which conditions can I leave out the perspective division?
When looking at a orthographic projection matrix as the following, 2/(r - l) 0 0 tx 0 2/(t - b) 0 ty M = 0 0 -2/(f - n) tz 0 0 0 1 one can notice, that the last row is [0,0,0,1]. This means, that when multiplying M with a vector [x1,y1,z1,1], the result will be [x2,y2,z2,1]. Thus when performing the perspect

Categories : Opengl

can i use opentk and xna in the same project and showing the data on the same window? Does OpenTk Support Xna?
XNA is using Direct3d, whereas OpenTK is OpenGL. In the general case, you cannot draw using OpenGL into a Direct3d window.[1] What you can do is switch from XNA to MonoGame. It is an open-source implementation of XNA and supports both Direct3d and OpenGL. If you use the OpenGL version, you will be able to draw into the same window using both XNA and OpenTK. [1] WGL_NV_DX_interop allows you to sh

Categories : Opengl

How to get accurate fragment screen position, like gl_FragCood in vertex shader?
In the vertex shader, you set gl_Position = ... This must be in clip space, before the perspective divide to normalized device coordinates. This is because OpenGL does a bunch of stuff in the 4D space and is necessary for interpolation. Since you just want the value at each vertex and nothing interpolated, you can normalize right away (or can even leave out if using an orthographic projection)

Categories : Opengl

Moving and looking around with camera conflicts
You should set uniform values right before you need them, i.e. in the drawing code, before making the glDraw… calls. If you set them somewhere in the event handlers, anything happening between the event handler and drawing may overwrite the values you put there. This is what happens to you: Your both camera class instances write to the same location and only one of them can win.

Categories : Opengl

Core OpenGL GUI
Qt is probably the easiest to use; but I speak only from experience since I know Qt. Qt being so vast and multi-platform requires a willingness to learn, and you don't have to know OpenGL entirely to know it; not unless you want to be creating a game with Qt. Although, I do recommend taking a look at Qt since it has a great emphasis on C++ and could make your programming a better experience.

Categories : Opengl

How to apply Bullet physics to drawn Opengl 3d shapes
Without studying the specifics of Bullet or OpenGL (I've coded in OpenGL a little) it seems you wish to apply Bullet to an object twice, once for the CollisionShape (whatever that is) and then for the drawn opengl object. It seems it would be a matter of creating your OpenGL object in a memory object, applying the Bullet method to get your CollisionShape (whatever that is), saving this data in me

Categories : Opengl

OpenGL Separating Polygons Inside VBO
Part of this was already covered in the comments. Replacement of GL_POLYGON The GL_POLYGON primitive type is deprecated, and not available in the OpenGL Core Profile. Fortunately it can easily be replace with GL_TRIANGLE_FAN. GL_TRIANGLE_FAN uses the same vertex order, so you can directly replace GL_POLYGON with GL_TRIANGLE_FAN, without changing anything else. Only convex polygons can directly

Categories : Opengl

Alpha blending, transparence and z-ordering
You typically disable depth writes (e.g. glDepthMask (GL_FALSE)) for the translucent objects, but the depth test itself is not something you would disable. You need to test against the depth values generated by the opaque objects for this to function correctly, otherwise you have to sort both your opaque and translucent objects (which is exactly what you did originally).

Categories : Opengl

how can i fire a point to the end of the screen in opengl?
You have to calculate the direction in which the particle has to fly, which is given by d = normalize(MousePos - ScreenCenter) In each frame you update your point's position by adding the direction (most probably times a factor controlling the speed) to it: PointPos = PointPos + d * speed When you reach the borders of your screen you make the point disappear. Testing whether you left the vis

Categories : Opengl

Color changes when scaling a gluQuadric
The normals are not being scaled correctly (they are non-unit length after scaling). You have two options to solve this: GL_NORMALIZE -- This will renormalize your normals, which is costly. GL_RESCALE_NORMAL -- This will simply rescale them. Option #2 is what you want here, since you applied a uniform scale (6.0x in every direction). If you had applied a non-uniform scale (e.g. glScalef (1.0f

Categories : Opengl

SDL2 render without pixel units
Those are Normalized Device Coordinates. They map the corners of your viewport to the range [-1,1]. All you need to do is implement your own mapping. I've explained this visually in another similar question. You want to go the other direction though, so you would use: ScreenX = (NDCX * 0.5 + 0.5) * ViewportW + ViewportX ScreenY = (NDCY * 0.5 + 0.5) * ViewportH + ViewportY

Categories : Opengl

texCoordPointer not working in lwjgl
I believe your problem is in the argument to textureBuffer.put() in this code fragment: textureBuffer = BufferUtils.createFloatBuffer(textureData.length); textureBuffer.put(texture); textureBuffer.flip(); texture is a variable of type int, which has not even been initialized yet. You later use it as a buffer name. The argument should be textureData instead: textureBuffer.put(te

Categories : Opengl

Can EGL application run in console mode?
This is a recurring question. TL;DR: With the current Linux graphics driver model it is impossible to use the GPU with traditional drivers without running a X server. If the GPU is supported by KMS+DRM+DRI you can do it. The long story is, that technically GPUs are perfectly capable of rendering to an offscreen buffer without a display being attached or a graphics server running. However due to

Categories : Opengl

Particles with different textures in OpenGL
OpenGL 3.2 supports 2D array textures. That would be the simplest way of giving these instanced particles different textures using an integer index. There is one caveat here, that each of the textures should have the same dimensions, but that's probably not a big deal for particles. Newer versions of GL also support bindless textures (as an ARB extension) and they can be used for the same purpose

Categories : Opengl

Incorrect result when using 3D textures
That's because 0 is the "leftmost" part of the left texel and 1 is the rightmost point in the rightmost texel. Assume we have 4 texels, than the coordinates are as follows: 0 1/4 1/2 3/4 1 | tx1 | tx2 | tx3 | tx4 | since you need to hit exactly the center of a voxel, you have to use addresses that are 1/2 voxel higher then you expected (+0.25/2 = +0.125), thus

Categories : Opengl

OpenGL program compiles with C but not with C++
It's possible that this is because C does not require function prototypes, whereas C++ does. Compiling in C, you are eventually linking to the definitions in libGL and that works. You don't technically need the headers for those functions. Compiling in C++, you are missing the headers which provide the function prototypes. You can use GLEW for that or you can load GL functions yourself with OS

Categories : Opengl

OpenGL Texture 2D arrays and mipmapping
The second param is the mipmap level of the texture you want to load. In your case, since you want to rely on GL to generate the mipmaps, it's 0. The eighth parameter is the depth. In the case of arrays, that means the number of layers you're passing. For you, it's 1, since you're passing a single layer per iteration of the loop. The 5th parameter, however, is the offset in depth of where you wa

Categories : Opengl

how can i draw an object in 2D at the center at openGl?
Assume we have a triangle with one vertex lying in the center of the screen (NDC=[0,0]), that is symmetric along the x-axis. The problem of letting the triangle point to the mouse is than the problem of finding the angle between the vector going from the center of the screen to the mouseposition and the x-axis ([1,0]). A solution for doing this can look like the following: Vec2 mousePosition = qu

Categories : Opengl

Orthographic projection matrix in OpenGL
use glutOrtho2d. Refer the link if you have any doubts https://www.opengl.org/sdk/docs/man2/xhtml/gluOrtho2D.xml

Categories : Opengl

Drawing 2D HUD over 3D OpenGL sence with SDL
IIRC, OpenGL has functions for drawing 2D elements. You could render the 3D to a texture and then render 2D over it. If you must use SDL, you'll need a method to copy an OpenGL texture to an SDL surface/texture.

Categories : Opengl

Can the pixel transfer format change when uploading texture data via glTexSubImage?
So, is my interpretation correct? In one word: Yes. It's called internal format and pixel data format for a reason. ANGLE is an emulation of OpenGL-ES and hence follows the specification and behavior as specified for that. Which is consistent with your observation.

Categories : Opengl

Render sphere like normals for billboard (volumetric billboard?)
The reason your gl_PointCoord usage doesn't turn out like you wanted is that the range of gl_PointCoord is 0.0 to 1.0, not -1.0 to 1.0. Just subtract 0.5 to make it balanced about 0.0. If you also multiply it by 2 it will have the range -1.0 to 1.0. You may also want to normalize the resulting vector (not doing so can cause unwanted brightness variations as the length of the vector changes due t

Categories : Opengl

PyOpenGL Transformation Blur
Use GL_NEAREST in your glTexParameteri() calls: glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST) glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST)

Categories : Opengl

Debuging OpenGL 3.0 without direct API ( aka glBegin() ... )
You can still use all the legacy features with OpenGL 3.2 or later if you create a context with the Compatibility Profile. Only the Core Profile has the legacy features removed. Most platforms still seem to support the Compatibility Profile. One notable exception is Mac OS, where 3.x contexts are only supported with the Core Profile. Up to OpenGL 3.1, there was only a single profile. The split i

Categories : Opengl

Multisampling using FBO
You are currently drawing into frameBufID instead of fboID. To fix this problem, move this line: glBindFramebuffer(GL_FRAMEBUFFER, fboID); Here: glGenFramebuffers(1, &frameBufID); glBindFramebuffer(GL_FRAMEBUFFER, frameBufID); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex_image[0], 0); glBindFramebuffer(GL_FRAMEBUFFER, fboID); Then you will draw into f

Categories : Opengl

no uniform with name 'u_proj' in shader
Make sure that you check the success of your shader compilation/linking. Your fragment shader will not compile: uniform u_projTrans; This variable declaration needs a type. It should be: uniform mat4 u_projTrans; You can use the following calls to test for errors while setting up your shader programs: glGetShaderiv(shaderId, GL_COMPILE_STATUS, ...); glGetShaderInfoLog(shaderId, ...); glGetP

Categories : Opengl

Coalesced memory access performance
General rules: memory access instructions are issued warp-wide, just like any other instruction each thread in a warp provides an address to read from assuming these addresses don't "hit" in any of the caches, the memory controller collects all addresses and determines how many "segments" (roughly analogous to a cacheline) are required from DRAM. A "segment" is either 32 bytes or 128 bytes, dep

Categories : Opengl

ellipsoid and paraboloid relation
It is sufficient to consider 2D case (because paraboloid and ellipsoid could be formed by rotation). Let's points in set have distances L to OY axis and distances R to F point, and distance's ratio is coefficient m: L * m = R Let's m^2 = k k * L^2 = R^2 k * X^2 = Y^2 + (X - F)^2 X^2 * (k-1) + 2 * X * F - F^2 = Y^2 when k = 1 then Y^2 = 2* F * (X - F/2) This is canonical equaition of pa

Categories : Opengl

glDrawArrays with buffer not working in JOGL
glEnableVertexAttribArray expects the attribute location (the number you set as first parameter of glVertexAttribPointer) so you should change it to: gl.glEnableVertexAttribArray(0); gl.glVertexAttribPointer(0, 3, GL2.GL_FLOAT, false, 0, 0); gl.glDrawArrays(GL2.GL_TRIANGLES, 0, 3); gl.glDisableVertexAttribArray(0);

Categories : Opengl

libgdx heighmap shader distortion artefact
I finaly found the solution, the problem came from the utilisation of the same FBO to draw the scene and then to render the shader like: batch.setShader(waterfallShaderProgram) fbo.begin(); batch.begin(); // here is the problem, fbo is started and used to // draw at the same time batch.draw(fbo.getColorBufferTexture()); batch.end() fbo.end(); the scene is rendered to the FBO fbo in order to ap

Categories : Opengl

Some questions about OpenGL transparency
You certainly need to take the transformations into account for sorting. Applying all the transformations, and then sorting by the resulting depth (z-coordinate), is the most direct approach. A mostly more efficient way of achieving the same thing is to apply the inverse transformations to your view direction once for each object (or set of objects that use the same transformations), and then cal

Categories : Opengl

Fishy glGetAttribLocation returns -1
Attributes cannot go directly into the fragment shader. Their full name is vertex attributes, which means that they provide values per vertex, and are inputs to the vertex shader. Fragment shaders can have in variables, but they do not correspond to vertex attributes. They need to match up with out variables of the vertex shader. So what you need to do to get this working is to define the attrib

Categories : Opengl

LWJGL How can I render texture shape in white color
This can be done using texture combiners. The idea is to replace the color channel of your rabbit texture with white, while keeping the alpha channel the same. Setup a texture combiner to combine a constant white color with your alpha mask: GLfloat white [4] = { 1.0f, 1.0f, 1.0f, 1.0f }; glBindTexture (GL_TEXTURE_2D, rabbitTexture); glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL

Categories : Opengl

What data type for internalformat specified as GL_RGBA?
I'm not sure what your question here is but GL_RGBA is normally a 4x8bit (4-byte/GL_BYTE type) format in the R,G,B,A order respectively but the constant is just saying that the buffer is composed of this order and not exactly how big each channel width is. More info here Edit: For some methods, you also need to specify this channel width (e.g. glReadPixels() or glDrawPixels())

Categories : Opengl

OpenGL shader not passing variable from vertex to fragment shader
I've seen implementations of OpenGL 2.0 having problems at compile time when adding floats and not explicitly casted integers. Even if it is not a problem I would think possible on a 4.3 implementation, maybe you should just add dots and suffixes to your "integer" constants. The last line of you're vertex shader seems to be the only one that could be a problem (I believe values are always casted

Categories : Opengl




© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.