В моем первоначальном вопросе была некоторая путаница относительно того, что я действительно пытался сделать. В один раз недавнее редактирование моей переменной изображения составила 2 МБ, но я хотел, чтобы она была намного больше. изображение. Затем, используя команды клавиатуры, вы можете увидеть, что произойдет, если я сделаю множество вещей с этим массивом. Это определяется как Pixel Trans [ihei] [iwid], а STBI с радостью экономит транспонированный массив эффективно. Проблема в том, что это неэффективно просто иметь 2 -й огромный массив, который эффективно идентичен огромному массиву. Я делаю очень много разных вещей с изображениями, и я думаю, что я бы вызвал много ошибок, пытаясь использовать массив с X и Y назад. < /P>
Это полная программа GLFW3. Если вы используете GLFW или STBI, ваши файлы GLFW могут быть не в одних и тех же местах. Кроме того, компилятор, вероятно, потребуется, чтобы вы показали это, что. A Files для включения в параметры сборки. (Для GLFW/GLU/GL/GLEXT и т. Д.)
#define GLFW_DLL
#include
#include "../common/stb_image.h"
#include "../common/stb_image_write.h"
#include
#include
#include
using namespace std;
GLFWwindow* window = NULL;
//used by loading functions to replace Pixel image[iwid][ihei]
class Pixel//this could be a struct/vec4/I'm pretty sure I could even make
{//it work as an unsigned int
public:
unsigned char rgba[4]; //red green blue alpha
};
const int iwid = 13; //width of the normal array
const int ihei = 7; //height of the normal array
const int icha = 4; //color channels
Pixel image[iwid][ihei]; //iwid = x columns ihei = y rows
Pixel trans[ihei][iwid]; //transposed version that stbi likes
void Quad(int x, int y) //generic opengl function to draw the pixels
{
glVertex2i(x, y);
glVertex2i(x, y+1);
glVertex2i(x+1, y+1);
glVertex2i(x+1, y);
}
void Draw()//very basic drawing function to draw the pixels of the image
{
glBegin(GL_QUADS);
for(int x = 0; x < iwid; x++)
{
for(int y = 0; y < ihei; y++)
{
glColor4ubv(image[x][y].rgba);
Quad(x,y);
}
}
glEnd();
}
void SavePNGCorrectly(const char fname[20])
{//this only works for arrays smaller than maybe 2 MB (heap problem)
//anything larger causes heap problems. I have workarounds for that though.
unsigned char img[iwid*ihei*icha];
for(int y=0, i=0; y
Подробнее здесь: https://stackoverflow.com/questions/797 ... tored-in-a