diff --git a/OpenGL/OpenGL.vcxproj b/OpenGL/OpenGL.vcxproj index 078b3a1..1a15d8b 100644 --- a/OpenGL/OpenGL.vcxproj +++ b/OpenGL/OpenGL.vcxproj @@ -128,10 +128,6 @@ -<<<<<<< HEAD -======= - ->>>>>>> 11f63887e9573415f2ed2fed84986ab4c4bd0b4f diff --git a/OpenGL/OpenGL.vcxproj.filters b/OpenGL/OpenGL.vcxproj.filters index df3a1e8..57d7367 100644 --- a/OpenGL/OpenGL.vcxproj.filters +++ b/OpenGL/OpenGL.vcxproj.filters @@ -5,12 +5,6 @@ -<<<<<<< HEAD -======= - - helpers - ->>>>>>> 11f63887e9573415f2ed2fed84986ab4c4bd0b4f diff --git a/OpenGL/headers/display.h b/OpenGL/headers/display.h new file mode 100644 index 0000000..45a5ab2 --- /dev/null +++ b/OpenGL/headers/display.h @@ -0,0 +1,19 @@ +#pragma once + +#include +#include + +class Display { +public: + Display(int width, int height, const std::string& title); + + void Update(); + bool isClosed(); + + virtual ~Display(); +private: + SDL_Window* m_window; + SDL_GLContext m_glContext; + + bool m_isClosed; +}; diff --git a/OpenGL/headers/mesh.h b/OpenGL/headers/mesh.h new file mode 100644 index 0000000..e1a371e --- /dev/null +++ b/OpenGL/headers/mesh.h @@ -0,0 +1,21 @@ +#pragma once + +#include +#include + +class Mesh { +public: + Mesh(GLfloat *vertices, unsigned int numVerticies); + void Draw(); + virtual ~Mesh(); +private: + enum { + POSITION_VB, + NUM_BUFFERS + }; + + unsigned int m_VAO; + unsigned int m_VBO[NUM_BUFFERS]; + + unsigned int m_drawCount; +}; diff --git a/OpenGL/headers/shader.h b/OpenGL/headers/shader.h new file mode 100644 index 0000000..511fd7a --- /dev/null +++ b/OpenGL/headers/shader.h @@ -0,0 +1,20 @@ +#pragma once + +#include +#include +#include + +class Shader { +public: + Shader(); + void Bind(); + virtual ~Shader(); +private: + static const unsigned int NUM_SHADERS = 2; + GLuint CreateShader(const std::string& text, GLenum shaderType); + + GLuint m_program; + GLuint m_shaders[NUM_SHADERS]; + // 0 = vertex, 1 = fragment +}; + diff --git a/OpenGL/main.cpp b/OpenGL/main.cpp index b4b8484..58973e6 100644 --- a/OpenGL/main.cpp +++ b/OpenGL/main.cpp @@ -9,7 +9,6 @@ #undef main int main(int argc, char** argv) { -<<<<<<< HEAD Display display(600, 600, "Crumpet Engine"); glClearColor(0.1f, 0.45f, 0.9f, 1.0f); @@ -26,17 +25,6 @@ int main(int argc, char** argv) { // 0.5f, -0.5f, 0.0f, 1.0f, 0.0f, 0.0f, // bottom right //-0.5f, -0.5f, 0.0f, 0.0f, 1.0f, 0.0f, // bottom left // 0.0f, 0.5f, 0.0f, 0.0f, 0.0f, 1.0f // top -======= - Display display(800, 800, "Crumpet Engine"); - glClearColor(0.1f, 0.45f, 0.9f, 1.0f); - - GLfloat vertices[] = { - // positions // colors // texture coords - 0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, // top right - 0.5f, -0.5f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, // bottom right - -0.5f,-0.5f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, // bottom left - -0.5f, 0.5f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f // top left ->>>>>>> 11f63887e9573415f2ed2fed84986ab4c4bd0b4f }; unsigned int indices[] = { @@ -44,7 +32,6 @@ int main(int argc, char** argv) { 1, 2, 3 // second triangle }; -<<<<<<< HEAD enum class ShaderMode { SHADER_TEXURE, SHADER_COLOUR, @@ -56,11 +43,6 @@ int main(int argc, char** argv) { Mesh mesh(vertices, indices, sizeof(vertices) / sizeof(vertices[0])); Texture chanceCube("C:/Users/Ben/Desktop/crumpet-engine/resources/textures/chance-cube.jpg"); -======= - Mesh mesh(vertices, indices, sizeof(vertices) / sizeof(vertices[0])); - Shader shader("E:/Games/Practicing/OpenGL/resources/shaders/simple2d"); - Texture chanceCube("E:/Games/Practicing/OpenGL/resources/textures/chance-cube.jpg"); ->>>>>>> 11f63887e9573415f2ed2fed84986ab4c4bd0b4f Shader shader("C:/Users/Ben/Desktop/crumpet-engine/resources/shaders/simple2d"); @@ -84,10 +66,7 @@ int main(int argc, char** argv) { } shader.Bind(); -<<<<<<< HEAD -======= ->>>>>>> 11f63887e9573415f2ed2fed84986ab4c4bd0b4f chanceCube.Bind(0); mesh.Draw(); diff --git a/OpenGL/mesh.cpp b/OpenGL/mesh.cpp index 8c8adc5..1b6344f 100644 --- a/OpenGL/mesh.cpp +++ b/OpenGL/mesh.cpp @@ -4,16 +4,11 @@ Mesh::Mesh(GLfloat *vertices, unsigned int *indices, unsigned int numVerticies) m_drawCount = numVerticies; glGenVertexArrays(1, &m_VAO); - glGenBuffers(1, &m_VBO); - glGenBuffers(1, &m_EBO); - glBindVertexArray(m_VAO); - glBindBuffer(GL_ARRAY_BUFFER, m_VBO); - glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW); - - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_EBO); - glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW); + glGenBuffers(NUM_BUFFERS, m_VBO); + glBindBuffer(GL_ARRAY_BUFFER, m_VBO[POSITION_VB]); + glBufferData(GL_ARRAY_BUFFER, numVerticies * sizeof(vertices[0]), vertices, GL_STATIC_DRAW); // position attribute glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)0); @@ -21,19 +16,10 @@ Mesh::Mesh(GLfloat *vertices, unsigned int *indices, unsigned int numVerticies) // color attribute glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)(3 * sizeof(float))); glEnableVertexAttribArray(1); -<<<<<<< HEAD // texture attribute glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)(6 * sizeof(float))); glEnableVertexAttribArray(2); -======= - // texture coord attribute - glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)(6 * sizeof(float))); - glEnableVertexAttribArray(2); - - glBindVertexArray(0); - ->>>>>>> 11f63887e9573415f2ed2fed84986ab4c4bd0b4f std::cout << "Mesh loaded successfully" << std::endl; } diff --git a/OpenGL/mesh.h b/OpenGL/mesh.h index f11f711..4c98ceb 100644 --- a/OpenGL/mesh.h +++ b/OpenGL/mesh.h @@ -13,13 +13,11 @@ public: private: enum { POSITION_VB, - NUM_BUFFERS, - TEXCOORD_VB + NUM_BUFFERS }; unsigned int m_VAO; - unsigned int m_VBO; - unsigned int m_EBO; + unsigned int m_VBO[NUM_BUFFERS]; unsigned int m_drawCount; }; diff --git a/OpenGL/stb_image.h b/OpenGL/stb_image.h index caa043c..7e59832 100644 --- a/OpenGL/stb_image.h +++ b/OpenGL/stb_image.h @@ -1,4 +1,3 @@ -<<<<<<< HEAD /* stb_image - v2.19 - public domain image loader - http://nothings.org/stb no warranty implied; use at your own risk @@ -118,28 +117,12 @@ RECENT REVISION HISTORY: // int x,y,n; // unsigned char *data = stbi_load(filename, &x, &y, &n, 0); // // ... process data if not NULL ... -======= -//// begin header file //////////////////////////////////////////////////// -// -// Limitations: -// - no jpeg progressive support -// - non-HDR formats support 8-bit samples only (jpeg, png) -// - no delayed line count (jpeg) -- IJG doesn't support either -// - no 1-bit BMP -// - GIF always returns *comp=4 -// -// Basic usage (see HDR discussion below): -// int x,y,n; -// unsigned char *data = stbi_load(filename, &x, &y, &n, 0); -// // ... process data if not NULL ... ->>>>>>> 11f63887e9573415f2ed2fed84986ab4c4bd0b4f // // ... x = width, y = height, n = # 8-bit components per pixel ... // // ... replace '0' with '1'..'4' to force that many components per pixel // // ... but 'n' will always be the number that it would have been if you said 0 // stbi_image_free(data) // // Standard parameters: -<<<<<<< HEAD // int *x -- outputs image width in pixels // int *y -- outputs image height in pixels // int *channels_in_file -- outputs # of image components in image file @@ -157,22 +140,6 @@ RECENT REVISION HISTORY: // output otherwise. E.g. if you set desired_channels to 4, you will always // get RGBA output, but you can check *channels_in_file to see if it's trivially // opaque because e.g. there were only 3 channels in the source image. -======= -// int *x -- outputs image width in pixels -// int *y -- outputs image height in pixels -// int *comp -- outputs # of image components in image file -// int req_comp -- if non-zero, # of image components requested in result -// -// The return value from an image loader is an 'unsigned char *' which points -// to the pixel data. The pixel data consists of *y scanlines of *x pixels, -// with each pixel consisting of N interleaved 8-bit components; the first -// pixel pointed to is top-left-most in the image. There is no padding between -// image scanlines or between pixels, regardless of format. The number of -// components N is 'req_comp' if req_comp is non-zero, or *comp otherwise. -// If req_comp is non-zero, *comp has the number of components that _would_ -// have been output otherwise. E.g. if you set req_comp to 4, you will always -// get RGBA output, but you can check *comp to easily see if it's opaque. ->>>>>>> 11f63887e9573415f2ed2fed84986ab4c4bd0b4f // // An output image with N components has the following components interleaved // in this order in each pixel: @@ -184,24 +151,16 @@ RECENT REVISION HISTORY: // 4 red, green, blue, alpha // // If image loading fails for any reason, the return value will be NULL, -<<<<<<< HEAD // and *x, *y, *channels_in_file will be unchanged. The function // stbi_failure_reason() can be queried for an extremely brief, end-user // unfriendly explanation of why the load failed. Define STBI_NO_FAILURE_STRINGS // to avoid compiling these strings at all, and STBI_FAILURE_USERMSG to get slightly -======= -// and *x, *y, *comp will be unchanged. The function stbi_failure_reason() -// can be queried for an extremely brief, end-user unfriendly explanation -// of why the load failed. Define STBI_NO_FAILURE_STRINGS to avoid -// compiling these strings at all, and STBI_FAILURE_USERMSG to get slightly ->>>>>>> 11f63887e9573415f2ed2fed84986ab4c4bd0b4f // more user-friendly ones. // // Paletted PNG, BMP, GIF, and PIC images are automatically depalettized. // // =========================================================================== // -<<<<<<< HEAD // Philosophy // // stb libraries are designed with the following priorities: @@ -255,20 +214,6 @@ RECENT REVISION HISTORY: // If for some reason you do not want to use any of SIMD code, or if // you have issues compiling it, you can disable it entirely by // defining STBI_NO_SIMD. -======= -// iPhone PNG support: -// -// By default we convert iphone-formatted PNGs back to RGB; nominally they -// would silently load as BGR, except the existing code should have just -// failed on such iPhone PNGs. But you can disable this conversion by -// by calling stbi_convert_iphone_png_to_rgb(0), in which case -// you will always just get the native iphone "format" through. -// -// Call stbi_set_unpremultiply_on_load(1) as well to force a divide per -// pixel to remove any premultiplied alpha *only* if the image file explicitly -// says there's premultiplied data (currently only happens in iPhone images, -// and only if iPhone convert-to-rgb processing is on). ->>>>>>> 11f63887e9573415f2ed2fed84986ab4c4bd0b4f // // =========================================================================== // @@ -291,11 +236,7 @@ RECENT REVISION HISTORY: // (linear) floats to preserve the full dynamic range: // // float *data = stbi_loadf(filename, &x, &y, &n, 0); -<<<<<<< HEAD // -======= -// ->>>>>>> 11f63887e9573415f2ed2fed84986ab4c4bd0b4f // If you load LDR images through this interface, those images will // be promoted to floating point values, run through the inverse of // constants corresponding to the above: @@ -312,7 +253,6 @@ RECENT REVISION HISTORY: // // =========================================================================== // -<<<<<<< HEAD // iPhone PNG support: // // By default we convert iphone-formatted PNGs back to RGB, even though @@ -366,37 +306,12 @@ RECENT REVISION HISTORY: #ifndef STBI_NO_STDIO #include #endif // STBI_NO_STDIO -======= -// I/O callbacks -// -// I/O callbacks allow you to read from arbitrary sources, like packaged -// files or some other source. Data read from callbacks are processed -// through a small internal buffer (currently 128 bytes) to try to reduce -// overhead. -// -// The three functions you must define are "read" (reads some bytes of data), -// "skip" (skips some bytes of data), "eof" (reports if the stream is at the end). - - -#ifndef STBI_NO_STDIO - -#if defined(_MSC_VER) && _MSC_VER >= 0x1400 -#define _CRT_SECURE_NO_WARNINGS // suppress bogus warnings about fopen() -#endif - -#include -#endif ->>>>>>> 11f63887e9573415f2ed2fed84986ab4c4bd0b4f #define STBI_VERSION 1 enum { -<<<<<<< HEAD STBI_default = 0, // only used for desired_channels -======= - STBI_default = 0, // only used for req_comp ->>>>>>> 11f63887e9573415f2ed2fed84986ab4c4bd0b4f STBI_grey = 1, STBI_grey_alpha = 2, @@ -405,24 +320,18 @@ enum }; typedef unsigned char stbi_uc; -<<<<<<< HEAD typedef unsigned short stbi_us; -======= ->>>>>>> 11f63887e9573415f2ed2fed84986ab4c4bd0b4f #ifdef __cplusplus extern "C" { #endif -<<<<<<< HEAD #ifdef STB_IMAGE_STATIC #define STBIDEF static #else #define STBIDEF extern #endif -======= ->>>>>>> 11f63887e9573415f2ed2fed84986ab4c4bd0b4f ////////////////////////////////////////////////////////////////////////////// // // PRIMARY API - works on images of any type @@ -432,7 +341,6 @@ extern "C" { // load image by filename, open file, or memory buffer // -<<<<<<< HEAD typedef struct { int(*read) (void *user, char *data, int size); // fill 'data' with 'size' bytes. return number of bytes actually read @@ -501,54 +409,11 @@ extern "C" { #ifndef STBI_NO_STDIO STBIDEF int stbi_is_hdr(char const *filename); STBIDEF int stbi_is_hdr_from_file(FILE *f); -======= - extern stbi_uc *stbi_load_from_memory(stbi_uc const *buffer, int len, int *x, int *y, int *comp, int req_comp); - -#ifndef STBI_NO_STDIO - extern stbi_uc *stbi_load(char const *filename, int *x, int *y, int *comp, int req_comp); - extern stbi_uc *stbi_load_from_file(FILE *f, int *x, int *y, int *comp, int req_comp); - // for stbi_load_from_file, file pointer is left pointing immediately after image -#endif - - typedef struct - { - int(*read) (void *user, char *data, int size); // fill 'data' with 'size' bytes. return number of bytes actually read - void(*skip) (void *user, unsigned n); // skip the next 'n' bytes - int(*eof) (void *user); // returns nonzero if we are at end of file/data - } stbi_io_callbacks; - - extern stbi_uc *stbi_load_from_callbacks(stbi_io_callbacks const *clbk, void *user, int *x, int *y, int *comp, int req_comp); - -#ifndef STBI_NO_HDR - extern float *stbi_loadf_from_memory(stbi_uc const *buffer, int len, int *x, int *y, int *comp, int req_comp); - -#ifndef STBI_NO_STDIO - extern float *stbi_loadf(char const *filename, int *x, int *y, int *comp, int req_comp); - extern float *stbi_loadf_from_file(FILE *f, int *x, int *y, int *comp, int req_comp); -#endif - - extern float *stbi_loadf_from_callbacks(stbi_io_callbacks const *clbk, void *user, int *x, int *y, int *comp, int req_comp); - - extern void stbi_hdr_to_ldr_gamma(float gamma); - extern void stbi_hdr_to_ldr_scale(float scale); - - extern void stbi_ldr_to_hdr_gamma(float gamma); - extern void stbi_ldr_to_hdr_scale(float scale); -#endif // STBI_NO_HDR - - // stbi_is_hdr is always defined - extern int stbi_is_hdr_from_callbacks(stbi_io_callbacks const *clbk, void *user); - extern int stbi_is_hdr_from_memory(stbi_uc const *buffer, int len); -#ifndef STBI_NO_STDIO - extern int stbi_is_hdr(char const *filename); - extern int stbi_is_hdr_from_file(FILE *f); ->>>>>>> 11f63887e9573415f2ed2fed84986ab4c4bd0b4f #endif // STBI_NO_STDIO // get a VERY brief reason for failure // NOT THREADSAFE -<<<<<<< HEAD STBIDEF const char *stbi_failure_reason(void); // free the loaded image -- this is just free() @@ -565,21 +430,6 @@ extern "C" { STBIDEF int stbi_info_from_file(FILE *f, int *x, int *y, int *comp); STBIDEF int stbi_is_16_bit(char const *filename); STBIDEF int stbi_is_16_bit_from_file(FILE *f); -======= - extern const char *stbi_failure_reason(void); - - // free the loaded image -- this is just free() - extern void stbi_image_free(void *retval_from_stbi_load); - - // get image dimensions & components without fully decoding - extern int stbi_info_from_memory(stbi_uc const *buffer, int len, int *x, int *y, int *comp); - extern int stbi_info_from_callbacks(stbi_io_callbacks const *clbk, void *user, int *x, int *y, int *comp); - -#ifndef STBI_NO_STDIO - extern int stbi_info(char const *filename, int *x, int *y, int *comp); - extern int stbi_info_from_file(FILE *f, int *x, int *y, int *comp); - ->>>>>>> 11f63887e9573415f2ed2fed84986ab4c4bd0b4f #endif @@ -587,7 +437,6 @@ extern "C" { // for image formats that explicitly notate that they have premultiplied alpha, // we just return the colors as stored in the file. set this flag to force // unpremultiplication. results are undefined if the unpremultiply overflow. -<<<<<<< HEAD STBIDEF void stbi_set_unpremultiply_on_load(int flag_true_if_should_unpremultiply); // indicate whether we should process iphone images back to canonical format, @@ -7717,49 +7566,3 @@ ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ------------------------------------------------------------------------------ */ -======= - extern void stbi_set_unpremultiply_on_load(int flag_true_if_should_unpremultiply); - - // indicate whether we should process iphone images back to canonical format, - // or just pass them through "as-is" - extern void stbi_convert_iphone_png_to_rgb(int flag_true_if_should_convert); - - - // ZLIB client - used by PNG, available for other purposes - - extern char *stbi_zlib_decode_malloc_guesssize(const char *buffer, int len, int initial_size, int *outlen); - extern char *stbi_zlib_decode_malloc(const char *buffer, int len, int *outlen); - extern int stbi_zlib_decode_buffer(char *obuffer, int olen, const char *ibuffer, int ilen); - - extern char *stbi_zlib_decode_noheader_malloc(const char *buffer, int len, int *outlen); - extern int stbi_zlib_decode_noheader_buffer(char *obuffer, int olen, const char *ibuffer, int ilen); - - - // define faster low-level operations (typically SIMD support) -#ifdef STBI_SIMD - typedef void(*stbi_idct_8x8)(stbi_uc *out, int out_stride, short data[64], unsigned short *dequantize); - // compute an integer IDCT on "input" - // input[x] = data[x] * dequantize[x] - // write results to 'out': 64 samples, each run of 8 spaced by 'out_stride' - // CLAMP results to 0..255 - typedef void(*stbi_YCbCr_to_RGB_run)(stbi_uc *output, stbi_uc const *y, stbi_uc const *cb, stbi_uc const *cr, int count, int step); - // compute a conversion from YCbCr to RGB - // 'count' pixels - // write pixels to 'output'; each pixel is 'step' bytes (either 3 or 4; if 4, write '255' as 4th), order R,G,B - // y: Y input channel - // cb: Cb input channel; scale/biased to be 0..255 - // cr: Cr input channel; scale/biased to be 0..255 - - extern void stbi_install_idct(stbi_idct_8x8 func); - extern void stbi_install_YCbCr_to_RGB(stbi_YCbCr_to_RGB_run func); -#endif // STBI_SIMD - - -#ifdef __cplusplus -} -#endif - -// -// -//// end header file ///////////////////////////////////////////////////// ->>>>>>> 11f63887e9573415f2ed2fed84986ab4c4bd0b4f diff --git a/OpenGL/texture.cpp b/OpenGL/texture.cpp index d6f480a..23261c4 100644 --- a/OpenGL/texture.cpp +++ b/OpenGL/texture.cpp @@ -1,20 +1,12 @@ -<<<<<<< HEAD #define STB_IMAGE_IMPLEMENTATION #include "stb_image.h" #include "texture.h" -======= -#include "texture.h" -#include "stb_image.h" ->>>>>>> 11f63887e9573415f2ed2fed84986ab4c4bd0b4f #include #include Texture::Texture(std::string fileName) { -<<<<<<< HEAD stbi_set_flip_vertically_on_load(true); -======= ->>>>>>> 11f63887e9573415f2ed2fed84986ab4c4bd0b4f int width, height, numComponents; unsigned char* imageData = stbi_load(fileName.c_str(), &width, &height, &numComponents, 4); diff --git a/resources/shaders/simple2d_fragment.glsl b/resources/shaders/simple2d_fragment.glsl index 4f8c938..3aea5d2 100644 --- a/resources/shaders/simple2d_fragment.glsl +++ b/resources/shaders/simple2d_fragment.glsl @@ -7,10 +7,5 @@ in vec2 TexCoord; uniform sampler2D ourTexture; void main() { -<<<<<<< HEAD FragColor = texture(ourTexture, TexCoord) * vec4(ourColor, 1.0); -} -======= - FragColor = texture(ourTexture, TexCoord); -} ->>>>>>> 11f63887e9573415f2ed2fed84986ab4c4bd0b4f +} \ No newline at end of file diff --git a/resources/shaders/simple2d_vertex.glsl b/resources/shaders/simple2d_vertex.glsl index b638ad9..7de44d9 100644 --- a/resources/shaders/simple2d_vertex.glsl +++ b/resources/shaders/simple2d_vertex.glsl @@ -10,8 +10,4 @@ void main() { gl_Position = vec4(aPos, 1.0); ourColor = aColor; TexCoord = aTexCoord; -<<<<<<< HEAD -} -======= -} ->>>>>>> 11f63887e9573415f2ed2fed84986ab4c4bd0b4f +} \ No newline at end of file