C ++错误C4700:未初始化的本地变量'i'使用

时间:2015-04-26 22:32:56

标签: c++ opengl

1>------ Build started: Project: RageBotGamingEngine, Configuration: Debug Win32 ------
1>  Sprite.cpp
1>c:\users\nha\documents\visual studio 2013\projects\ragebotgamingengine\ragebotgamingengine\sprite.cpp(51): error C4700: uninitialized local variable 'i' used
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

以上是输出日志所说的内容。 以下是可能涉及此问题的一些相关文件:

Sprite.cpp

#include "Sprite.h"
#include "Vertex.h"

#include <cstddef>

Sprite::Sprite()
{
_vboID = 0;
}


Sprite::~Sprite()
{
if (_vboID != 0) {
    glDeleteBuffers(1, &_vboID);
}
}

void Sprite::init(float x, float y, float width, float height) {
_x = x;
_y = y;
_width = width;
_height = height;

if (_vboID == 0) {
    glGenBuffers(1, &_vboID);
}

Vertex vertexData[6];

//First Triangle
vertexData[0].position.x = x + width;
vertexData[0].position.y = y + width;

vertexData[1].position.x = x;
vertexData[1].position.y = y + height;

vertexData[2].position.x = x;
vertexData[2].position.y = y;

//Second Triangle
vertexData[3].position.x = x;
vertexData[3].position.y = y;

vertexData[4].position.x = x + width;
vertexData[4].position.y = y;

vertexData[5].position.x = x + width;
vertexData[5].position.y = y + height;

for (int i; i < 6; i++) {
    vertexData[i].color.r = 255;
    vertexData[i].color.g = 0;
    vertexData[i].color.b = 255;
    vertexData[i].color.a = 255;
}

glBindBuffer(GL_ARRAY_BUFFER, _vboID);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertexData), vertexData, GL_STATIC_DRAW);

glBindBuffer(GL_ARRAY_BUFFER, 0);
}

void Sprite::draw() {
glBindBuffer(GL_ARRAY_BUFFER, _vboID);

glEnableVertexAttribArray(0);

//This is position attribute pointer
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)offsetof(Vertex, position));
//This is color attribute pointer
glVertexAttribPointer(1, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(Vertex), (void*)offsetof(Vertex, color));

glDrawArrays(GL_TRIANGLES, 0, 6);

glDisableVertexAttribArray(0);

glBindBuffer(GL_ARRAY_BUFFER, 0);
}

我试图找到问题,但我对OpenGL,SDL和&amp; C ++&amp;你可以想象这是一个巨大的麻烦,因为OpenGL wiki并不容易理解。是一致的。几乎任何帮助都非常需要和赞赏。

我正在尝试创建一个游戏引擎(显然我非常缺乏技能并且没有时间来开发这个项目)

1 个答案:

答案 0 :(得分:4)

trackingObject

应该是

for (int i; i < 6; i++)

你声明了变量&#39; i&#39;但是忘了初始化变量,所以它可以有任意值,不一定是&#39; 0&#39;