我尝试在没有来自界面构建器的xib文件的情况下运行XCode openGL ES模板.但仍然得到这一行[(EAGLView *)self.view setContext:context];
[UIView setContext:]:无法识别的选择器发送到实例0x4b1fac0由于未捕获的异常'NSInvalidArgumentException'终止应用程序,原因:' - [UIView setContext:]:无法识别的选择器发送到实例0x4b1fac0
我做错了什么?
main.mm
int main(int argc, char *argv[]) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, @"myAppDelegate");
[pool release];
return retVal;
}
Run Code Online (Sandbox Code Playgroud)
myAppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.viewController = [[myViewController alloc] initWithNibName:nil bundle:nil];
self.window.rootViewController = self.viewController;
return YES;
}
Run Code Online (Sandbox Code Playgroud)
myViewController.m
- (id)initWithNibName:(NSString *)nibName bundle:(NSBundle *)nibBundle
{
EAGLContext *aContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
if (!aContext) {
aContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES1];
}
if (!aContext) …
Run Code Online (Sandbox Code Playgroud) 为什么以下着色器,而不是在OpenGL(桌面)上编译 - 但在OpenGL ES 2.0(iPhone)上它运行良好(我使用相同的c/c ++代码来加载,编译和链接两个平台上的着色器).我的FragmentShader:
varying lowp vec4 colorVarying;
void main()
{
gl_FragColor = colorVarying;
}
Run Code Online (Sandbox Code Playgroud)
顶点着色器:
attribute vec4 position;
attribute vec4 color;
varying vec4 colorVarying;
uniform float translate;
void main()
{
gl_Position = position;
gl_Position.y += sin(translate) / 2.0;
colorVarying = color;
}
Run Code Online (Sandbox Code Playgroud)
编译日志如下所示:
Shader compile log:
ERROR: 0:9: 'lowp' : syntax error syntax error
ERROR: Parser found no code to compile in source strings.
Failed to compile fragment shaderProgram validate log:
Validation Failed: Program is not successfully …
Run Code Online (Sandbox Code Playgroud) 我只是想知道如何将我的 GLSL 着色器源文件(对于 OpenGL ES(iOs)/OpenGL with GLUT (Mac/Windows))与我的应用程序捆绑在一起。作为纯文本文件,我的软件的每个用户都可以轻松更改它们,而且我担心未定义的行为......在 iOS 上,我只是为我的着色器使用 XCodes“Copy Bundle Ressources”(然后从应用程序包中检索它们) ) - Visual Studio 是否有类似的可能性?
或者有没有更好的跨平台方式来做到这一点?
我想为点精灵制作一个着色器 - 到目前为止,一切都在 iOS 上运行。但不是在 Mac OS X 上。我的顶点着色器:
attribute vec4 position;
attribute vec4 color;
attribute vec2 texcoord;
varying vec4 colorVarying;
uniform mat4 modelViewProjectionMatrix;
uniform float pointSize;
void main()
{
gl_Position = modelViewProjectionMatrix * position;
colorVarying = color;
gl_PointSize = pointSize;
}
Run Code Online (Sandbox Code Playgroud)
我的片段着色器:
varying lowp vec4 colorVarying;
uniform lowp float textureFlag;
uniform sampler2D texture;
void main()
{
gl_FragColor = textureFlag * texture2D(texture, gl_PointCoord) * colorVarying +
(1.0 - textureFlag) * colorVarying;
}
Run Code Online (Sandbox Code Playgroud)
由于“gl_PointCoord”,片段着色器无法在 mac 上编译。在 Mac 上,我在着色器中添加了一个“#define lowp”作为预处理器。
如果我在着色器顶部添加一个“#version 120\n”,它在 …
我正在使用双缓冲在任意已打开的Windows 7窗口(例如Windows记事本窗口)中绘制Open GL内容(直接Win32 - 不使用GLUT,FreeGLUT,GLFW等).我有窗口句柄,可以按预期绘制我想要的内容,但我看到该glClear()
功能的奇怪行为.
我的理解是,该glClear()
功能应该只影响屏幕上由glScissor()
功能定义的区域内的像素.我已经定义了剪刀区域,glScissor()
然后启用了剪刀功能glEnable(GL_SCISSOR_TEST)
.glClearColor
设置为白色(0,0,0,1)
.我正在用glClear()
命令清除颜色和深度缓冲区.
当SwapBuffers()
命令以呈现在屏幕上被执行时,我选择了白色的清澈颜色被涂成剪刀区域内,因为我的要求,但窗口的其余部分OUTSIDE剪刀区域被涂成黑色,而不是把这些像素不变的我期望.
正如图中所示,剪刀区域(白色)和对象(3D立方体)的正确绘制,但记事本窗口的像素的其余部分设置为黑色,以前在记事本窗口中画任何东西覆盖了.
glClearColor(1.0f, 1.0f, 1.0f, 1.0f); // white background
glViewport(0, 0, 300, 300);
glScissor(0, 0, 250, 400);
glEnable(GL_SCISSOR_TEST);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//... draw cube inside glBegin()/glEnd()...
SwapBuffers(hDC);
Run Code Online (Sandbox Code Playgroud) 我有一个带循环的函数,我将在c ++代码中获得循环的扩展开发.我也有一个递归函数,我希望得到相同的.
我需要的一个例子:
for (i = 0; i <4; i++)
{
printf ("%d", "example");
}
Run Code Online (Sandbox Code Playgroud)
应该导致我需要
printf ("%d", "example");
printf ("%d", "example");
printf ("%d", "example");
printf ("%d", "example");
Run Code Online (Sandbox Code Playgroud)
这是一个简单的例子.但是我需要为更复杂的功能做这件事.我使用它的价值visual c++
.我不知道是否有这样的构建选项.
我尝试使用Visual Studio 2013为x64构建我的Win32 API项目.但路由的WindowProc回调无法正常工作.我正在使用SetWindowLongPtr/GetWindowLongPtr和GWLP_USERDATA来存储我的窗口的this指针.在过去,我使用SetWindowLong/GetWindowLong和GWL_USERDATA用于此目的 - 但这些在x64上消失了.但是在x86上一切仍然正常(即使使用SetWindowLongPtr/GetWindowLongPtr和GWLP_USERDATA),但在x64上,一旦我尝试访问我的成员函数WindowProc中的任何方法/成员,就会出现访问冲突.
#include <windows.h>
#include <stdio.h>
#include "main.h"
class Window{
public:
Window(const char* title, const float width, const float height){
char windowClass[255];
sprintf_s(windowClass, "WindowClass%s", title);
WNDCLASSEX wc;
ZeroMemory(&wc, sizeof(WNDCLASSEX));
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
wc.lpfnWndProc = WindowProcRouter;
wc.hInstance = nullptr;
wc.hCursor = LoadCursor(nullptr, IDC_ARROW);
wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
wc.lpszClassName = windowClass;
RegisterClassEx(&wc);
DWORD dwStyle = WS_CAPTION | WS_MINIMIZEBOX | WS_SYSMENU;
RECT WindowRect;
WindowRect.left = (long)0;
WindowRect.right = (long)width;
WindowRect.top = (long)0;
WindowRect.bottom …
Run Code Online (Sandbox Code Playgroud) 我试图从我自己的DLL调用一个函数,但根据DLL项目中的调用约定,我找不到ProcAddress或我的堆栈已损坏.它适用于第三方DLL,所以如果没有重大问题,我想在加载代码本身中不做任何改变.一个最小的例子:
#include <windows.h>
#include <cstdlib>
#include <iostream>
typedef long (__stdcall* tMyFunction)(int);
int main(int argc, char* argv[]){
HINSTANCE m_dllHandle = LoadLibrary("MyDll.dll");
if (m_dllHandle != NULL){
tMyFunction function = (tMyFunction)GetProcAddress(m_dllHandle, "myFunction");
if (function != NULL){
long value = function(1);
std::cout << value << std::endl;
}else{
std::cout << "GetProcAddress() failed" << std::endl;
}
FreeLibrary(m_dllHandle);
m_dllHandle = NULL;
}else{
std::cout << "LoadLibrary() failed" << std::endl;
}
system("pause");
return EXIT_SUCCESS;
}
Run Code Online (Sandbox Code Playgroud)
在DLL中:
extern "C" __declspec(dllexport) long __stdcall myFunction(int a){
return 10;
}
Run Code Online (Sandbox Code Playgroud)
结果:GetProcAddress()失败
dumpbin/EXPORTS - …
我正在尝试编写一个使用'get-iplayer'的脚本,并将用于不同的发行版.在debian上它位于'/ usr/bin/get-iplayer'中,但是在centos上,例如,它位于'/ usr/bin/get_iplayer'中.
我已经能够检查它是否安装 -
if [[ -f "/usr/bin/get-iplayer" ]] || [[ -f "/usr/bin/get_iplayer" ]]
then
echo ;
else
echo "$(tput setaf 1) $(tput setab 7) Error: 'get-iplayer' or 'get_iplayer' is not installed. Please install it. $(tput sgr 0)"
fi
Run Code Online (Sandbox Code Playgroud)
如果可以通过两个不同的名称知道,我怎么称它呢?
我有一个C函数,它使用私钥,并希望防止任何人读出此密钥.不仅来自二进制 - 而且来自源存储库.关键不是明文,但仍然应该尽可能难以访问它.我的计划是将此c文件编译为目标文件,并将此目标文件(带有混淆的privateKey数组)放入源存储库中.但我不确定我应该在哪个存储类/范围内放置密钥(本地堆栈变量,静态变量 - 本地/全局,...).
1.)全球静态
static unsigned char const privateKey[] = {
0x44, 0x8e, 0x54, 0xae, 0x64, 0x74, 0xbe, ...
};
void myFunction(){
//do something with privateKey
}
Run Code Online (Sandbox Code Playgroud)
2.)本地Stackvariable
void myFunction(){
unsigned char const privateKey[] = {
0x44, 0x8e, 0x54, 0xae, 0x64, 0x74, 0xbe, ...
};
//do something with privateKey
}
Run Code Online (Sandbox Code Playgroud)
3.)局部静态
void myFunction(){
static unsigned char const privateKey[] = {
0x44, 0x8e, 0x54, 0xae, 0x64, 0x74, 0xbe, ...
};
//do something with privateKey
}
Run Code Online (Sandbox Code Playgroud)
我只是用nm观察了这3个解决方案的目标文件 - 在第二个解决方案中,我甚至没有看到键的符号(但我担心使用调试器很容易读取密钥,因为它放在了在运行时堆栈).解决方案3在nm中看起来像:
00000000 …
Run Code Online (Sandbox Code Playgroud) 这个问题是关于Vulkan-Hpp中的异常处理(官方的Vulkan C++绑定).
我在没有VULKAN_HPP_NO_EXCEPTIONS
定义的情况下使用Vulkan-Hpp编写了一个小应用程序(并使用异常处理程序).但是在遇到这个stackoverflow问题(C++中的异常真的很慢)后,我开始担心在那里使用异常会受到惩罚.然后我发现了define VULKAN_HPP_NO_EXCEPTIONS
,但它完全改变了所有可能引发异常的调用的语法(因为返回值不同):这意味着,必须在开始实现之前决定使用VULKAN_HPP_NO_EXCEPTIONS
与否(即它们可以' t为"Debug"配置启用,轻松禁用"Release"配置.
如果通过定义
VULKAN_HPP_NO_EXCEPTIONS
ResultValue<SomeType>::type
是一个结构来禁用异常处理,该结构包含字段result和value中的返回值和错误代码.
即
surface = instance.createWin32SurfaceKHR(surfaceCreateInfo);
Run Code Online (Sandbox Code Playgroud)
变
vk::ResultValue<vk::SurfaceKHR> surfaceResult = instance.createWin32SurfaceKHR(surfaceCreateInfo);
if (surfaceResult.result == vk::Result::eSuccess) {
surface = surfaceResult.value;
}
Run Code Online (Sandbox Code Playgroud)
因此,考虑到VULKAN_HPP_NO_EXCEPTIONS
在开发的后期改变策略并非易事,我想知道我应该在哪些情况下使用VULKAN_HPP_NO_EXCEPTIONS
我的项目以及在哪些情况下我不应该这样做?
我认为除了个人品味/意见之外,必须有一些技术原理.
我正在从结构C转向OOP C++,:
在C++中声明/定义构造函数时,我经常发现" "符号作为运算符的特殊用法.我粗略地理解了这种风格的使用,但是有人用这个构造函数定义向我解释了精确的编程技术.
例如:1
class time_stamp
{
public:
time_stamp(time &t_time)
: m_time(t_time)
{}
~time_stamp()
{
m_time.update(); // as soon as I'm destroyed, update the time
}
private:
time &m_time;
};
Run Code Online (Sandbox Code Playgroud)
例如:2
class threaded_class
{
public:
threaded_class()
: m_stoprequested(false), m_running(false)
{
pthread_mutex_init(&m_mutex);
}
~threaded_class()
{
pthread_mutex_destroy(&m_mutex);
}
/** Some other member declarations */
}
Run Code Online (Sandbox Code Playgroud)
请解释我:
在以下2个例子time_stamp(time &t_time) : m_time(t_time){}
和下面的代码行中使用" "
threaded_class(): m_stoprequested(false), m_running(false)
{
pthread_mutex_init(&m_mutex);
}
Run Code Online (Sandbox Code Playgroud)