Browse Source

make linux/gcc happy

master
Odilitime 5 years ago
parent
commit
ef115137f6
  1. 2
      src/interfaces/components/ImageComponent.cpp
  2. 21
      src/interfaces/graphical/renderers/glfw/opengl.cpp
  3. 14
      src/interfaces/graphical/renderers/glfw/opengl.h
  4. 6
      src/main.cpp
  5. 18
      src/parsers/images/netpbm/pnm.cpp
  6. 35
      src/parsers/images/tga/tga.cpp

2
src/interfaces/components/ImageComponent.cpp

@ -43,7 +43,7 @@ ImageComponent::ImageComponent(std::string filename, const float rawX, const flo @@ -43,7 +43,7 @@ ImageComponent::ImageComponent(std::string filename, const float rawX, const flo
if (anime) {
for (unsigned int i = 0; i < 4; i++) {
//data[1023 - py][px][i] = anime.pixel_data[((px * 4) + (py * 4 * 1024)) + i];
data[loadWidth - 1 - py][px][i] = static_cast<unsigned char>(anime->m_Ptr[((px * 4) + (py * 4 * loadWidth)) + i]);
data[loadWidth - 1 - py][px][i] = anime->m_Ptr[((px * 4) + (py * 4 * loadWidth)) + i];
}
} else {
data[loadWidth - 1 - py][px][3] = 0x00; // just make it all transparent for now

21
src/interfaces/graphical/renderers/glfw/opengl.cpp

@ -2,6 +2,7 @@ @@ -2,6 +2,7 @@
#include <iostream>
#include <cmath>
#include <cstring> // for memset
// maybe change to return std::pair<GLuint, GLuint>
bool initGL() {
@ -97,7 +98,8 @@ opengl_window_handle * opengl::createWindow(std::string title, Rect *position, u @@ -97,7 +98,8 @@ opengl_window_handle * opengl::createWindow(std::string title, Rect *position, u
// init GLEW
if (!initGLEW()) {
// FIXME: un do glfw create window
delete win;
// can't delete without a non-virtual deconstrcutor
//delete win;
return nullptr;
}
// init shaders?
@ -114,7 +116,7 @@ opengl_window_handle * opengl::createWindow(std::string title, Rect *position, u @@ -114,7 +116,7 @@ opengl_window_handle * opengl::createWindow(std::string title, Rect *position, u
// configure opengl coordinates
//std::cout << "position: " << position->w << "x" << position->h << std::endl;
glViewport(0, 0, (GLsizei)position->w, (GLsizei)position->h);
glViewport(0, 0, static_cast<GLsizei>(position->w), static_cast<GLsizei>(position->h));
GLenum glErr=glGetError();
if(glErr != GL_NO_ERROR) {
std::cout << "opengl::createWindow - glViewport - not ok: " << gluErrorString(glErr) << std::endl;
@ -233,8 +235,8 @@ void opengl_window_handle::clear() { @@ -233,8 +235,8 @@ void opengl_window_handle::clear() {
}
}
void opengl_window_handle::swapBuffers(opengl_window_handle *window) {
glfwSwapBuffers(window->window);
void opengl_window_handle::swapBuffers() {
glfwSwapBuffers(this->window);
GLenum glErr=glGetError();
if(glErr != GL_NO_ERROR) {
std::cout << "opengl::swapBuffers - not ok: " << glErr << std::endl;
@ -248,11 +250,12 @@ opengl_texture_handle* opengl_window_handle::createTexture(unsigned char* textur @@ -248,11 +250,12 @@ opengl_texture_handle* opengl_window_handle::createTexture(unsigned char* textur
// make sure texture size is a power of two
size_t potw = pow(2, ceil(log(w) / log(2)));
size_t poth = pow(2, ceil(log(h) / log(2)));
unsigned char data[poth][potw][4];
// FIXME: need to dynamically allocate for c++
unsigned char data[16384][16384][4];
memset(data, 0, poth * potw * 4);
// unflip texture
int loadWidth = w;
int loadHeight = h;
unsigned int loadWidth = static_cast<unsigned int>(w);
unsigned int loadHeight = static_cast<unsigned int>(h);
for (unsigned int py = 0; py < loadHeight; py++) {
for (unsigned int px = 0; px < loadWidth; px++) {
for (unsigned int i = 0; i < 4; i++) {
@ -372,10 +375,10 @@ void opengl_window_handle::drawTexturedBox(opengl_texture_handle *texture, Rect @@ -372,10 +375,10 @@ void opengl_window_handle::drawTexturedBox(opengl_texture_handle *texture, Rect
// 320, 320 is mid to top
// 0, 320 to bottom to top
//float vy = (int)position->h - (int)position->y - (int)this->height;
float vy = (int)position->h - (int)position->y;
float vy = static_cast<int>(position->h) - position->y;
float vWidth = position->w;
float vHeight = position->h;
std::cout << "placing box at " << (int)vx << "x" << (int)vy << " size: " << (int)vWidth << "x" << (int)vHeight << std::endl;
//std::cout << "placing box at " << (int)vx << "x" << (int)vy << " size: " << (int)vWidth << "x" << (int)vHeight << std::endl;
pointToViewport(vx, vy, this->width, this->height);
//std::cout << "vWidth before: " << (int)vWidth << std::endl;

14
src/interfaces/graphical/renderers/glfw/opengl.h

@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
#include <GL/glew.h>
#include <GLFW/glfw3.h>
#include <memory> // for unique_ptr
#include <vector>
#include <string>
#include "ShaderLoader.h"
@ -26,7 +27,8 @@ class window_handle { @@ -26,7 +27,8 @@ class window_handle {
public:
virtual void clear() { }
virtual void swapBuffers() { }
virtual texture_handle* createTexture(const unsigned char *texture, GLsizei w, GLsizei h) { return nullptr; }
// can we const texture?
virtual texture_handle* createTexture(unsigned char *texture, GLsizei w, GLsizei h) { return nullptr; }
virtual texture_handle* createTextureFromColor(const unsigned int hexColor) { return nullptr; }
virtual void drawTexturedBox(texture_handle *texture, Rect *position) {}
//
@ -36,6 +38,7 @@ public: @@ -36,6 +38,7 @@ public:
// maybe convert to interface?
class baseRenderer {
public:
virtual bool initialize() { return true; }
// maybe it should return a window object?
virtual window_handle *createWindow(std::string title, Rect *position, unsigned int flags) { return nullptr; }
@ -97,12 +100,16 @@ public: @@ -97,12 +100,16 @@ public:
class opengl; // few declr
bool initGL();
bool initGLEW();
class opengl_window_handle : public window_handle {
public:
void clear();
void swapBuffers(opengl_window_handle *window);
void swapBuffers();
opengl_texture_handle* createTexture(unsigned char* texture, GLsizei w, GLsizei h);
opengl_texture_handle* createTextureFromColor(const unsigned int hexColor);
using window_handle::drawTexturedBox;
void drawTexturedBox(opengl_texture_handle *texture, Rect *position);
// property
GLFWwindow *window;
@ -133,5 +140,8 @@ public: @@ -133,5 +140,8 @@ public:
GLFWcursor* cursorIbeam;
};
void pointToViewport(float&, float&, size_t, size_t);
void distanceToViewport(float&, float&, size_t, size_t);
#endif

6
src/main.cpp

@ -1,6 +1,6 @@ @@ -1,6 +1,6 @@
#include "CommandLineParams.h"
#include "graphics/components/TabbedComponent.h"
#include "graphics/components/InputComponent.h"
#include "interfaces/components/TabbedComponent.h"
#include "interfaces/components/InputComponent.h"
#include "environment/Environment.h"
#include "Log.h"
#include "URL.h"
@ -151,4 +151,4 @@ std::cout \ @@ -151,4 +151,4 @@ std::cout \
browser->loop();
return 0;
}
}

18
src/parsers/images/netpbm/pnm.cpp

@ -128,7 +128,7 @@ void writePBM4(const char *filename, const RGBAPNMObject &data) { @@ -128,7 +128,7 @@ void writePBM4(const char *filename, const RGBAPNMObject &data) {
//color[0] = data.m_Ptr[pos + 0]; /* red */
//color[1] = data.m_Ptr[pos + 1]; /* green */
//color[2] = data.m_Ptr[pos + 2]; /* blue */
color[0] = static_cast<unsigned char>(data.m_Ptr[pos + 3]); /* alpha */
color[0] = data.m_Ptr[pos + 3]; /* alpha */
fwrite(color, 1, 1, fp);
}
}
@ -142,7 +142,7 @@ void writePGM5(const char *filename, const RGBAPNMObject &data) { @@ -142,7 +142,7 @@ void writePGM5(const char *filename, const RGBAPNMObject &data) {
for (unsigned int i = 0; i < data.width; ++i) {
static unsigned char color[1];
unsigned int pos = ((i * 4) + (j * 4 * 1024));
color[0] = static_cast<unsigned char>(data.m_Ptr[pos + 0]); /* red */
color[0] = data.m_Ptr[pos + 0]; /* red */
//color[1] = data.m_Ptr[pos + 1]; /* green */
//color[2] = data.m_Ptr[pos + 2]; /* blue */
//color[3] = data.m_Ptr[pos + 3]; /* alpha */
@ -159,9 +159,9 @@ void writePPM6(const char *filename, const RGBAPNMObject &data) { @@ -159,9 +159,9 @@ void writePPM6(const char *filename, const RGBAPNMObject &data) {
for (unsigned int i = 0; i < data.width; ++i) {
static unsigned char color[3];
unsigned int pos = ((i * 4) + (j * 4 * 1024));
color[0] = static_cast<unsigned char>(data.m_Ptr[pos + 0]); /* red */
color[1] = static_cast<unsigned char>(data.m_Ptr[pos + 1]); /* green */
color[2] = static_cast<unsigned char>(data.m_Ptr[pos + 2]); /* blue */
color[0] = data.m_Ptr[pos + 0]; /* red */
color[1] = data.m_Ptr[pos + 1]; /* green */
color[2] = data.m_Ptr[pos + 2]; /* blue */
//color[3] = data.m_Ptr[pos + 3]; /* alpha */
fwrite(color, 1, 3, fp);
}
@ -176,10 +176,10 @@ void writePPM8(const char *filename, const RGBAPNMObject &data) { @@ -176,10 +176,10 @@ void writePPM8(const char *filename, const RGBAPNMObject &data) {
for (unsigned int i = 0; i < data.width; ++i) {
static unsigned char color[4];
unsigned int pos = ((i * 4) + (j * 4 * 1024));
color[0] = static_cast<unsigned char>(data.m_Ptr[pos + 0]); /* red */
color[1] = static_cast<unsigned char>(data.m_Ptr[pos + 1]); /* green */
color[2] = static_cast<unsigned char>(data.m_Ptr[pos + 2]); /* blue */
color[3] = static_cast<unsigned char>(data.m_Ptr[pos + 3]); /* alpha */
color[0] = data.m_Ptr[pos + 0]; /* red */
color[1] = data.m_Ptr[pos + 1]; /* green */
color[2] = data.m_Ptr[pos + 2]; /* blue */
color[3] = data.m_Ptr[pos + 3]; /* alpha */
fwrite(color, 1, 4, fp);
}
}

35
src/parsers/images/tga/tga.cpp

@ -17,6 +17,7 @@ BitMapObject *LoadTGAFile(const char *filename) { @@ -17,6 +17,7 @@ BitMapObject *LoadTGAFile(const char *filename) {
long imageSize;
int colorMode;
unsigned char colorSwap;
size_t res;
// Open the TGA file.
filePtr = fopen(filename, "rb");
@ -25,12 +26,12 @@ BitMapObject *LoadTGAFile(const char *filename) { @@ -25,12 +26,12 @@ BitMapObject *LoadTGAFile(const char *filename) {
}
// Read the two first bytes we don't need.
fread(&ucharBad, sizeof(unsigned char), 1, filePtr);
fread(&ucharBad, sizeof(unsigned char), 1, filePtr);
res = fread(&ucharBad, sizeof(unsigned char), 1, filePtr);
res = fread(&ucharBad, sizeof(unsigned char), 1, filePtr);
// Which type of image gets stored in imageTypeCode.
unsigned char imageTypeCode;
fread(&imageTypeCode, sizeof(unsigned char), 1, filePtr);
res = fread(&imageTypeCode, sizeof(unsigned char), 1, filePtr);
// For our purposes, the type code should be 2 (uncompressed RGBA image)
// or 3 (uncompressed black-and-white images).
@ -40,36 +41,36 @@ BitMapObject *LoadTGAFile(const char *filename) { @@ -40,36 +41,36 @@ BitMapObject *LoadTGAFile(const char *filename) {
}
// Read 13 bytes of data we don't need.
fread(&sintBad, sizeof(short int), 1, filePtr);
fread(&sintBad, sizeof(short int), 1, filePtr);
fread(&ucharBad, sizeof(unsigned char), 1, filePtr);
fread(&sintBad, sizeof(short int), 1, filePtr);
fread(&sintBad, sizeof(short int), 1, filePtr);
res = fread(&sintBad, sizeof(short int), 1, filePtr);
res = fread(&sintBad, sizeof(short int), 1, filePtr);
res = fread(&ucharBad, sizeof(unsigned char), 1, filePtr);
res = fread(&sintBad, sizeof(short int), 1, filePtr);
res = fread(&sintBad, sizeof(short int), 1, filePtr);
// Read the image's width and height.
short int imageWidth;
short int imageHeight;
fread(&imageWidth, sizeof(short int), 1, filePtr);
fread(&imageHeight, sizeof(short int), 1, filePtr);
tgaFile->width = imageWidth;
tgaFile->height = imageHeight;
res = fread(&imageWidth, sizeof(short int), 1, filePtr);
res = fread(&imageHeight, sizeof(short int), 1, filePtr);
tgaFile->width = static_cast<size_t>(imageWidth);
tgaFile->height = static_cast<size_t>(imageHeight);
// Read the bit depth.
unsigned char bitCount;
fread(&bitCount, sizeof(unsigned char), 1, filePtr);
res = fread(&bitCount, sizeof(unsigned char), 1, filePtr);
// Read one byte of data we don't need.
fread(&ucharBad, sizeof(unsigned char), 1, filePtr);
res = fread(&ucharBad, sizeof(unsigned char), 1, filePtr);
// Color mode -> 3 = BGR, 4 = BGRA.
colorMode = bitCount / 8;
imageSize = tgaFile->width * tgaFile->height * colorMode;
imageSize = static_cast<long int>(tgaFile->width * tgaFile->height * static_cast<long unsigned int>(colorMode & 32));
// Allocate memory for the image data.
tgaFile->imageData = (unsigned char*)malloc(sizeof(unsigned char)*imageSize);
tgaFile->imageData = static_cast<unsigned char*>(malloc(sizeof(unsigned char) * static_cast<long unsigned int>(imageSize)));
// Read the image data.
fread(tgaFile->imageData, sizeof(unsigned char), imageSize, filePtr);
res = fread(tgaFile->imageData, sizeof(unsigned char), static_cast<long unsigned int>(imageSize), filePtr);
// Change from BGR to RGB so OpenGL can read the image data.
for (int imageIdx = 0; imageIdx < imageSize; imageIdx += colorMode) {

Loading…
Cancel
Save