glfw

Noticable lag in a simple OpenGL program with mouse input through GLFW

佐手、 提交于 2019-12-07 06:40:10
问题 Here's a simple program that draws a triangle following the mouse cursor's position. What I (and hopefully you) can notice, is that the triangle lags behind the cursor, it's not as tight as when dragging around even a whole window. So my question is: What am I doing wrong? What leads to this lag? One thing I realize is that it would suffice to shift the actual pixel values of the triangle, and not rasterize it again and again. But is rasterizing this one triangle really that expensive? I also

OpenGL配置GLFW与GLEW的问题

烂漫一生 提交于 2019-12-06 13:59:22
在OpenGL学习的网站( https://learnopengl-cn.readthedocs.io/zh/latest/ )上学习时,按照上面的指导来配置GLFW和GLEW行不通,总是显示无法打开文件glfw3.lib 解决方法: 直接现在好预编译的二进制文件,然后将.lib文件放到VS的安装目录下(我的是VS2013),将include的所有文件(可以整个GLFW拷贝过去)放在VS安装目录下的include中即可,有dll文件的,需要放在system32的目录下,然后生成解决方案,编译顺利通过 来源: https://www.cnblogs.com/x-d-x/p/11988340.html

Lighting maps_练习二

穿精又带淫゛_ 提交于 2019-12-06 05:39:40
添加一个叫做放射光贴图(Emission Map)的东西,它是一个储存了每个片段的发光值(Emission Value)的贴图。发光值是一个包含(假设)光源的物体发光(Emit)时可能显现的颜色,这样的话物体就能够忽略光照条件进行发光(Glow)。游戏中某个物体在发光的时候,你通常看到的就是放射光贴图(比如 机器人的眼,或是箱子上的灯带)。将这个纹理(作者为 creativesam)作为放射光贴图添加到箱子上,产生这些字母都在发光的效果 片段着色器代码: 1 #version 330 core 2 struct Material { 3 sampler2D diffuse; 4 sampler2D specular; 5 sampler2D emission; 6 float shininess; 7 }; 8 9 struct Light { 10 vec3 position; 11 12 vec3 ambient; 13 vec3 diffuse; 14 vec3 specular; 15 }; 16 17 in vec2 TexCoords; 18 in vec3 Normal; 19 in vec3 FragPos; 20 out vec4 FragColor; 21 22 uniform Material material; 23 uniform Light light;

Materials_练习

混江龙づ霸主 提交于 2019-12-06 04:56:18
你能像教程一开始那样,定义相应的材质来模拟现实世界的物体吗? 分享一个银材质的箱子: 1 // silver material 2 lightingShader.setVec3("material.ambient", 0.19225,0.19225,0.19225); 3 lightingShader.setVec3("material.diffuse", 0.50754 ,0.50754, 0.50754); 4 lightingShader.setVec3("material.specular", 0.508273, 0.508273 ,0.508273); 5 lightingShader.setFloat("material.shininess", 0.4 * 128); View Code 完整代码: 1 #include <glad/glad.h> 2 #include <GLFW/glfw3.h> 3 #define STB_IMAGE_IMPLEMENTATION 4 #include <stb/stb_image.h> 5 6 #include <glm/glm.hpp> 7 #include <glm/gtc/matrix_transform.hpp> 8 #include <glm/gtc/type_ptr.hpp> 9 10 #include <Shader

Textures_练习二

不羁的心 提交于 2019-12-05 20:22:55
尝试用不同的纹理环绕方式,设定一个从 0.0f 到 2.0f 范围内的(而不是原来的 0.0f 到 1.0f )纹理坐标。试试看能不能在箱子的角落放置4个笑脸 1 #include <glad/glad.h> 2 #include <GLFW/glfw3.h> 3 #define STB_IMAGE_IMPLEMENTATION 4 #include <stb/stb_image.h> 5 6 #include <Shader/shader.h> 7 8 #include <iostream> 9 10 void framebuffer_size_callback(GLFWwindow* window, int width, int height); 11 void processInput(GLFWwindow *window); 12 13 // settings 14 const unsigned int SCR_WIDTH = 800; 15 const unsigned int SCR_HEIGHT = 600; 16 17 int main() 18 { 19 // glfw: initialize and configure 20 // ------------------------------ 21 glfwInit(); 22 glfwWindowHint

GLFW SetWindowIcon

对着背影说爱祢 提交于 2019-12-05 19:00:51
So, I am trying to set the window icon for my glfw window (obviously) but I am having trouble doing so because I don't know how to set an icon using GLFWimage. The code in the docs is as shown: GLFWimage images[2]; images[0] = load_icon("my_icon.png"); images[1] = load_icon("my_icon_small.png"); glfwSetWindowIcon(window, 2, images); But there, it doesn't show how to use or create a "load_icon" function. So, can anyone help cause I have been searching for months. glfwSetWindowIcon(GLFWwindow * window, int count, const GLFWimage * images) I think the first parameters 2 are clear and there is the

OpenGL学习 (一) - 简单窗口绘制

纵饮孤独 提交于 2019-12-05 17:49:52
一、OpenGL 简介 OpenGL 本质: OpenGL (Open Graphics Library),通常可以认为是 API ,其包含了一系列可以 操作图形、图像的函数 。但深究下来,它是由Khronos组织制定并维护的 规范 ,即 规定了每个函数该如何执行,以及它们的输出值 。根据该OpenGL的规范,开发者可编写各类 扩展库 OpenGL 发展: 立即渲染模式 :Immediate mode,也就是 固定渲染管线 ,是OpenGL早期的使用渲染模式 优点:对多数 细节做了抽象处理 ,方便调用和理解 缺点:不利于开发者完全操控,且效率低下 核心模式 :Core-profile,从OpenGL3.2起替代立即渲染模式的开发方式,迫使开发者使用 现代方法进行开发 优点:更高的 灵活性和效率 ,便于开发者深入理解图像编程 缺点:学习难度加大 OpenGL 库: OpenGL库的作用在于给我们提供了各类方法,OpenGL自身库包含:gl核心库、glu实用库、glut实用工具库(这几个库的介绍: OpenGL库中gl、glu、glut、glaux的关系 - 极客小生 ) 此外,OpenGL的一大特性就是 扩展 ,主要体现在显卡公司所提出的新特性可以 以驱动的方法实现 ,开发者可以在支持这个扩展的显卡上、使用这个扩展提供的一些更先进更有效的图形功能 常见到的库有:GLFW库和

Hello Triangle_练习二:创建相同的两个三角形,但对它们的数据使用不同的VAO和VBO

混江龙づ霸主 提交于 2019-12-05 17:45:29
2019/11/26 1 #include <glad/glad.h> 2 #include <GLFW/glfw3.h> 3 4 #include <iostream> 5 6 void framebuffer_size_callback(GLFWwindow* window, int width, int height); 7 void processInput(GLFWwindow *window); 8 9 // settings 10 const unsigned int SCR_WIDTH = 800; 11 const unsigned int SCR_HEIGHT = 600; 12 13 const char *vertexShaderSource = "#version 330 core\n" 14 "layout (location = 0) in vec3 aPos;\n" 15 "void main()\n" 16 "{\n" 17 " gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);\n" 18 "}\0"; 19 const char *fragmentShaderSource = "#version 330 core\n" 20 "out vec4 FragColor;\n" 21 "void main

Hello Triangle_练习一:添加更多顶点到数据中,使用glDrawArrays,尝试绘制两个彼此相连的三角形

那年仲夏 提交于 2019-12-05 17:44:19
2019/11/26 1 #include <glad/glad.h> 2 #include <GLFW/glfw3.h> 3 4 #include <iostream> 5 6 void framebuffer_size_callback(GLFWwindow* window, int width, int height); 7 void processInput(GLFWwindow *window); 8 9 // settings 10 const unsigned int SCR_WIDTH = 800; 11 const unsigned int SCR_HEIGHT = 600; 12 13 const char *vertexShaderSource = "#version 330 core\n" 14 "layout (location = 0) in vec3 aPos;\n" 15 "void main()\n" 16 "{\n" 17 " gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);\n" 18 "}\0"; 19 const char *fragmentShaderSource = "#version 330 core\n" 20 "out vec4 FragColor;\n" 21 "void main

测试OpenGL环境是否搭建成功

匆匆过客 提交于 2019-12-05 17:22:48
一个用来验证OpenGL(glfw + glad)环境是否搭建成功的测试代码 内特为生成一个小窗口 #include <glad/glad.h> #include <GLFW/glfw3.h> #include <stdio.h> // settings const unsigned int SCR_WIDTH = 800; const unsigned int SCR_HEIGHT = 600; void processInput(GLFWwindow *window) { if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) { //将窗口设置为关闭,跳出循环 glfwSetWindowShouldClose(window, true); } } void framebuffer_size_callback(GLFWwindow* window, int width, int height) { glViewport(0, 0, width, height); } int main() { //glfw初始化 glfwInit(); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);