这有点重复 this question .
我正在尝试制作一个无窗口控制台应用程序来检查支持的 OpenGL 版本。为此,我需要设置渲染上下文——但不创建窗口。我正在尝试使用我不会写入的桌面句柄。
我忘记在前面的示例中设置像素格式 - 这可能是创建渲染上下文失败的原因 - 但是即使设置了像素格式,我也无法激活它。 wglMakeCurrent(hDC, hRC) 只返回 0。
这是完整的源代码转储:
#include <iostream>
#include <GL/GLee.h>
#include <windows.h>
HDC hDC = NULL;
HGLRC hRC = NULL;
HWND hWnd = NULL;
HINSTANCE hInstance;
int res = 0;
int pf = 0;
PIXELFORMATDESCRIPTOR pfd = {
sizeof(PIXELFORMATDESCRIPTOR),
1, /* version */
PFD_DRAW_TO_WINDOW |
PFD_SUPPORT_OPENGL |
PFD_DOUBLEBUFFER,
PFD_TYPE_RGBA,
24, /* 24-bit color depth */
0, 0, 0, 0, 0, 0, /* color bits */
0, /* alpha buffer */
0, /* shift bit */
0, /* accumulation buffer */
0, 0, 0, 0, /* accum bits */
32, /* z-buffer */
0, /* stencil buffer */
0, /* auxiliary buffer */
PFD_MAIN_PLANE, /* main layer */
0, /* reserved */
0, 0, 0 /* layer masks */
};
std::string trash;
int main(int argc, char**argv) {
hInstance = GetModuleHandle(NULL); // Grab An Instance For Our Window
hWnd = GetDesktopWindow(); // Instead of CreateWindowEx
if (!(hDC = GetDC(hWnd))) {
std::cout << "Device context failed" << std::endl;
std::cout << std::endl << "Press ENTER to exit" << std::endl;
std::getline(std::cin, trash);
return 1;
}
// pixel format
pf = ChoosePixelFormat(hDC, &pfd);
res = SetPixelFormat(hDC, pf, &pfd);
if (!(hRC = wglCreateContext(hDC))) {
std::cout << "Render context failed" << std::endl;
std::cout << std::endl << "Press ENTER to exit" << std::endl;
std::getline(std::cin, trash);
return 1;
}
if(!wglMakeCurrent(hDC,hRC)) { // fail: wglMakeCurrent returns 0
std::cout << "Activating render context failed" << std::endl;
std::cout << std::endl << "Press ENTER to exit" << std::endl;
std::getline(std::cin, trash);
return 1;
}
std::cout << "OpenGL 1.2 support ... ";
if (GLEE_VERSION_1_2) {
std::cout << "OK" << std::endl;
} else {
std::cout << "FAIL" << std::endl;
}
std::cout << "OpenGL 1.3 support ... ";
if (GLEE_VERSION_1_3) {
std::cout << "OK" << std::endl;
} else {
std::cout << "FAIL" << std::endl;
}
std::cout << "OpenGL 1.4 support ... ";
if (GLEE_VERSION_1_4) {
std::cout << "OK" << std::endl;
} else {
std::cout << "FAIL" << std::endl;
}
std::cout << "OpenGL 1.5 support ... ";
if (GLEE_VERSION_1_5) {
std::cout << "OK" << std::endl;
} else {
std::cout << "FAIL" << std::endl;
}
std::cout << "OpenGL 2.0 support ... ";
if (GLEE_VERSION_2_0) {
std::cout << "OK" << std::endl;
} else {
std::cout << "FAIL" << std::endl;
}
std::cout << "OpenGL 2.1 support ... ";
if (GLEE_VERSION_2_1) {
std::cout << "OK" << std::endl;
} else {
std::cout << "FAIL" << std::endl;
}
std::cout << "OpenGL 3.0 support ... ";
if (GLEE_VERSION_3_0) {
std::cout << "OK" << std::endl;
} else {
std::cout << "FAIL" << std::endl;
}
std::cout << std::endl << "Press ENTER to exit" << std::endl;
std::getline(std::cin, trash);
// cleanup
wglMakeCurrent(NULL, NULL); /* make our context not current */
wglDeleteContext(hRC); /* delete the rendering context */
ReleaseDC(hWnd, hDC); /* release handle to DC */
return 0;
编辑: 我知道 wglMakeCurrent() 如果传递给它的句柄中的任何一个无效,或者如果要变为当前的渲染上下文目前对于另一个线程是当前的,但我不是真的很确定在这种情况下哪些是正确的。
最佳答案
不得在桌面窗口上创建 OpenGL 上下文。要创建 OpenGL 上下文,必须设置窗口的像素格式,这在桌面窗口上是严格禁止的。
如果您想进行离屏渲染,请使用 PBuffer 而不是窗口,或者创建一个不可见的窗口并使用帧缓冲区对象 (FBO) 作为渲染目标。
关于c++ - 不打开窗口的 OpenGL 上下文 - 当使用由 GetDesktopWindow 制作的 HWND 时,wglMakeCurrent 因 HDC 和 HGLRC 而失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/714707/
我的瘦服务器配置了nginx,我的ROR应用程序正在它们上运行。在我发布代码更新时运行thinrestart会给我的应用程序带来一些停机时间。我试图弄清楚如何优雅地重启正在运行的Thin实例,但找不到好的解决方案。有没有人能做到这一点? 最佳答案 #Restartjustthethinserverdescribedbythatconfigsudothin-C/etc/thin/mysite.ymlrestartNginx将继续运行并代理请求。如果您将Nginx设置为使用多个上游服务器,例如server{listen80;server
我已经构建了一些serverspec代码来在多个主机上运行一组测试。问题是当任何测试失败时,测试会在当前主机停止。即使测试失败,我也希望它继续在所有主机上运行。Rakefile:namespace:specdotask:all=>hosts.map{|h|'spec:'+h.split('.')[0]}hosts.eachdo|host|begindesc"Runserverspecto#{host}"RSpec::Core::RakeTask.new(host)do|t|ENV['TARGET_HOST']=hostt.pattern="spec/cfengine3/*_spec.r
如何将send与+=一起使用?a=20;a.send"+=",10undefinedmethod`+='for20:Fixnuma=20;a+=10=>30 最佳答案 恐怕你不能。+=不是方法,而是语法糖。参见http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_expressions.html它说Incommonwithmanyotherlanguages,Rubyhasasyntacticshortcut:a=a+2maybewrittenasa+=2.你能做的最好的事情是:
我正在尝试在Rails上安装ruby,到目前为止一切都已安装,但是当我尝试使用rakedb:create创建数据库时,我收到一个奇怪的错误:dyld:lazysymbolbindingfailed:Symbolnotfound:_mysql_get_client_infoReferencedfrom:/Library/Ruby/Gems/1.8/gems/mysql2-0.3.11/lib/mysql2/mysql2.bundleExpectedin:flatnamespacedyld:Symbolnotfound:_mysql_get_client_infoReferencedf
我需要一个非常简单的字符串验证器来显示第一个符号与所需格式不对应的位置。我想使用正则表达式,但在这种情况下,我必须找到与表达式相对应的字符串停止的位置,但我找不到可以做到这一点的方法。(这一定是一种相当简单的方法……也许没有?)例如,如果我有正则表达式:/^Q+E+R+$/带字符串:"QQQQEEE2ER"期望的结果应该是7 最佳答案 一个想法:你可以做的是标记你的模式并用可选的嵌套捕获组编写它:^(Q+(E+(R+($)?)?)?)?然后你只需要计算你获得的捕获组的数量就可以知道正则表达式引擎在模式中停止的位置,你可以确定匹配结束
我对如何计算通过{%assignvar=0%}赋值的变量加一完全感到困惑。这应该是最简单的任务。到目前为止,这是我尝试过的:{%assignamount=0%}{%forvariantinproduct.variants%}{%assignamount=amount+1%}{%endfor%}Amount:{{amount}}结果总是0。也许我忽略了一些明显的东西。也许有更好的方法。我想要存档的只是获取运行的迭代次数。 最佳答案 因为{{incrementamount}}将输出您的变量值并且不会影响{%assign%}定义的变量,我
我正在尝试在配备ARMv7处理器的SynologyDS215j上安装ruby2.2.4或2.3.0。我用了optware-ng安装gcc、make、openssl、openssl-dev和zlib。我根据README中的说明安装了rbenv(版本1.0.0-19-g29b4da7)和ruby-build插件。.这些是随optware-ng安装的软件包及其版本binutils-2.25.1-1gcc-5.3.0-6gconv-modules-2.21-3glibc-opt-2.21-4libc-dev-2.21-1libgmp-6.0.0a-1libmpc-1.0.2-1libm
我想用这两种语言中的任何一种(最好是ruby)制作一个窗口管理器。老实说,除了我需要加载某种X模块外,我不知道从哪里开始。因此,如果有人有线索,如果您能指出正确的方向,那就太好了。谢谢 最佳答案 XCB,X的下一代API使用XML格式定义X协议(protocol),并使用脚本生成特定语言绑定(bind)。它在概念上与SWIG类似,只是它描述的不是CAPI,而是X协议(protocol)。目前,C和Python存在绑定(bind)。理论上,Ruby端口只是编写一个从XML协议(protocol)定义语言到Ruby的翻译器的问题。生
一段时间以来,我一直在使用open_uri下拉ftp路径作为数据源,但突然发现我几乎连续不断地收到“530抱歉,允许的最大客户端数(95)已经连接。”我不确定我的代码是否有问题,或者是否是其他人在访问服务器,不幸的是,我无法真正确定谁有问题。本质上,我正在读取FTPURI:defself.read_uri(uri)beginuri=open(uri).readuri=="Error"?nil:urirescueOpenURI::HTTPErrornilendend我猜我需要在这里添加一些额外的错误处理代码...我想确保我采取一切预防措施来关闭所有连接,这样我的连接就不是问题所在,但是我
我在思考流量控制的最佳实践。我应该走哪条路?1)不要检查任何东西并让程序失败(更清晰的代码,自然的错误消息):defself.fetch(feed_id)feed=Feed.find(feed_id)feed.fetchend2)通过返回nil静默失败(但是,“CleanCode”说,你永远不应该返回null):defself.fetch(feed_id)returnunlessfeed_idfeed=Feed.find(feed_id)returnunlessfeedfeed.fetchend3)抛出异常(因为不按id查找feed是异常的):defself.fetch(feed_id