我已经阅读了一个纹理示例OpenGL 2.1.片段着色器看起来像这样:
#version 120
uniform sampler2D texture;
varying vec2 texcoord;
void main(void)
{
gl_FragColor = texture2D(texture, texcoord);
}
Run Code Online (Sandbox Code Playgroud)
在texcoord从顶点着色器传递.
使用以下C++呈现代码:
void render()
{
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, texture_id);
glUniform1i(unf_texture, 0);
}
Run Code Online (Sandbox Code Playgroud)
我对某些事感到困惑.我有一些问题:
在片段着色器中,纹理传递零值(通过glUniform1i).价值真的是零吗?价值还有别的吗?
被glUniform1i()调用真正需要的?
为什么我们在glUniform1i中传递零值?
我找到了一种理解为什么glActiveTexture需要的方法.我有以下代码:
glGenTextures(1, &textureId);
glBindTexture(GL_TEXTURE_2D, textureId);
Run Code Online (Sandbox Code Playgroud)
如果我想象这GL_TEXTURE_2D是挂在墙上的图片框架并且textureId是真实的图片,那么glBindTexture它是唯一一个将真实图片分配给框架的命令,那么,什么是GL_TEXTURE0和glActiveTexture?
我的代码可以正常工作吗?
glActiveTexture(GL_TEXTURE0);
glGenTextures(1, &textureId);
glBindTexture(GL_TEXTURE_2D, textureId);
glActiveTexture(GL_TEXTURE1);
glTexImage2D(GL_TEXTURE_2D, .....)
glTexParameteri(GL_TEXTURE_2D, ...)
Run Code Online (Sandbox Code Playgroud)
我目前正在使用OpenGL2.1.
我正在做一个每片段照明,当纠正正常的时候,我得到了这个代码:vec3 f_normal = mat3(MVI) * normal;MVI在哪里:mat4 MVI = transpose(inverse(ModelViewMatrix));.那么什么是mat3(MVI)声明后的回报?
可能重复:
C++:删除这个?
面向对象的自杀或删除此;
我想知道下面的代码是否安全运行:
#include <iostream>
using namespace std;
class A
{
public:
A() {
cout << "Constructor" << endl;
}
~A() {
cout << "Destructor" << endl;
}
void deleteMe() {
delete this;
cout << "I was deleted" << endl;
}
};
int main()
{
A *a = new A();
a->deleteMe();
cout << "Exit ...";
return 0;
}
Run Code Online (Sandbox Code Playgroud)
输出是:
Constructor
Destructor
I was deleted
Exit ...
Run Code Online (Sandbox Code Playgroud)
并且程序正常退出,但这里有一些内存访问暴力吗?
我在许多ose(和一些引导程序)中看到,它们cli在从实模式切换到保护模式之前都禁用了interrupt().为什么我们需要这样做?
我有一个QML TextEdit元素,我计划附加一些文本并将光标放在最后.我的方法:
import QtQuick 1.1
Rectangle {
color: "black"
anchors.fill: parent
focus: false
TextEdit {
id: txtCommands
color: "lightGreen"
anchors.fill: parent
textFormat: TextEdit.RichText
wrapMode: TextEdit.WordWrap
font.family: "Consolas"
font.pixelSize: 15
focus: true
MouseArea {
anchors.fill: parent
focus: false
}
Keys.onPressed: {
console.log(event.text)
switch (event.key) {
case 16777234: // LEFT
case 16777235: // UP
case 16777237: // DOWN
case 16777236: // RIGHT
event.accepted = true
break;
case 16777220: // Enter
txtCommands.text = txtCommands.text + ">: "
txtCommands.selectAll()
txtCommands.cursorPosition = txtCommands.text.length
break; …Run Code Online (Sandbox Code Playgroud) 在OpenGL 2.1+中我们需要glEnable(GL_TEXTURE)在使用纹理之前调用吗?如果我们遇到纹理问题,可能是什么原因?
更新:
我正在使用OpenGL 2.1 for Desktop,我的步骤是:
加载bmp 24位图像(我在gDebuger中检查它显示我的纹理正常,所以我确定我的加载图像程序没有失败).
在程序中调用几个OpenGL函数init():
glGenTextures(1, &texture_id);
glBindTexture(GL_TEXTURE_2D, texture_id);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, image_width, image_height, 0, GL_BGR, GL_UNSIGNED_BYTE, image_data);
Run Code Online (Sandbox Code Playgroud)在draw_scene()中:
glUseProgram(program);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, texture_id);
glUniform1i(uniform_texture, 0);
...
Run Code Online (Sandbox Code Playgroud)顶点着色器(版本120):
attribute vec3 vPos;
attribute vec2 vTexCoord;
uniform mat4 MV;
uniform mat4 Projection;
varying vec2 fragTexCoord;
void main()
{
fragTexCoord = vTexCoord;
gl_Position = Projection * MV * vPos;
}
Run Code Online (Sandbox Code Playgroud)片段着色器:
uniform sampler2D my_texture;
varying vec2 fragTexCoord;
void main() …Run Code Online (Sandbox Code Playgroud)我正在学习Phong阴影并且有些困惑:
顶点着色器是:
varying vec3 normal, lightDir, eyeVec;
void main()
{
normal = gl_NormalMatrix * gl_Normal;
vec3 vVertex = vec3(gl_ModelViewMatrix * gl_Vertex);
lightDir = vec3(gl_LightSource[0].position.xyz - vVertex);
eyeVec = -vVertex;
gl_Position = ftransform();
}
Run Code Online (Sandbox Code Playgroud)
为什么eyeVec = -vVertex?
正则表达式是否具有匹配任何字符的模式,包括正则表达式中的新行?该dot模式匹配任何字符,但不包括新行,(目前,我正在使用,[^~]因为该~字符很少使用).
编辑:我使用的是regex与C#语言.
I have a C# form with some types of controls, i throught this code for loop all Labels and re-parent:
private void MakeAllLabelTrans(Control frm, Control parent)
{
foreach (Control ctl in frm.Controls)
{
if (ctl is Label)
{
ctl.Parent = parent;
// ctl.BackColor = Color.Transparent;
}
else if (ctl.HasChildren)
{
MakeAllLabelTrans(ctl, parent);
}
}
}
Run Code Online (Sandbox Code Playgroud)
and call as: MakeAllLabelTrans(this, picBackground); in Form_Load event, but some label was missed (i have puted a messagebox in the loop body - it really …