这是交易.如果我将代码保留为glGenBuffers(1,vertexBuffers),代码编译就可以了.但是,我认为它应该是2,因为vertexBuffers的大小为2.
我错过了什么吗?
代码如下:
-(void)drawRect:(NSRect)dirtyRect
{
// get program ID for shader program
GLuint programID = [self loadShaders];
// get new dimensions
NSSize dim = [self frame].size;
// clear the background with color
glClearColor(0.0, 0.0, 0.0, 0.4);
glDepthRange(0.1, 100.0);
glViewport(0, 0, dim.width, dim.height);
glClear(GL_COLOR_BUFFER_BIT);
// vertex data
GLfloat vertexPositionData[] = {-dim.width/2, -dim.height/2, 0.0, 5.0,
dim.width/2, -dim.height/2, 0.0, 5.0,
0.0, dim.height/2, 0.0, 5.0};
GLfloat vertexColorData[] = {1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.5, 0.0, 0.0, 1.0, 0.5};
GLfloat scaleMatrixData[] = {1/(dim.width/2), …Run Code Online (Sandbox Code Playgroud) 我使用Swift泛型键入了两个版本的离散卷积算法.整数版本有效.但是浮点版本存在乘法问题:
import Foundation
import Swift
func linconv<T: IntegerType>(signal_A signal_A: [T], signal_B: [T]) -> [T]? {
// guard
guard signal_A.isEmpty == false && signal_B.isEmpty == false else {
return nil
}
// reverse at least one of the arrays
//let signal_A_reversed = Array(signal_A.reverse())
// size of new array
let N = signal_A.count + signal_B.count - 1
// new array for result
var resultSignal = [T](count: N, repeatedValue: 0)
for n in 0..<N {
for j in 0...n {
if j < …Run Code Online (Sandbox Code Playgroud) 我有一个包含 uint16 和一个结构的联合,如下所示:
union pData {
uint16_t w1;
struct {
uint8_t d1 : 8;
uint8_t d2 : 4;
bool b1 : 1;
bool b2 : 1;
bool b3 : 1;
bool b4 : 1;
} bits;
};
Run Code Online (Sandbox Code Playgroud)
我的同事说这个便携有问题,但我不确定我买这个。可以请一些人解释(尽可能简单)这里的“错误”是什么?