- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我只想对默认的 OpenGL 行为进行一些说明。据我了解,默认事件纹理单元为 0 (GL_TEXTURE0
),除非通过 glActiveTexture
明确更改,否则将保持不变。
我问这个是因为我遇到了无法解释且有问题的行为。加载纹理并将其绑定(bind)到 GL_TEXTURE_2D
(假设 GL_TEXTURE0
处于事件状态)后,我无法显示它,直到我将事件纹理设置为 GL_TEXTURE1
。甚至在加载后第一次绑定(bind)之前显式调用 glActiveTexture(GL_TEXTUREX)
,然后在绘制期间使用它时重复此调用也没有任何作用。仅当我在绑定(bind)和分配给着色器之前调用 glActiveTexture(GL_TEXTURE1)
时才会显示纹理。
当我尝试使用更多纹理时会重复此过程,而我必须显式设置每个 glActiveTexture(GL_TEXTURE...)
取决于我之前加载和首次绑定(bind)纹理的顺序我绑定(bind)它们并将它们分配给着色器。即使我没有使用我加载的第一个纹理进行绘制,我仍然必须调用 glActiveTexture(GL_TEXTURE2)
...而不是 GL_TEXTURE1
,或者更好的 GL_TEXTURE0
因为到那时我什至还没有调用 glActiveTexture(...)
。我认为后者是根据 GL 规范应该发生的情况。
https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glActiveTexture.xhtml
这是司机主义吗?
Dell Precision M6800、nV K2200M、GL 4.1 和 3.3。
更新:孤立的例子。
#include <Windows.h>
#include <gl\GL.h>
#include "glext.h"
#include "wglext.h"
#include <vector>
#include <memory>
#include <atlimage.h>
namespace
{
class GLFunc
{
public:
GLFunc()
{
glCreateProgram = (PFNGLCREATEPROGRAMPROC)wglGetProcAddress("glCreateProgram");
glCreateShader = (PFNGLCREATESHADERPROC)wglGetProcAddress("glCreateShader");
glShaderSource = (PFNGLSHADERSOURCEPROC)wglGetProcAddress("glShaderSource");
glCompileShader = (PFNGLCOMPILESHADERPROC)wglGetProcAddress("glCompileShader");
glAttachShader = (PFNGLATTACHSHADERPROC)wglGetProcAddress("glAttachShader");
glDetachShader = (PFNGLDETACHSHADERPROC)wglGetProcAddress("glDetachShader");
glLinkProgram = (PFNGLLINKPROGRAMPROC)wglGetProcAddress("glLinkProgram");
glUseProgram = (PFNGLUSEPROGRAMPROC)wglGetProcAddress("glUseProgram");
glGenFramebuffers = (PFNGLGENFRAMEBUFFERSPROC)wglGetProcAddress("glGenFramebuffers");
glBindFramebuffer = (PFNGLBINDFRAMEBUFFERPROC)wglGetProcAddress("glBindFramebuffer");
glGenRenderbuffers = (PFNGLGENRENDERBUFFERSPROC)wglGetProcAddress("glGenRenderbuffers");
glBindRenderbuffer = (PFNGLBINDRENDERBUFFERPROC)wglGetProcAddress("glBindRenderbuffer");
glRenderbufferStorage = (PFNGLRENDERBUFFERSTORAGEPROC)wglGetProcAddress("glRenderbufferStorage");
glFramebufferRenderbuffer = (PFNGLFRAMEBUFFERRENDERBUFFERPROC)wglGetProcAddress("glFramebufferRenderbuffer");
glFramebufferTexture = (PFNGLFRAMEBUFFERTEXTUREPROC)wglGetProcAddress("glFramebufferTexture");
glDrawBuffers = (PFNGLDRAWBUFFERSPROC)wglGetProcAddress("glDrawBuffers");
glCheckFramebufferStatus = (PFNGLCHECKFRAMEBUFFERSTATUSPROC)wglGetProcAddress("glCheckFramebufferStatus");
glGenVertexArrays = (PFNGLGENVERTEXARRAYSPROC)wglGetProcAddress("glGenVertexArrays");
glBindBuffer = (PFNGLBINDBUFFERPROC)wglGetProcAddress("glBindBuffer");
glBufferData = (PFNGLBUFFERDATAPROC)wglGetProcAddress("glBufferData");
glDeleteFramebuffers = (PFNGLDELETEFRAMEBUFFERSPROC)wglGetProcAddress("glDeleteFramebuffers");
glDeleteRenderbuffers = (PFNGLDELETERENDERBUFFERSPROC)wglGetProcAddress("glDeleteRenderbuffers");
glDeleteVertexArrays = (PFNGLDELETEVERTEXARRAYSPROC)wglGetProcAddress("glDeleteVertexArrays");
glGetShaderiv = (PFNGLGETSHADERIVPROC)wglGetProcAddress("glGetShaderiv");
glGetShaderInfoLog = (PFNGLGETSHADERINFOLOGPROC)wglGetProcAddress("glGetShaderInfoLog");
glGetProgramiv = (PFNGLGETPROGRAMIVPROC)wglGetProcAddress("glGetProgramiv");
glGetProgramInfoLog = (PFNGLGETPROGRAMINFOLOGPROC)wglGetProcAddress("glGetProgramInfoLog");
glGenBuffers = (PFNGLGENBUFFERSPROC)wglGetProcAddress("glGenBuffers");
glEnableVertexAttribArray = (PFNGLENABLEVERTEXATTRIBARRAYPROC)wglGetProcAddress("glEnableVertexAttribArray");
glVertexAttribPointer = (PFNGLVERTEXATTRIBPOINTERPROC)wglGetProcAddress("glVertexAttribPointer");
glBindVertexArray = (PFNGLBINDVERTEXARRAYPROC)wglGetProcAddress("glBindVertexArray");
glGetUniformLocation = (PFNGLGETUNIFORMLOCATIONPROC)wglGetProcAddress("glGetUniformLocation");
glUniformMatrix2fv = (PFNGLUNIFORMMATRIX2FVPROC)wglGetProcAddress("glUniformMatrix2fv");
glUniformMatrix3fv = (PFNGLUNIFORMMATRIX3FVPROC)wglGetProcAddress("glUniformMatrix3fv");
glUniformMatrix4fv = (PFNGLUNIFORMMATRIX4FVPROC)wglGetProcAddress("glUniformMatrix4fv");
glUniform1f = (PFNGLUNIFORM1FPROC)wglGetProcAddress("glUniform1f");
glUniform2f = (PFNGLUNIFORM2FPROC)wglGetProcAddress("glUniform2f");
glUniform3f = (PFNGLUNIFORM3FPROC)wglGetProcAddress("glUniform3f");
glUniform4f = (PFNGLUNIFORM4FPROC)wglGetProcAddress("glUniform4f");
glUniform1i = (PFNGLUNIFORM1IPROC)wglGetProcAddress("glUniform1i");
glUniform2i = (PFNGLUNIFORM2IPROC)wglGetProcAddress("glUniform2i");
glUniform3i = (PFNGLUNIFORM3IPROC)wglGetProcAddress("glUniform3i");
glUniform4i = (PFNGLUNIFORM4IPROC)wglGetProcAddress("glUniform4i");
glActiveTexture = (PFNGLACTIVETEXTUREPROC)wglGetProcAddress("glActiveTexture");
glDeleteShader = (PFNGLDELETESHADERPROC)wglGetProcAddress("glDeleteShader");
}
PFNGLCREATEPROGRAMPROC glCreateProgram;
PFNGLCREATESHADERPROC glCreateShader;
PFNGLSHADERSOURCEPROC glShaderSource;
PFNGLCOMPILESHADERPROC glCompileShader;
PFNGLATTACHSHADERPROC glAttachShader;
PFNGLDETACHSHADERPROC glDetachShader;
PFNGLLINKPROGRAMPROC glLinkProgram;
PFNGLUSEPROGRAMPROC glUseProgram;
PFNGLGENFRAMEBUFFERSPROC glGenFramebuffers;
PFNGLBINDFRAMEBUFFERPROC glBindFramebuffer;
PFNGLGENRENDERBUFFERSPROC glGenRenderbuffers;
PFNGLBINDRENDERBUFFERPROC glBindRenderbuffer;
PFNGLRENDERBUFFERSTORAGEPROC glRenderbufferStorage;
PFNGLFRAMEBUFFERRENDERBUFFERPROC glFramebufferRenderbuffer;
PFNGLFRAMEBUFFERTEXTUREPROC glFramebufferTexture;
PFNGLDRAWBUFFERSPROC glDrawBuffers;
PFNGLCHECKFRAMEBUFFERSTATUSPROC glCheckFramebufferStatus;
PFNGLGENVERTEXARRAYSPROC glGenVertexArrays;
PFNGLBINDBUFFERPROC glBindBuffer;
PFNGLBUFFERDATAPROC glBufferData;
PFNGLDELETEFRAMEBUFFERSPROC glDeleteFramebuffers;
PFNGLDELETERENDERBUFFERSPROC glDeleteRenderbuffers;
PFNGLDELETEVERTEXARRAYSPROC glDeleteVertexArrays;
PFNGLGETSHADERIVPROC glGetShaderiv;
PFNGLGETSHADERINFOLOGPROC glGetShaderInfoLog;
PFNGLGETPROGRAMIVPROC glGetProgramiv;
PFNGLGETPROGRAMINFOLOGPROC glGetProgramInfoLog;
PFNGLGENBUFFERSPROC glGenBuffers;
PFNGLENABLEVERTEXATTRIBARRAYPROC glEnableVertexAttribArray;
PFNGLVERTEXATTRIBPOINTERPROC glVertexAttribPointer;
PFNGLBINDVERTEXARRAYPROC glBindVertexArray;
PFNGLGETUNIFORMLOCATIONPROC glGetUniformLocation;
PFNGLUNIFORMMATRIX2FVPROC glUniformMatrix2fv;
PFNGLUNIFORMMATRIX3FVPROC glUniformMatrix3fv;
PFNGLUNIFORMMATRIX4FVPROC glUniformMatrix4fv;
PFNGLUNIFORM1FPROC glUniform1f;
PFNGLUNIFORM2FPROC glUniform2f;
PFNGLUNIFORM3FPROC glUniform3f;
PFNGLUNIFORM4FPROC glUniform4f;
PFNGLUNIFORM1IPROC glUniform1i;
PFNGLUNIFORM2IPROC glUniform2i;
PFNGLUNIFORM3IPROC glUniform3i;
PFNGLUNIFORM4IPROC glUniform4i;
PFNGLACTIVETEXTUREPROC glActiveTexture;
PFNGLDELETESHADERPROC glDeleteShader;
};
static HGLRC hglrc_;
static GLFunc* gl_;
unsigned int points_;
unsigned int uvs_;
unsigned int indexes_;
unsigned int vao_;
unsigned int calibrationTexture_;
unsigned int vertexShader_;
unsigned int fragmentShader_;
unsigned int programID_;
struct Vector3
{
Vector3(float x, float y, float z)
: x_(x), y_(y), z_(z)
{
}
float x_;
float y_;
float z_;
};
struct Vector2
{
Vector2(float x, float y)
: x_(x), y_(y)
{
}
float x_;
float y_;
};
struct Texture
{
Texture(unsigned int width, unsigned int height)
: width_(width), height_(height)
{
bits_.insert(bits_.end(), width*height * 3, 0);
}
unsigned char* GetTexel(unsigned int x, unsigned int y)
{
return &bits_[((x * height_) + y)*3];
}
unsigned int width_;
unsigned int height_;
std::vector<unsigned char> bits_;
};
unsigned int CompileVertexShader(const std::string& sourceCode)
{
GLint result = GL_FALSE;
GLuint vertexShaderID = gl_->glCreateShader(GL_VERTEX_SHADER);
const char* src = sourceCode.c_str();
gl_->glShaderSource(vertexShaderID, 1, &src, NULL);
gl_->glCompileShader(vertexShaderID);
gl_->glGetShaderiv(vertexShaderID, GL_COMPILE_STATUS, &result);
if (result == GL_FALSE)
{
int infoLogLength;
gl_->glGetShaderiv(vertexShaderID, GL_INFO_LOG_LENGTH, &infoLogLength);
std::vector<GLchar> error(infoLogLength);
gl_->glGetShaderInfoLog(vertexShaderID, infoLogLength, &infoLogLength, &error[0]);
std::string errStr(&error[0], error.size());
OutputDebugString(errStr.c_str());
return 0;
}
return vertexShaderID;
}
unsigned int CompileFragmentShader(const std::string& sourceCode)
{
GLint result = GL_FALSE;
GLuint fragmentShaderID = gl_->glCreateShader(GL_FRAGMENT_SHADER);
const char* src = sourceCode.c_str();
gl_->glShaderSource(fragmentShaderID, 1, &src, NULL);
gl_->glCompileShader(fragmentShaderID);
gl_->glGetShaderiv(fragmentShaderID, GL_COMPILE_STATUS, &result);
if (result == GL_FALSE)
{
int infoLogLength;
gl_->glGetShaderiv(fragmentShaderID, GL_INFO_LOG_LENGTH, &infoLogLength);
std::vector<GLchar> error(infoLogLength);
gl_->glGetShaderInfoLog(fragmentShaderID, infoLogLength, &infoLogLength, &error[0]);
std::string errStr(&error[0], error.size());
OutputDebugString(errStr.c_str());
return 0;
}
return fragmentShaderID;
}
unsigned int LinkShaderProgram(unsigned int vertexShader, unsigned int fragmentShader)
{
// attempt to link the program...
GLint result = GL_FALSE;
unsigned int programID = gl_->glCreateProgram();
gl_->glAttachShader(programID, vertexShader);
gl_->glAttachShader(programID, fragmentShader);
gl_->glLinkProgram(programID);
gl_->glGetProgramiv(programID, GL_LINK_STATUS, &result);
if (result == GL_FALSE)
{
int InfoLogLength;
gl_->glGetProgramiv(programID, GL_INFO_LOG_LENGTH, &InfoLogLength);
std::vector<GLchar> error(InfoLogLength);
gl_->glGetProgramInfoLog(programID, InfoLogLength, &InfoLogLength, &error[0]);
std::string errStr(&error[0], error.size());
OutputDebugString(errStr.c_str());
return 0;
}
gl_->glDetachShader(programID, vertexShader);
gl_->glDetachShader(programID, fragmentShader);
return programID;
}
void SetUniform(const std::string& name, unsigned int ID)
{
int location = gl_->glGetUniformLocation(programID_, name.c_str());
if (location < 0)
OutputDebugString("Unable to find uniform location :(");
else
gl_->glUniform1i(location, ID);
}
std::shared_ptr<Texture> LoadTexture(const std::string& filename)
{
CImage image;
image.Load(filename.c_str());
std::shared_ptr<Texture> texture(new Texture(image.GetWidth(), image.GetHeight()));
for (int y = image.GetHeight() - 1; y >= 0; --y)
{
for (int x = 0; x < image.GetWidth(); ++x)
{
unsigned char* target = texture->GetTexel(x, y);
unsigned char* source = reinterpret_cast<unsigned char*>(image.GetPixelAddress(x, y));
for ( unsigned int c = 0; c < 3; ++c )
*(target+c) = *(source+c);
}
}
return texture;
}
}
extern "C" __declspec(dllexport) int OpenGLInit(void* hdc)
{
// We need to create a context or get an existing one that fits the supplied context.
// first check we have a valid device context
if (!hdc)
return 1;
HDC hDC = static_cast<HDC>(hdc);
if (!hDC)
return 2;
// we then need to get a valid DC...
PIXELFORMATDESCRIPTOR pfd;
memset(&pfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
pfd.nVersion = 1;
pfd.dwFlags = PFD_DOUBLEBUFFER | PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 32;
pfd.cDepthBits = 32;
pfd.cStencilBits = 8;
pfd.iLayerType = PFD_MAIN_PLANE;
int nPixelFormat = ChoosePixelFormat(hDC, &pfd);
if (nPixelFormat == 0)
return 3;
if (!SetPixelFormat(hDC, nPixelFormat, &pfd))
return 4;
HGLRC tempContext = wglCreateContext(hDC);
wglMakeCurrent(hDC, tempContext);
int attribs[] =
{
WGL_CONTEXT_MAJOR_VERSION_ARB, 4,
WGL_CONTEXT_MINOR_VERSION_ARB, 1,
WGL_CONTEXT_FLAGS_ARB, 0,
0
};
PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC)wglGetProcAddress("wglCreateContextAttribsARB");
if (wglCreateContextAttribsARB)
{
hglrc_ = wglCreateContextAttribsARB(hDC, 0, attribs);
wglMakeCurrent(NULL, NULL);
wglDeleteContext(tempContext);
if (!wglMakeCurrent(hDC, hglrc_))
return 5;
}
// Initialise the functions..
gl_ = new GLFunc();
// Cache the geometry for a quad
float v = 1.0f;
std::vector<Vector3> quadPoints = std::initializer_list<Vector3>({
Vector3(-v, -v, 0),
Vector3(v, -v, 0),
Vector3(v, v, 0),
Vector3(-v, v, 0)
});
std::vector<Vector2> quadUVs = std::initializer_list<Vector2>({
Vector2(0, 0),
Vector2(1.0f, 0),
Vector2(1.0f, 1.0f),
Vector2(0, 1.0f)
});
std::vector<unsigned int> quadIndexes = std::initializer_list<unsigned int>({
0, 1, 2, 2, 3, 0
});
gl_->glGenVertexArrays(1, &vao_);
gl_->glBindVertexArray(vao_);
// Cache the points...
gl_->glGenBuffers(1, &points_);
gl_->glBindBuffer(GL_ARRAY_BUFFER, points_);
gl_->glBufferData(GL_ARRAY_BUFFER, sizeof(float) * 3 * quadPoints.size(), &quadPoints[0].x_, GL_STATIC_DRAW);
gl_->glEnableVertexAttribArray(0);
gl_->glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
// Cache the UVs...
gl_->glGenBuffers(1, &uvs_);
gl_->glBindBuffer(GL_ARRAY_BUFFER, uvs_);
gl_->glBufferData(GL_ARRAY_BUFFER, sizeof(float) * quadUVs.size() * 2, &quadUVs[0].x_, GL_STATIC_DRAW);
gl_->glEnableVertexAttribArray(1);
gl_->glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, 0);
// Cache the indexes...
gl_->glGenBuffers(1, &indexes_);
gl_->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexes_);
gl_->glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(unsigned int) * quadIndexes.size(), &quadIndexes[0], GL_STATIC_DRAW);
gl_->glBindBuffer(GL_ARRAY_BUFFER, NULL);
gl_->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, NULL);
gl_->glBindVertexArray(NULL);
// Load the texture...
std::shared_ptr<Texture> calibrationImage = LoadTexture("uvgrid.jpg");
glGenTextures(1, &calibrationTexture_);
glBindTexture(GL_TEXTURE_2D, calibrationTexture_);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, calibrationImage->width_, calibrationImage->height_, 0, GL_RGB, GL_UNSIGNED_BYTE, &calibrationImage->bits_[0]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glBindTexture(GL_TEXTURE_2D, NULL);
// Compile the shaders
const char* fragmentSource = R"(
#version 410 core
uniform sampler2D quadTexture;
in vec2 UV;
out vec3 COLOUR;
void main()
{
//COLOUR = vec3(UV.st, 0);
COLOUR = texture(quadTexture, UV).bgr;
}
)";
const char* vertexSource = R"(
#version 410 core
in vec3 inP;
in vec2 inUV;
out vec2 UV;
void main()
{
gl_Position = vec4(inP, 1.0);
UV = inUV;
}
)";
vertexShader_ = CompileVertexShader(vertexSource);
fragmentShader_ = CompileFragmentShader(fragmentSource);
programID_ = LinkShaderProgram(vertexShader_, fragmentShader_);
return 0;
}
extern "C" __declspec(dllexport) void OpenGLKill()
{
wglDeleteContext(hglrc_);
}
extern "C" __declspec(dllexport) void OpenGLDraw(void* hdc, float rotation)
{
HDC validHDC = static_cast<HDC>(hdc);
glClearColor(0.2f, 0.2f, 0.2f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
gl_->glUseProgram(programID_);
gl_->glBindVertexArray(vao_);
gl_->glBindBuffer(GL_ARRAY_BUFFER, uvs_);
gl_->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexes_);
// Assign the texture...
gl_->glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, calibrationTexture_);
SetUniform("quadTexture", calibrationTexture_);
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
gl_->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, NULL);
gl_->glBindVertexArray(NULL);
gl_->glUseProgram(NULL);
SwapBuffers(validHDC);
}
extern "C" __declspec(dllexport) void OpenGLResize(int width, int height)
{
glViewport(0, 0, width, height);
//glMatrixMode(GL_PROJECTION);
//glLoadIdentity();
//glOrtho(width / static_cast<float>(height), -width / static_cast<float>(height), -1.0f, 1.0f, 0.1f, 100.0f);
}
包含 wpf 客户端的完整代码:https://github.com/spiroyster/wpfogl(分支“GL4”)。
如前所述,在绘制例程绑定(bind)纹理之前,我必须显式调用 gl_->glActiveTexture(GL_TEXTURE1)
,即使在此之前我从未设置过事件纹理单元(而且只有一个)在上下文中加载的纹理)。如果我删除该行,即事件纹理单元保留为 GL_TEXTURE0
,它不会显示纹理。
接下来是我加载的所有后续纹理...也就是说,如果它是我在此实例/上下文中加载的第二个纹理,则必须将事件纹理单元设置为说 GL_TEXTURE2
...即使我只使用所述纹理,也会发生这种情况。即,即使我只使用第二个纹理进行绘制(而不是第一个加载的纹理),我仍然必须明确地将事件纹理单元设置为 GL_TEXTURE2
。
最佳答案
必须为纹理采样器统一设置的值是纹理单元的索引,而不是纹理对象。
像这样更改您的代码:
gl_->glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, calibrationTexture_);
// this is wrong
//SetUniform("quadTexture", calibrationTexture_);
SetUniform( "quadTexture", 1 ); // 1 because of GL_TEXTURE1
参见 OpenGL 4.6 API Compatibility Profile Specification; 7.10 Samplers; page 154 :
Samplers are special uniforms used in the OpenGL Shading Language to identify the texture object used for each texture lookup. The value of a sampler indicates the texture image unit being accessed. Setting a sampler’s value to
i
selects texture image unit numberi
.
注意,纹理对象的“名称”由
glGenTextures(1, &calibrationTexture_);
此“名称”(整数)取决于硬件和驱动程序。
但是由于您的代码中只生成了 1 个纹理对象,因此名称的值很有可能是 1。
这意味着,当你设置
gl_->glActiveTexture(GL_TEXTURE1);
您的代码有效,因为 calibrationTexture_
的值为 1。
关于c++ - glActiveTexture 默认行为不符合预期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49542557/
#include using namespace std; class C{ private: int value; public: C(){ value = 0;
这个问题已经有答案了: What is the difference between char a[] = ?string?; and char *p = ?string?;? (8 个回答) 已关闭
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 7 年前。 此帖子已于 8 个月
除了调试之外,是否有任何针对 c、c++ 或 c# 的测试工具,其工作原理类似于将独立函数复制粘贴到某个文本框,然后在其他文本框中输入参数? 最佳答案 也许您会考虑单元测试。我推荐你谷歌测试和谷歌模拟
我想在第二台显示器中移动一个窗口 (HWND)。问题是我尝试了很多方法,例如将分辨率加倍或输入负值,但它永远无法将窗口放在我的第二台显示器上。 关于如何在 C/C++/c# 中执行此操作的任何线索 最
我正在寻找 C/C++/C## 中不同类型 DES 的现有实现。我的运行平台是Windows XP/Vista/7。 我正在尝试编写一个 C# 程序,它将使用 DES 算法进行加密和解密。我需要一些实
很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visit the help center . 关闭 1
有没有办法强制将另一个 窗口置于顶部? 不是应用程序的窗口,而是另一个已经在系统上运行的窗口。 (Windows, C/C++/C#) 最佳答案 SetWindowPos(that_window_ha
假设您可以在 C/C++ 或 Csharp 之间做出选择,并且您打算在 Windows 和 Linux 服务器上运行同一服务器的多个实例,那么构建套接字服务器应用程序的最明智选择是什么? 最佳答案 如
你们能告诉我它们之间的区别吗? 顺便问一下,有什么叫C++库或C库的吗? 最佳答案 C++ 标准库 和 C 标准库 是 C++ 和 C 标准定义的库,提供给 C++ 和 C 程序使用。那是那些词的共同
下面的测试代码,我将输出信息放在注释中。我使用的是 gcc 4.8.5 和 Centos 7.2。 #include #include class C { public:
很难说出这里问的是什么。这个问题是含糊的、模糊的、不完整的、过于宽泛的或修辞性的,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开它,visit the help center 。 已关
我的客户将使用名为 annoucement 的结构/类与客户通信。我想我会用 C++ 编写服务器。会有很多不同的类继承annoucement。我的问题是通过网络将这些类发送给客户端 我想也许我应该使用
我在 C# 中有以下函数: public Matrix ConcatDescriptors(IList> descriptors) { int cols = descriptors[0].Co
我有一个项目要编写一个函数来对某些数据执行某些操作。我可以用 C/C++ 编写代码,但我不想与雇主共享该函数的代码。相反,我只想让他有权在他自己的代码中调用该函数。是否可以?我想到了这两种方法 - 在
我使用的是编写糟糕的第 3 方 (C/C++) Api。我从托管代码(C++/CLI)中使用它。有时会出现“访问冲突错误”。这使整个应用程序崩溃。我知道我无法处理这些错误[如果指针访问非法内存位置等,
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以便用事实和引用来回答。 关闭 7 年前。
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 要求我们推荐或查找工具、库或最喜欢的场外资源的问题对于 Stack Overflow 来说是偏离主题的,因为
我有一些 C 代码,将使用 P/Invoke 从 C# 调用。我正在尝试为这个 C 函数定义一个 C# 等效项。 SomeData* DoSomething(); struct SomeData {
这个问题已经有答案了: Why are these constructs using pre and post-increment undefined behavior? (14 个回答) 已关闭 6
我是一名优秀的程序员,十分优秀!