glsl

Can't get ids assigned to an attribute in OpenGL

旧时模样 提交于 2019-12-12 06:47:28
问题 I am trying to have OpenGL automatically assign an ID to a glsl-attribute, but it is failing. My main program: #include <iostream> #include <GL/glew.h> #include <GL/glfw3.h> #include "test.h" #include "shader_utils.h" static void error_callback(int error, const char* description) { std::cout << description << std::endl; } static void key_callback(GLFWwindow* window, int a, int b) { if (a == GLFW_KEY_ESCAPE && b == GLFW_PRESS) { glfwSetWindowShouldClose(window, GL_TRUE); } } void test() { std:

Atmosphere Scattering for Earth from space and on the ground

心不动则不痛 提交于 2019-12-12 06:15:37
问题 Please provide prompt how to make the atmosphere of the Earth so that it is visible from space and from the ground (as shown in the image) a model of the earth: Earth = new THREE.Mesh(new THREE.SphereGeometry(6700,32,32),ShaderMaterialEarth); model of the cosmos: cosmos= new THREE.Mesh(new THREE.SphereGeometry(50000,32,32),ShaderMaterialCosmos); and a light source: sun = new THREE.DirectionalLight(); where to start, just I do not know. Perhaps this should do ShaderMaterialCosmos , where to

map world coordinate to a texture's value in fragment shader

ε祈祈猫儿з 提交于 2019-12-12 05:28:22
问题 I am trying to map a world coordinate to a texture's value in the fragment shader using threeJS. The generated 'color' is only black but webgl doesn't return any error. Here is what I get: in the 3D, what I get in webgl (black slice instead of an image) in the 2D canvas, what I should in webgl. My shaders: <script id="vertShader" type="shader"> varying vec4 vPos; void main() { vPos = modelViewMatrix * vec4(position, 1.0 ); gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0

OpenGL ES 2.0 Shader on Texture not working

隐身守侯 提交于 2019-12-12 04:25:19
问题 I copied the example from this site click It is working well after fixing some minor things and extending the shader for my purpose. Now i want to move/translate the texture to the right side of the screen. For that case i have to add a ModelViewProjection Matrix to my code and as well to the shader, right? After doing this the Texture is not showing up anymore :-( What am I doing wrong? So the code is working until i change in my shader gl_position from : gl_Position= a_position to gl

OpenTK - After multiplying with ProjectionMatrix nothing is rendering anymore

可紊 提交于 2019-12-12 04:06:43
问题 From a tutorial that refused to explain it I got the following code. It was a lwjgl tutorial I copied where it worked perfectly fine. I'm not sure if the problem is created by having OpenGl differ from the java openGl, but since it's only math I would be surprised by that: private void createProjectionMatrix(int width, int height) { float aspectRatio = width / height; float yScale = (float)((1f / Math.Tan(Maths.degreeToRadian(FOV/2f))) * aspectRatio); float xScale = yScale / aspectRatio;

OpenGL shaders questions

天大地大妈咪最大 提交于 2019-12-12 03:59:58
问题 I have a running program that uses glVertexPointer, glNormalPointer etc to draw a large number of elements. This works around 30 FPS. Now I've reach a point where integrating shaders would be a viable option (each vertex need to have a color calculated based on a specific class). 1. Now my first question is how much would using shaders affect my FPS ? My current implementation (which I'm 99.99% is flawed in at least some way, will post code below) drops the FPS drastically to 3 FPS. If this

Copying float arrays and float values to a bytebuffer - Java

十年热恋 提交于 2019-12-12 02:56:08
问题 I am trying copy the data from two arrays and two variables to a bytebuffer. The bytebuffer will hold this data for a uniform block structure in a fragment shader. I can copy the first one in fine but the second always generates an index out of range error. I've tried using .asFloatBuffer, tried initializing the buffer to twice the size I needed and tried using a FloatBuffer (I need a ByteBuffer but I thought I'd just try to fix this error then work my way back) The structure from fragment

How can I implement the distance from a point to a line segment in GLSL?

此生再无相见时 提交于 2019-12-12 02:53:45
问题 I just can't seem to spot my bug here, can you? bool oblong (vec2 p, vec2 a, vec2 b, float r) { return (((b.y-a.y)*(p.x-a.x)+(b.x-a.x)*(p.y-a.y))^2/((b.x-a.x)^2+(b.y-a.y)^2)<= r); } This is my second GLSL program, (my first was a circle.) Thanks for your input! 回答1: You don't explain very well what the function is supposed to do and what your single-character variable names actually mean. I'm going to guess that a and b are the points on the line segment, and p is the point of interest. r

Get errors about redefinition (OpenGL 4.0 Shading Language Cookbook)

寵の児 提交于 2019-12-12 02:06:22
问题 I just tested the code in chapter 1 (OpenGL 4.0 Shading Language Cookbook) I have installed Qt5, qmake -tp vc chapter01.pro then open it in vs2010. Built and got many errors like: 1>D:\APP\Qt5\5.0.0\msvc2010\include\GLES2/gl2.h(38): error C2371: 'GLintptr' : redefinition; different basic types 1> D:\OpenGL\glew-1.5.4\include\GL/glew.h(1615) : see declaration of 'GLintptr' 1>D:\APP\Qt5\5.0.0\msvc2010\include\GLES2/gl2.h(39): error C2371: 'GLsizeiptr' : redefinition; different basic types 1> D:

OpenGL - gpu memory exceeded, possible scenarios

孤者浪人 提交于 2019-12-12 01:58:17
问题 I can use glTexImage2D or glBufferData to send some data to the gpu memory. Let's assume that I request driver to send more data to the gpu but the gpu memory is already full. I probably get GL_OUT_OF_MEMORY. What might happen with a rendering thread ? What are possible scenarios ? Is it possible that a rendering thread will be terminated ? 回答1: It depends on the actual OpenGL implementation. But the most likely scenario is, that you'll just encounter a serious performance drop, but things