Browse Source

Full theming support on NT

master
despair 5 years ago
parent
commit
a08568ea1c
  1. 24
      src/graphics/components/ImageComponent.cpp
  2. 1
      src/graphics/components/ImageComponent.h
  3. 11
      src/pnm.cpp

24
src/graphics/components/ImageComponent.cpp

@ -1,10 +1,8 @@ @@ -1,10 +1,8 @@
#include "ImageComponent.h"
#include <cmath>
#include <iostream>
#include <cstring>
#include "../../pnm.h"
#ifdef __MINGW32__
#include "../../../anime.h"
#endif
ImageComponent::ImageComponent(std::string filename, const float rawX, const float rawY, const float rawWidth, const float rawHeight, const int passedWindowWidth, const int passedWindowHeight) : BoxComponent(rawX, rawY, rawWidth, rawHeight, 0x00000000, passedWindowWidth, passedWindowHeight) {
//std::cout << "ImageComponent::ImageComponent" << std::endl;
@ -16,17 +14,7 @@ ImageComponent::ImageComponent(std::string filename, const float rawX, const flo @@ -16,17 +14,7 @@ ImageComponent::ImageComponent(std::string filename, const float rawX, const flo
y = rawY;
width = rawWidth;
height = rawHeight;
#ifdef __MINGW32__ // the old "huge string" works fine with mingw
//
for (int py = 0; py < 1024; py++) {
for (int px = 0; px < 1024; px++) {
for (int i = 0; i < 4; i++) {
data[1023 - py][px][i] = anime.pixel_data[((px * 4) + (py * 4 * 1024)) + i];
}
}
}
#else // this is either non-Windows or Microsoft C/C++
RGBAPNMObject *anime = readPPM(filename.c_str());
if (!anime) {
std::cout << "Can't set up image component, couldn't read " << filename << std::endl;
@ -41,7 +29,6 @@ for (int py = 0; py < 1024; py++) { @@ -41,7 +29,6 @@ for (int py = 0; py < 1024; py++) {
anime = nullptr;
}
std::cout << "loading " << filename << " at " << loadWidth << "," << loadHeight << std::endl;
for (unsigned int py = 0; py < loadHeight; py++) {
for (unsigned int px = 0; px < loadWidth; px++) {
if (anime) {
@ -54,7 +41,6 @@ for (int py = 0; py < 1024; py++) { @@ -54,7 +41,6 @@ for (int py = 0; py < 1024; py++) {
}
}
}
#endif
float vx = rawX;
float vy = rawY;
@ -93,17 +79,11 @@ for (int py = 0; py < 1024; py++) { @@ -93,17 +79,11 @@ for (int py = 0; py < 1024; py++) {
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
#ifndef __MINGW32__
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, static_cast<int>(loadWidth), static_cast<int>(loadHeight), 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
#else
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1024, 1024, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
#endif
glGenerateMipmap(GL_TEXTURE_2D);
#ifndef __MINGW32__
if (anime) {
tlsf_free(anime->m_Ptr);
delete anime;
}
#endif
}

1
src/graphics/components/ImageComponent.h

@ -8,6 +8,7 @@ class ImageComponent : public BoxComponent { @@ -8,6 +8,7 @@ class ImageComponent : public BoxComponent {
public:
ImageComponent(std::string filename, const float rawX, const float rawY, const float rawWidth, const float rawHeight, const int passedWindowWidth, const int passedWindowHeight);
// FIXME: dynamically allocate this
// Soon. -despair
unsigned char data[1024][1024][4];
};

11
src/pnm.cpp

@ -4,6 +4,11 @@ @@ -4,6 +4,11 @@
#include <stdio.h>
#include <string.h>
#include <map>
#ifdef _WIN32
#include <io.h>
#include <windows.h>
#include <fcntl.h>
#endif
#include "environment/Environment.h"
@ -14,7 +19,7 @@ @@ -14,7 +19,7 @@
RGBAPNMObject * readPPM(const char* fileName) {
RGBAPNMObject *data=new RGBAPNMObject;
// open the file to read just the header reading
FILE* fr = fopen((Environment::getResourceDir() + "/" + fileName).c_str(), "r");
FILE* fr = fopen((Environment::getResourceDir() + "/" + fileName).c_str(), "rb");
if (!fr) {
std::cout << "Can't open " << fileName << std::endl;
return nullptr;
@ -99,10 +104,10 @@ RGBAPNMObject * readPPM(const char* fileName) { @@ -99,10 +104,10 @@ RGBAPNMObject * readPPM(const char* fileName) {
std::cout << "read " << fileName << " pnm/pam " << width << "," << height << "@" << static_cast<int>(bits) << "(" << bits/8 << ")" << "/" << data->maxColVal << std::endl;
// allocate array for pixels
char* pixels = reinterpret_cast<char*>(tlsf_malloc(size)); // used to be: new char[size];
char* pixels = static_cast<char*>(tlsf_malloc(size)); // used to be: new char[size];
// unformatted read of binary pixel data
res = fread(pixels, sizeof(int), size, fr);
res = fread(pixels, 1, size,fr);
data->m_Ptr = pixels;
// close file

Loading…
Cancel
Save