Merge pull request #14 from raysan5/master
Integrate master into develop branch
This commit is contained in:
commit
e37ef10595
19 changed files with 406 additions and 229 deletions
|
@ -13,11 +13,13 @@ Release: raylib 1.2.2 (31 December 2014)
|
|||
[core] Corrected bug on input handling (keyboard and mouse)
|
||||
[textures] Renamed function CreateTexture() to LoadTextureFromImage()
|
||||
[textures] Added function ConvertToPOT()
|
||||
[rlgl] Added support for color tint on models on GL 3.3+ and ES2
|
||||
[rlgl] Added support for normals on models
|
||||
[models] Corrected bug on DrawBillboard()
|
||||
[models] Corrected bug on DrawHeightmap()
|
||||
[models] Renamed LoadCubesmap() to LoadCubicmap()
|
||||
[audio] Added function LoadSoundFromWave()
|
||||
[makefile] Added support for Linux compiling
|
||||
[makefile] Added support for Linux and OSX compiling
|
||||
[stb] Updated to latest headers versions
|
||||
[*] Lots of tweaks around
|
||||
|
||||
|
|
|
@ -27,8 +27,8 @@ int main()
|
|||
PlayMusicStream("resources/audio/guitar_noodling.ogg"); // Play music stream
|
||||
|
||||
int framesCounter = 0;
|
||||
float volume = 1.0;
|
||||
float timePlayed = 0;
|
||||
//float volume = 1.0;
|
||||
|
||||
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
|
|
@ -2,6 +2,16 @@
|
|||
*
|
||||
* raylib [core] example - Basic window
|
||||
*
|
||||
* Welcome to raylib!
|
||||
*
|
||||
* To test examples, just press F6 and execute raylib_compile_execute script
|
||||
* Note that compiled executable is placed in the same folder as .c file
|
||||
*
|
||||
* You can find all basic examples on C:\raylib\raylib\examples folder or
|
||||
* raylib official webpage: www.raylib.com
|
||||
*
|
||||
* Enjoy using raylib. :)
|
||||
*
|
||||
* This example has been created using raylib 1.0 (www.raylib.com)
|
||||
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||
*
|
||||
|
|
|
@ -26,6 +26,23 @@
|
|||
# WARNING: To compile examples to HTML5, they must be redesigned to use emscripten.h and emscripten_set_main_loop()
|
||||
PLATFORM ?= PLATFORM_DESKTOP
|
||||
|
||||
# determine SUBPLATFORM in case PLATFORM_DESKTOP selected
|
||||
ifeq ($(PLATFORM),PLATFORM_DESKTOP)
|
||||
# No uname.exe on MinGW!, but OS=Windows_NT on Windows! ifeq ($(UNAME),Msys) -> Windows
|
||||
ifeq ($(OS),Windows_NT)
|
||||
SUBPLATFORM=WINDOWS
|
||||
else
|
||||
UNAMEOS:=$(shell uname)
|
||||
ifeq ($(UNAMEOS),Linux)
|
||||
SUBPLATFORM=LINUX
|
||||
else
|
||||
ifeq ($(UNAMEOS),Darwin)
|
||||
SUBPLATFORM=OSX
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
# define compiler: gcc for C program, define as g++ for C++
|
||||
ifeq ($(PLATFORM),PLATFORM_WEB)
|
||||
# define emscripten compiler
|
||||
|
@ -44,14 +61,14 @@ ifeq ($(PLATFORM),PLATFORM_RPI)
|
|||
else
|
||||
CFLAGS = -O2 -Wall -std=c99
|
||||
endif
|
||||
#CFLAGSEXTRA = -Wextra -Wmissing-prototypes -Wstrict-prototypes
|
||||
|
||||
ifeq ($(PLATFORM),PLATFORM_WEB)
|
||||
CFLAGS = -O1 -Wall -std=c99 -s USE_GLFW=3 -s ASSERTIONS=1 --preload-file resources
|
||||
#-s ALLOW_MEMORY_GROWTH=1 # to allow memory resizing
|
||||
#-s TOTAL_MEMORY=16777216 # to specify heap memory size (default = 16MB)
|
||||
endif
|
||||
|
||||
#CFLAGSEXTRA = -Wextra -Wmissing-prototypes -Wstrict-prototypes
|
||||
|
||||
# define any directories containing required header files
|
||||
ifeq ($(PLATFORM),PLATFORM_RPI)
|
||||
INCLUDES = -I. -I../src -I/opt/vc/include -I/opt/vc/include/interface/vcos/pthreads
|
||||
|
@ -63,28 +80,35 @@ endif
|
|||
ifeq ($(PLATFORM),PLATFORM_RPI)
|
||||
LFLAGS = -L. -L../src -L/opt/vc/lib
|
||||
else
|
||||
LFLAGS = -L. -L../src
|
||||
LFLAGS = -L. -L../src -L../external/glfw3/lib/ -I../external/openal_soft/lib/
|
||||
endif
|
||||
|
||||
# define any libraries to link into executable
|
||||
# if you want to link libraries (libname.so or libname.a), use the -lname
|
||||
ifeq ($(PLATFORM),PLATFORM_RPI)
|
||||
# libraries for Raspberry Pi compiling
|
||||
# NOTE: OpenAL Soft library should be installed (libopenal1 package)
|
||||
LIBS = -lraylib -lGLESv2 -lEGL -lpthread -lrt -lm -lbcm_host -lopenal
|
||||
else
|
||||
ifeq ($(PLATFORM),PLATFORM_DESKTOP_LINUX)
|
||||
ifeq ($(PLATFORM),PLATFORM_DESKTOP)
|
||||
ifeq ($(SUBPLATFORM),LINUX)
|
||||
# libraries for Debian GNU/Linux desktop compiling
|
||||
# requires the following packages:
|
||||
# libglfw3-dev libopenal-dev libglew-dev libegl1-mesa-dev
|
||||
LIBS = -lraylib -lglfw -lGLEW -lGL -lopenal
|
||||
else
|
||||
endif
|
||||
ifeq ($(SUBPLATFORM),OSX)
|
||||
# libraries for OS X 10.9 desktop compiling
|
||||
# requires the following packages:
|
||||
# libglfw3-dev libopenal-dev libglew-dev libegl1-mesa-dev
|
||||
LIBS = -lraylib -lglfw -framework OpenGL -framework OpenAl -framework Cocoa
|
||||
|
||||
else
|
||||
# libraries for Windows desktop compiling
|
||||
# NOTE: GLFW3 and OpenAL Soft libraries should be installed
|
||||
LIBS = -lraylib -lglfw3 -lglew32 -lopengl32 -lopenal32 -lgdi32
|
||||
endif
|
||||
endif
|
||||
ifeq ($(PLATFORM),PLATFORM_RPI)
|
||||
# libraries for Raspberry Pi compiling
|
||||
# NOTE: OpenAL Soft library should be installed (libopenal1 package)
|
||||
LIBS = -lraylib -lGLESv2 -lEGL -lpthread -lrt -lm -lbcm_host -lopenal
|
||||
endif
|
||||
|
||||
ifeq ($(PLATFORM),PLATFORM_WEB)
|
||||
LIBS = ../src/libraylib.bc
|
||||
endif
|
||||
|
@ -265,20 +289,24 @@ audio_music_stream: audio_music_stream.c
|
|||
|
||||
# clean everything
|
||||
clean:
|
||||
ifeq ($(PLATFORM),PLATFORM_RPI)
|
||||
ifeq ($(PLATFORM),PLATFORM_DESKTOP)
|
||||
ifeq ($(SUBPLATFORM),OSX)
|
||||
rm -f *.o
|
||||
# find . -executable -delete
|
||||
else
|
||||
ifeq ($(PLATFORM),PLATFORM_DESKTOP_LINUX)
|
||||
else
|
||||
ifeq ($(SUBPLATFORM),LINUX)
|
||||
find . -type f -executable -delete
|
||||
rm -f *.o
|
||||
else
|
||||
else
|
||||
del *.o *.exe
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
ifeq ($(PLATFORM),PLATFORM_RPI)
|
||||
find . -type f -executable -delete
|
||||
rm -f *.o
|
||||
endif
|
||||
ifeq ($(PLATFORM),PLATFORM_WEB)
|
||||
del *.o *.html *.js
|
||||
else
|
||||
del *.o *.exe
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
@echo Cleaning done
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
/*******************************************************************************************
|
||||
*
|
||||
* raylib [models] example - Cubesmap loading and drawing
|
||||
* raylib [models] example - Cubicmap loading and drawing
|
||||
*
|
||||
* This example has been created using raylib 1.2 (www.raylib.com)
|
||||
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
|
||||
|
@ -23,9 +23,9 @@ int main()
|
|||
// Define the camera to look into our 3d world
|
||||
Camera camera = {{ 7.0, 7.0, 7.0 }, { 0.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 }};
|
||||
|
||||
Image img = LoadImage("resources/cubesmap.png"); // Load cubesmap image (RAM)
|
||||
Texture2D texture = CreateTexture(img, false); // Convert image to texture (VRAM)
|
||||
Model map = LoadCubesmap(img); // Load cubesmap model
|
||||
Image img = LoadImage("resources/cubicmap.png"); // Load cubesmap image (RAM)
|
||||
Texture2D texture = LoadTextureFromImage(img, false); // Convert image to texture (VRAM)
|
||||
Model map = LoadCubicmap(img); // Load cubicmap model
|
||||
SetModelTexture(&map, texture); // Bind texture to model
|
||||
Vector3 mapPosition = { -1, 0.0, -1 }; // Set model position
|
||||
|
Before Width: | Height: | Size: 27 KiB After Width: | Height: | Size: 27 KiB |
|
@ -24,7 +24,7 @@ int main()
|
|||
Camera camera = {{ 10.0, 12.0, 10.0 }, { 0.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 }};
|
||||
|
||||
Image img = LoadImage("resources/heightmap.png"); // Load heightmap image (RAM)
|
||||
Texture2D texture = CreateTexture(img, false); // Convert image to texture (VRAM)
|
||||
Texture2D texture = LoadTextureFromImage(img, false); // Convert image to texture (VRAM)
|
||||
Model map = LoadHeightmap(img, 4); // Load heightmap model
|
||||
SetModelTexture(&map, texture); // Bind texture to model
|
||||
Vector3 mapPosition = { -4, 0.0, -4 }; // Set model position
|
||||
|
|
Before Width: | Height: | Size: 173 B After Width: | Height: | Size: 173 B |
|
@ -25,7 +25,7 @@ int main()
|
|||
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
|
||||
|
||||
Image img = LoadImage("resources/raylib_logo.png"); // Loaded in CPU memory (RAM)
|
||||
Texture2D texture = CreateTexture(img, false); // Image converted to texture, GPU memory (VRAM)
|
||||
Texture2D texture = LoadTextureFromImage(img, false); // Image converted to texture, GPU memory (VRAM)
|
||||
|
||||
UnloadImage(img); // Once image has been converted to texture and uploaded to VRAM, it can be unloaded from RAM
|
||||
//---------------------------------------------------------------------------------------
|
||||
|
|
|
@ -27,7 +27,7 @@ int main()
|
|||
// with mipmaps option set to true on CreateTexture()
|
||||
|
||||
Image image = LoadImage("resources/raylib_logo.png"); // Load image to CPU memory (RAM)
|
||||
Texture2D texture = CreateTexture(image, true); // Create texture and generate mipmaps
|
||||
Texture2D texture = LoadTextureFromImage(image, true); // Create texture and generate mipmaps
|
||||
|
||||
UnloadImage(image); // Once texture has been created, we can unload image data from RAM
|
||||
//--------------------------------------------------------------------------------------
|
||||
|
|
BIN
external/glfw3/lib/libglfw.3.0.dylib
vendored
Executable file
BIN
external/glfw3/lib/libglfw.3.0.dylib
vendored
Executable file
Binary file not shown.
1
external/glfw3/lib/libglfw.3.dylib
vendored
Symbolic link
1
external/glfw3/lib/libglfw.3.dylib
vendored
Symbolic link
|
@ -0,0 +1 @@
|
|||
libglfw.3.0.dylib
|
1
external/glfw3/lib/libglfw.dylib
vendored
Symbolic link
1
external/glfw3/lib/libglfw.dylib
vendored
Symbolic link
|
@ -0,0 +1 @@
|
|||
libglfw.3.dylib
|
18
src/core.c
18
src/core.c
|
@ -170,7 +170,6 @@ static Matrix downscaleView; // Matrix to downscale view (in case
|
|||
|
||||
#if defined(PLATFORM_DESKTOP) || defined(PLATFORM_RPI) || defined(PLATFORM_WEB)
|
||||
static const char *windowTitle; // Window text title...
|
||||
static char configFlags = 0;
|
||||
|
||||
static bool customCursor = false; // Tracks if custom cursor has been set
|
||||
static bool cursorOnScreen = false; // Tracks if cursor is inside client area
|
||||
|
@ -204,6 +203,7 @@ static double updateTime, drawTime; // Time measures for update and draw
|
|||
static double frameTime; // Time measure for one frame
|
||||
static double targetTime = 0.0; // Desired time for one frame, if 0 not applied
|
||||
|
||||
static char configFlags = 0;
|
||||
static bool showLogo = false;
|
||||
|
||||
//----------------------------------------------------------------------------------
|
||||
|
@ -261,6 +261,8 @@ static void CommandCallback(struct android_app *app, int32_t cmd); //
|
|||
// Initialize Window and Graphics Context (OpenGL)
|
||||
void InitWindow(int width, int height, const char *title)
|
||||
{
|
||||
TraceLog(INFO, "Initializing raylib...");
|
||||
|
||||
// Store window title (could be useful...)
|
||||
windowTitle = title;
|
||||
|
||||
|
@ -298,6 +300,8 @@ void InitWindow(int width, int height, const char *title)
|
|||
// Android activity initialization
|
||||
void InitWindow(int width, int height, struct android_app *state)
|
||||
{
|
||||
TraceLog(INFO, "Initializing raylib...");
|
||||
|
||||
app_dummy();
|
||||
|
||||
screenWidth = width;
|
||||
|
@ -451,12 +455,6 @@ int GetScreenHeight(void)
|
|||
return screenHeight;
|
||||
}
|
||||
|
||||
// Get the last key pressed
|
||||
int GetKeyPressed(void)
|
||||
{
|
||||
return lastKeyPressed;
|
||||
}
|
||||
|
||||
// Sets Background Color
|
||||
void ClearBackground(Color color)
|
||||
{
|
||||
|
@ -670,6 +668,12 @@ bool IsKeyUp(int key)
|
|||
else return false;
|
||||
}
|
||||
|
||||
// Get the last key pressed
|
||||
int GetKeyPressed(void)
|
||||
{
|
||||
return lastKeyPressed;
|
||||
}
|
||||
|
||||
// Detect if a mouse button has been pressed once
|
||||
bool IsMouseButtonPressed(int button)
|
||||
{
|
||||
|
|
40
src/makefile
40
src/makefile
|
@ -25,6 +25,23 @@
|
|||
# possible platforms: PLATFORM_DESKTOP PLATFORM_RPI PLATFORM_WEB
|
||||
PLATFORM ?= PLATFORM_DESKTOP
|
||||
|
||||
# determine SUBPLATFORM in case PLATFORM_DESKTOP selected
|
||||
ifeq ($(PLATFORM),PLATFORM_DESKTOP)
|
||||
# No uname.exe on MinGW!, but OS=Windows_NT on Windows! ifeq ($(UNAME),Msys) -> Windows
|
||||
ifeq ($(OS),Windows_NT)
|
||||
SUBPLATFORM=WINDOWS
|
||||
else
|
||||
UNAMEOS:=$(shell uname)
|
||||
ifeq ($(UNAMEOS),Linux)
|
||||
SUBPLATFORM=LINUX
|
||||
else
|
||||
ifeq ($(UNAMEOS),Darwin)
|
||||
SUBPLATFORM=OSX
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
# define raylib graphics api depending on selected platform
|
||||
ifeq ($(PLATFORM),PLATFORM_RPI)
|
||||
# define raylib graphics api to use (on RPI, OpenGL ES 2.0 must be used)
|
||||
|
@ -34,7 +51,6 @@ else
|
|||
GRAPHICS ?= GRAPHICS_API_OPENGL_11
|
||||
#GRAPHICS = GRAPHICS_API_OPENGL_33 # Uncomment to use OpenGL 3.3
|
||||
endif
|
||||
|
||||
ifeq ($(PLATFORM),PLATFORM_WEB)
|
||||
GRAPHICS = GRAPHICS_API_OPENGL_ES2
|
||||
endif
|
||||
|
@ -66,7 +82,7 @@ endif
|
|||
ifeq ($(PLATFORM),PLATFORM_RPI)
|
||||
INCLUDES = -I. -I/opt/vc/include -I/opt/vc/include/interface/vcos/pthreads
|
||||
else
|
||||
INCLUDES = -I.
|
||||
INCLUDES = -I. -I../external/glfw3/include/ -I../external/openal_soft/include/
|
||||
endif
|
||||
|
||||
# define all object files required
|
||||
|
@ -127,19 +143,23 @@ stb_vorbis.o: stb_vorbis.c
|
|||
|
||||
# clean everything
|
||||
clean:
|
||||
ifeq ($(PLATFORM),PLATFORM_RPI)
|
||||
ifeq ($(PLATFORM),PLATFORM_DESKTOP)
|
||||
ifeq ($(SUBPLATFORM),OSX)
|
||||
rm -f *.o libraylib.a
|
||||
else
|
||||
ifeq ($(PLATFORM),PLATFORM_DESKTOP_LINUX)
|
||||
else
|
||||
ifeq ($(SUBPLATFORM),LINUX)
|
||||
find . -type f -executable -delete
|
||||
rm -f *.o libraylib.a
|
||||
else
|
||||
else
|
||||
del *.o libraylib.a
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
ifeq ($(PLATFORM),PLATFORM_RPI)
|
||||
rm -f *.o libraylib.a
|
||||
endif
|
||||
ifeq ($(PLATFORM),PLATFORM_WEB)
|
||||
del *.o libraylib.bc
|
||||
else
|
||||
del *.o libraylib.a
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
@echo Cleaning done
|
||||
|
||||
|
|
|
@ -711,7 +711,7 @@ Model LoadHeightmap(Image heightmap, float maxHeight)
|
|||
vData.vertices = (float *)malloc(vData.vertexCount * 3 * sizeof(float));
|
||||
vData.normals = (float *)malloc(vData.vertexCount * 3 * sizeof(float));
|
||||
vData.texcoords = (float *)malloc(vData.vertexCount * 2 * sizeof(float));
|
||||
vData.colors = (unsigned char *)malloc(vData.vertexCount * 4 * sizeof(unsigned char));
|
||||
vData.colors = (unsigned char *)malloc(vData.vertexCount * 4 * sizeof(unsigned char)); // Not used...
|
||||
|
||||
int vCounter = 0; // Used to count vertices float by float
|
||||
int tcCounter = 0; // Used to count texcoords float by float
|
||||
|
@ -795,9 +795,9 @@ Model LoadHeightmap(Image heightmap, float maxHeight)
|
|||
}
|
||||
|
||||
// Fill color data
|
||||
// NOTE: Not used any more... just one plain color defined at DrawModel()
|
||||
for (int i = 0; i < (4*vData.vertexCount); i++) vData.colors[i] = 255;
|
||||
|
||||
|
||||
// NOTE: At this point we have all vertex, texcoord, normal data for the model in vData struct
|
||||
|
||||
Model model = rlglLoadModel(vData);
|
||||
|
@ -1071,9 +1071,10 @@ Model LoadCubicmap(Image cubesmap)
|
|||
vData.vertices = (float *)malloc(vData.vertexCount * 3 * sizeof(float));
|
||||
vData.normals = (float *)malloc(vData.vertexCount * 3 * sizeof(float));
|
||||
vData.texcoords = (float *)malloc(vData.vertexCount * 2 * sizeof(float));
|
||||
vData.colors = (unsigned char *)malloc(vData.vertexCount * 4 * sizeof(unsigned char));
|
||||
vData.colors = (unsigned char *)malloc(vData.vertexCount * 4 * sizeof(unsigned char)); // Not used...
|
||||
|
||||
// Fill color data
|
||||
// NOTE: Not used any more... just one plain color defined at DrawModel()
|
||||
for (int i = 0; i < (4*vData.vertexCount); i++) vData.colors[i] = 255;
|
||||
|
||||
int fCounter = 0;
|
||||
|
@ -1510,6 +1511,7 @@ static VertexData LoadOBJ(const char *fileName)
|
|||
if (numTexCoords == 0) for (int i = 0; i < (2*vData.vertexCount); i++) vData.texcoords[i] = 0.0f;
|
||||
|
||||
// NOTE: We set all vertex colors to white
|
||||
// NOTE: Not used any more... just one plain color defined at DrawModel()
|
||||
for (int i = 0; i < (4*vData.vertexCount); i++) vData.colors[i] = 255;
|
||||
|
||||
// Now we can free temp mid* arrays
|
||||
|
|
352
src/rlgl.c
352
src/rlgl.c
|
@ -32,14 +32,21 @@
|
|||
#include <stdlib.h> // Declares malloc() and free() for memory management, rand()
|
||||
|
||||
#if defined(GRAPHICS_API_OPENGL_11)
|
||||
#ifdef __APPLE__ // OpenGL include for OSX
|
||||
#include <OpenGL/gl.h>
|
||||
#else
|
||||
#include <GL/gl.h> // Basic OpenGL include
|
||||
//#include <OpenGL/gl.h> // Basic OpenGL include (OSX)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(GRAPHICS_API_OPENGL_33)
|
||||
#define GLEW_STATIC
|
||||
#ifdef __APPLE__ // OpenGL include for OSX
|
||||
#include <OpenGL/gl3.h>
|
||||
#else
|
||||
#include <GL/glew.h> // Extensions loading lib
|
||||
//#include "glad.h" // TODO: Other extensions loading lib? --> REVIEW
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(GRAPHICS_API_OPENGL_ES2)
|
||||
|
@ -145,12 +152,17 @@ static VertexPositionColorBuffer triangles; // No texture support
|
|||
static VertexPositionColorTextureIndexBuffer quads;
|
||||
|
||||
// Vetex-Fragment Shader Program ID
|
||||
static GLuint shaderProgram;
|
||||
static GLuint defaultShaderProgram, simpleShaderProgram;
|
||||
|
||||
// Shader program attibutes binding locations
|
||||
static GLuint vertexLoc, texcoordLoc, colorLoc;
|
||||
static GLuint projectionMatrixLoc, modelviewMatrixLoc;
|
||||
static GLuint textureLoc;
|
||||
// Default Shader program attibutes binding locations
|
||||
static GLuint defaultVertexLoc, defaultTexcoordLoc, defaultColorLoc;
|
||||
static GLuint defaultProjectionMatrixLoc, defaultModelviewMatrixLoc;
|
||||
static GLuint defaultTextureLoc;
|
||||
|
||||
// Simple Shader program attibutes binding locations
|
||||
static GLuint simpleVertexLoc, simpleTexcoordLoc, simpleNormalLoc, simpleColorLoc;
|
||||
static GLuint simpleProjectionMatrixLoc, simpleModelviewMatrixLoc;
|
||||
static GLuint simpleTextureLoc;
|
||||
|
||||
// Vertex Array Objects (VAO)
|
||||
static GLuint vaoLines, vaoTriangles, vaoQuads;
|
||||
|
@ -189,13 +201,14 @@ unsigned int whiteTexture;
|
|||
// Module specific Functions Declaration
|
||||
//----------------------------------------------------------------------------------
|
||||
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
||||
static GLuint LoadDefaultShaders(void);
|
||||
static GLuint LoadDefaultShader(void);
|
||||
static GLuint LoadSimpleShader(void);
|
||||
static void InitializeBuffers(void);
|
||||
static void InitializeBuffersGPU(void);
|
||||
static void UpdateBuffers(void);
|
||||
|
||||
// Shader files loading (external) - Not used but useful...
|
||||
static GLuint LoadShaders(char *vertexFileName, char *fragmentFileName);
|
||||
// Custom shader files loading (external)
|
||||
static GLuint LoadCustomShader(char *vertexFileName, char *fragmentFileName);
|
||||
static char *TextFileRead(char *fn);
|
||||
#endif
|
||||
|
||||
|
@ -836,20 +849,38 @@ void rlglInit(void)
|
|||
for (int i = 0; i < MATRIX_STACK_SIZE; i++) stack[i] = MatrixIdentity();
|
||||
|
||||
// Init default Shader (GLSL 110) -> Common for GL 3.3+ and ES2
|
||||
shaderProgram = LoadDefaultShaders();
|
||||
//shaderProgram = LoadShaders("simple150.vert", "simple150.frag");
|
||||
defaultShaderProgram = LoadDefaultShader();
|
||||
simpleShaderProgram = LoadSimpleShader();
|
||||
//customShaderProgram = LoadShaders("simple150.vert", "simple150.frag");
|
||||
|
||||
// Get handles to GLSL input vars locations
|
||||
vertexLoc = glGetAttribLocation(shaderProgram, "vertexPosition");
|
||||
texcoordLoc = glGetAttribLocation(shaderProgram, "vertexTexCoord");
|
||||
colorLoc = glGetAttribLocation(shaderProgram, "vertexColor");
|
||||
// Get handles to GLSL input vars locations for defaultShaderProgram
|
||||
//-------------------------------------------------------------------
|
||||
defaultVertexLoc = glGetAttribLocation(defaultShaderProgram, "vertexPosition");
|
||||
defaultTexcoordLoc = glGetAttribLocation(defaultShaderProgram, "vertexTexCoord");
|
||||
defaultColorLoc = glGetAttribLocation(defaultShaderProgram, "vertexColor");
|
||||
|
||||
// Get handles to GLSL uniform vars locations (vertex-shader)
|
||||
modelviewMatrixLoc = glGetUniformLocation(shaderProgram, "modelviewMatrix");
|
||||
projectionMatrixLoc = glGetUniformLocation(shaderProgram, "projectionMatrix");
|
||||
defaultModelviewMatrixLoc = glGetUniformLocation(defaultShaderProgram, "modelviewMatrix");
|
||||
defaultProjectionMatrixLoc = glGetUniformLocation(defaultShaderProgram, "projectionMatrix");
|
||||
|
||||
// Get handles to GLSL uniform vars locations (fragment-shader)
|
||||
textureLoc = glGetUniformLocation(shaderProgram, "texture0");
|
||||
defaultTextureLoc = glGetUniformLocation(defaultShaderProgram, "texture0");
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
// Get handles to GLSL input vars locations for simpleShaderProgram
|
||||
//-------------------------------------------------------------------
|
||||
simpleVertexLoc = glGetAttribLocation(simpleShaderProgram, "vertexPosition");
|
||||
simpleTexcoordLoc = glGetAttribLocation(simpleShaderProgram, "vertexTexCoord");
|
||||
simpleNormalLoc = glGetAttribLocation(defaultShaderProgram, "vertexNormal");
|
||||
|
||||
// Get handles to GLSL uniform vars locations (vertex-shader)
|
||||
simpleModelviewMatrixLoc = glGetUniformLocation(simpleShaderProgram, "modelviewMatrix");
|
||||
simpleProjectionMatrixLoc = glGetUniformLocation(simpleShaderProgram, "projectionMatrix");
|
||||
|
||||
// Get handles to GLSL uniform vars locations (fragment-shader)
|
||||
simpleTextureLoc = glGetUniformLocation(simpleShaderProgram, "texture0");
|
||||
simpleColorLoc = glGetUniformLocation(simpleShaderProgram, "fragColor");
|
||||
//--------------------------------------------------------------------
|
||||
|
||||
InitializeBuffers(); // Init vertex arrays
|
||||
InitializeBuffersGPU(); // Init VBO and VAO
|
||||
|
@ -914,11 +945,11 @@ void rlglClose(void)
|
|||
glDeleteVertexArrays(1, &vaoQuads);
|
||||
}
|
||||
|
||||
//glDetachShader(shaderProgram, v);
|
||||
//glDetachShader(shaderProgram, f);
|
||||
//glDetachShader(defaultShaderProgram, v);
|
||||
//glDetachShader(defaultShaderProgram, f);
|
||||
//glDeleteShader(v);
|
||||
//glDeleteShader(f);
|
||||
glDeleteProgram(shaderProgram);
|
||||
glDeleteProgram(defaultShaderProgram);
|
||||
|
||||
// Free vertex arrays memory
|
||||
free(lines.vertices);
|
||||
|
@ -944,11 +975,14 @@ void rlglDraw(void)
|
|||
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
||||
UpdateBuffers();
|
||||
|
||||
glUseProgram(shaderProgram); // Use our shader
|
||||
if ((lines.vCounter > 0) || (triangles.vCounter > 0) || (quads.vCounter > 0))
|
||||
{
|
||||
glUseProgram(defaultShaderProgram); // Use our shader
|
||||
|
||||
glUniformMatrix4fv(projectionMatrixLoc, 1, false, GetMatrixVector(projection));
|
||||
glUniformMatrix4fv(modelviewMatrixLoc, 1, false, GetMatrixVector(modelview));
|
||||
glUniform1i(textureLoc, 0);
|
||||
glUniformMatrix4fv(defaultProjectionMatrixLoc, 1, false, GetMatrixVector(projection));
|
||||
glUniformMatrix4fv(defaultModelviewMatrixLoc, 1, false, GetMatrixVector(modelview));
|
||||
glUniform1i(defaultTextureLoc, 0);
|
||||
}
|
||||
|
||||
// NOTE: We draw in this order: triangle shapes, textured quads and lines
|
||||
|
||||
|
@ -963,12 +997,12 @@ void rlglDraw(void)
|
|||
else
|
||||
{
|
||||
glBindBuffer(GL_ARRAY_BUFFER, trianglesBuffer[0]);
|
||||
glVertexAttribPointer(vertexLoc, 3, GL_FLOAT, 0, 0, 0);
|
||||
glEnableVertexAttribArray(vertexLoc);
|
||||
glVertexAttribPointer(defaultVertexLoc, 3, GL_FLOAT, 0, 0, 0);
|
||||
glEnableVertexAttribArray(defaultVertexLoc);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, trianglesBuffer[1]);
|
||||
glVertexAttribPointer(colorLoc, 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, 0);
|
||||
glEnableVertexAttribArray(colorLoc);
|
||||
glVertexAttribPointer(defaultColorLoc, 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, 0);
|
||||
glEnableVertexAttribArray(defaultColorLoc);
|
||||
}
|
||||
|
||||
glDrawArrays(GL_TRIANGLES, 0, triangles.vCounter);
|
||||
|
@ -991,16 +1025,16 @@ void rlglDraw(void)
|
|||
{
|
||||
// Enable vertex attributes
|
||||
glBindBuffer(GL_ARRAY_BUFFER, quadsBuffer[0]);
|
||||
glVertexAttribPointer(vertexLoc, 3, GL_FLOAT, 0, 0, 0);
|
||||
glEnableVertexAttribArray(vertexLoc);
|
||||
glVertexAttribPointer(defaultVertexLoc, 3, GL_FLOAT, 0, 0, 0);
|
||||
glEnableVertexAttribArray(defaultVertexLoc);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, quadsBuffer[1]);
|
||||
glVertexAttribPointer(texcoordLoc, 2, GL_FLOAT, 0, 0, 0);
|
||||
glEnableVertexAttribArray(texcoordLoc);
|
||||
glVertexAttribPointer(defaultTexcoordLoc, 2, GL_FLOAT, 0, 0, 0);
|
||||
glEnableVertexAttribArray(defaultTexcoordLoc);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, quadsBuffer[2]);
|
||||
glVertexAttribPointer(colorLoc, 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, 0);
|
||||
glEnableVertexAttribArray(colorLoc);
|
||||
glVertexAttribPointer(defaultColorLoc, 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, 0);
|
||||
glEnableVertexAttribArray(defaultColorLoc);
|
||||
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, quadsBuffer[3]);
|
||||
}
|
||||
|
@ -1048,12 +1082,12 @@ void rlglDraw(void)
|
|||
else
|
||||
{
|
||||
glBindBuffer(GL_ARRAY_BUFFER, linesBuffer[0]);
|
||||
glVertexAttribPointer(vertexLoc, 3, GL_FLOAT, 0, 0, 0);
|
||||
glEnableVertexAttribArray(vertexLoc);
|
||||
glVertexAttribPointer(defaultVertexLoc, 3, GL_FLOAT, 0, 0, 0);
|
||||
glEnableVertexAttribArray(defaultVertexLoc);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, linesBuffer[1]);
|
||||
glVertexAttribPointer(colorLoc, 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, 0);
|
||||
glEnableVertexAttribArray(colorLoc);
|
||||
glVertexAttribPointer(defaultColorLoc, 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, 0);
|
||||
glEnableVertexAttribArray(defaultColorLoc);
|
||||
}
|
||||
|
||||
glDrawArrays(GL_LINES, 0, lines.vCounter);
|
||||
|
@ -1104,8 +1138,6 @@ void rlglDrawModel(Model model, Vector3 position, Vector3 rotation, Vector3 scal
|
|||
glNormalPointer(GL_FLOAT, 0, model.mesh.normals); // Pointer to normals array
|
||||
//glColorPointer(4, GL_UNSIGNED_BYTE, 0, model.mesh.colors); // Pointer to colors array (NOT USED)
|
||||
|
||||
//TraceLog(DEBUG, "Drawing model.mesh, VertexCount: %i", model.mesh.vertexCount);
|
||||
|
||||
rlPushMatrix();
|
||||
rlTranslatef(position.x, position.y, position.z);
|
||||
rlScalef(scale.x, scale.y, scale.z);
|
||||
|
@ -1127,7 +1159,7 @@ void rlglDrawModel(Model model, Vector3 position, Vector3 rotation, Vector3 scal
|
|||
#endif
|
||||
|
||||
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
||||
glUseProgram(shaderProgram); // Use our shader
|
||||
glUseProgram(simpleShaderProgram); // Use our simple shader
|
||||
|
||||
VectorScale(&rotation, DEG2RAD);
|
||||
|
||||
|
@ -1136,37 +1168,14 @@ void rlglDrawModel(Model model, Vector3 position, Vector3 rotation, Vector3 scal
|
|||
Matrix modelviewworld = MatrixMultiply(transform, modelview);
|
||||
|
||||
// NOTE: Drawing in OpenGL 3.3+, transform is passed to shader
|
||||
glUniformMatrix4fv(projectionMatrixLoc, 1, false, GetMatrixVector(projection));
|
||||
glUniformMatrix4fv(modelviewMatrixLoc, 1, false, GetMatrixVector(modelviewworld));
|
||||
glUniform1i(textureLoc, 0);
|
||||
glUniformMatrix4fv(simpleProjectionMatrixLoc, 1, false, GetMatrixVector(projection));
|
||||
glUniformMatrix4fv(simpleModelviewMatrixLoc, 1, false, GetMatrixVector(modelviewworld));
|
||||
glUniform1i(simpleTextureLoc, 0);
|
||||
|
||||
// Apply color tinting to model: 2 OPTIONS
|
||||
/*
|
||||
// OPTION 1
|
||||
// Update colors array (model.mesh.colors) with color
|
||||
int j = 0;
|
||||
for (int i = 0; i < model.mesh.vertexCount; i++)
|
||||
{
|
||||
model.mesh.colors[j] = color.r;
|
||||
model.mesh.colors[j+1] = color.g;
|
||||
model.mesh.colors[j+2] = color.b;
|
||||
model.mesh.colors[j+3] = color.a;
|
||||
j += 4;
|
||||
}
|
||||
|
||||
// Update colors buffer in CPU (using Shader)
|
||||
if (vaoSupported) glBindVertexArray(model.vaoId);
|
||||
GLuint colorVboId;
|
||||
glGetVertexAttribIuiv(2, GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, &colorVboId); // NOTE: Color VBO is buffer index 2
|
||||
glBindBuffer(GL_ARRAY_BUFFER, colorVboId);
|
||||
glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(unsigned char)*4*model.mesh.vertexCount, model.mesh.colors);
|
||||
|
||||
// OPTION 2: Just update one uniform on fragment shader
|
||||
// NOTE: It requires shader modification to add uniform (fragment shader) and create location point
|
||||
//glUniform4f(fragmentUniformColorLoc, (float)color.r/255, (float)color.g/255, (float)color.b/255, (float)color.a/255);
|
||||
*/
|
||||
|
||||
//TraceLog(DEBUG, "ShaderProgram: %i, VAO ID: %i, VertexCount: %i", shaderProgram, model.vaoId, model.mesh.vertexCount);
|
||||
// Apply color tinting to model
|
||||
// NOTE: Just update one uniform on fragment shader
|
||||
float vColor[4] = { (float)color.r/255, (float)color.g/255, (float)color.b/255, (float)color.a/255 };
|
||||
glUniform4fv(simpleColorLoc, 1, vColor);
|
||||
|
||||
if (vaoSupported)
|
||||
{
|
||||
|
@ -1176,16 +1185,17 @@ void rlglDrawModel(Model model, Vector3 position, Vector3 rotation, Vector3 scal
|
|||
{
|
||||
// Bind model VBOs data
|
||||
glBindBuffer(GL_ARRAY_BUFFER, model.vboId[0]);
|
||||
glVertexAttribPointer(vertexLoc, 3, GL_FLOAT, 0, 0, 0);
|
||||
glEnableVertexAttribArray(vertexLoc);
|
||||
glVertexAttribPointer(simpleVertexLoc, 3, GL_FLOAT, 0, 0, 0);
|
||||
glEnableVertexAttribArray(simpleVertexLoc);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, model.vboId[1]);
|
||||
glVertexAttribPointer(texcoordLoc, 2, GL_FLOAT, 0, 0, 0);
|
||||
glEnableVertexAttribArray(texcoordLoc);
|
||||
glVertexAttribPointer(simpleTexcoordLoc, 2, GL_FLOAT, 0, 0, 0);
|
||||
glEnableVertexAttribArray(simpleTexcoordLoc);
|
||||
|
||||
// Add normals support
|
||||
glBindBuffer(GL_ARRAY_BUFFER, model.vboId[2]);
|
||||
glVertexAttribPointer(colorLoc, 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, 0);
|
||||
glEnableVertexAttribArray(colorLoc);
|
||||
glVertexAttribPointer(simpleNormalLoc, 3, GL_FLOAT, 0, 0, 0);
|
||||
glEnableVertexAttribArray(simpleNormalLoc);
|
||||
}
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, model.textureId);
|
||||
|
@ -1196,6 +1206,8 @@ void rlglDrawModel(Model model, Vector3 position, Vector3 rotation, Vector3 scal
|
|||
|
||||
if (vaoSupported) glBindVertexArray(0); // Unbind VAO
|
||||
else glBindBuffer(GL_ARRAY_BUFFER, 0); // Unbind VBOs
|
||||
|
||||
glUseProgram(0);
|
||||
#endif
|
||||
|
||||
#if defined (GRAPHICS_API_OPENGL_11) || defined(GRAPHICS_API_OPENGL_33)
|
||||
|
@ -1360,8 +1372,7 @@ Model rlglLoadModel(VertexData mesh)
|
|||
model.vaoId = 0; // Vertex Array Object
|
||||
model.vboId[0] = 0; // Vertex position VBO
|
||||
model.vboId[1] = 0; // Texcoords VBO
|
||||
//model.vboId[2] = 0; // Normals VBO (not used)
|
||||
model.vboId[2] = 0; // Colors VBO
|
||||
model.vboId[2] = 0; // Normals VBO
|
||||
|
||||
#elif defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
||||
model.textureId = 1; // Default whiteTexture
|
||||
|
@ -1382,28 +1393,24 @@ Model rlglLoadModel(VertexData mesh)
|
|||
// Enable vertex attributes: position
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer[0]);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(float)*3*mesh.vertexCount, mesh.vertices, GL_STATIC_DRAW);
|
||||
glEnableVertexAttribArray(vertexLoc);
|
||||
glVertexAttribPointer(vertexLoc, 3, GL_FLOAT, 0, 0, 0);
|
||||
glEnableVertexAttribArray(simpleVertexLoc);
|
||||
glVertexAttribPointer(simpleVertexLoc, 3, GL_FLOAT, 0, 0, 0);
|
||||
|
||||
// Enable vertex attributes: texcoords
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer[1]);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(float)*2*mesh.vertexCount, mesh.texcoords, GL_STATIC_DRAW);
|
||||
glEnableVertexAttribArray(texcoordLoc);
|
||||
glVertexAttribPointer(texcoordLoc, 2, GL_FLOAT, 0, 0, 0);
|
||||
|
||||
// TODO: Normals support -> Lighting
|
||||
glEnableVertexAttribArray(simpleTexcoordLoc);
|
||||
glVertexAttribPointer(simpleTexcoordLoc, 2, GL_FLOAT, 0, 0, 0);
|
||||
|
||||
// Enable vertex attributes: normals
|
||||
//glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer[2]);
|
||||
//glBufferData(GL_ARRAY_BUFFER, sizeof(float)*3*mesh.vertexCount, mesh.normals, GL_STATIC_DRAW);
|
||||
//glEnableVertexAttribArray(normalLoc);
|
||||
//glVertexAttribPointer(normalLoc, 3, GL_FLOAT, 0, 0, 0);
|
||||
|
||||
// Enable vertex attributes: colors
|
||||
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer[2]);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(unsigned char)*4*mesh.vertexCount, mesh.colors, GL_STATIC_DRAW);
|
||||
glEnableVertexAttribArray(colorLoc);
|
||||
glVertexAttribPointer(colorLoc, 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, 0);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(float)*3*mesh.vertexCount, mesh.normals, GL_STATIC_DRAW);
|
||||
glEnableVertexAttribArray(simpleNormalLoc);
|
||||
glVertexAttribPointer(simpleNormalLoc, 3, GL_FLOAT, 0, 0, 0);
|
||||
|
||||
model.vboId[0] = vertexBuffer[0]; // Vertex position VBO
|
||||
model.vboId[1] = vertexBuffer[1]; // Texcoords VBO
|
||||
model.vboId[2] = vertexBuffer[2]; // Normals VBO
|
||||
|
||||
if (vaoSupported)
|
||||
{
|
||||
|
@ -1416,11 +1423,6 @@ Model rlglLoadModel(VertexData mesh)
|
|||
}
|
||||
else
|
||||
{
|
||||
model.vboId[0] = vertexBuffer[0]; // Vertex position VBO
|
||||
model.vboId[1] = vertexBuffer[1]; // Texcoords VBO
|
||||
//model.vboId[2] = 0; // Normals VBO (not used)
|
||||
model.vboId[2] = vertexBuffer[2]; // Colors VBO
|
||||
|
||||
TraceLog(INFO, "[VBO ID %i][VBO ID %i][VBO ID %i] Model uploaded successfully to VRAM (GPU)", model.vboId[0], model.vboId[1], model.vboId[2]);
|
||||
}
|
||||
#endif
|
||||
|
@ -1551,8 +1553,9 @@ void PrintModelviewMatrix()
|
|||
|
||||
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
||||
|
||||
// Load Shaders (Vertex and Fragment)
|
||||
static GLuint LoadDefaultShaders(void)
|
||||
// Load Shader (Vertex and Fragment)
|
||||
// NOTE: This shader program is used only for batch buffers (lines, triangles, quads)
|
||||
static GLuint LoadDefaultShader(void)
|
||||
{
|
||||
// NOTE: Shaders are written using GLSL 110 (desktop), that is equivalent to GLSL 100 on ES2
|
||||
|
||||
|
@ -1650,9 +1653,106 @@ static GLuint LoadDefaultShaders(void)
|
|||
return program;
|
||||
}
|
||||
|
||||
// Load Simple Shader (Vertex and Fragment)
|
||||
// NOTE: This shader program is used to render models
|
||||
static GLuint LoadSimpleShader(void)
|
||||
{
|
||||
// NOTE: Shaders are written using GLSL 110 (desktop), that is equivalent to GLSL 100 on ES2
|
||||
|
||||
// Load Shaders
|
||||
static GLuint LoadShaders(char *vertexFileName, char *fragmentFileName)
|
||||
// Vertex shader directly defined, no external file required
|
||||
#if defined(GRAPHICS_API_OPENGL_33)
|
||||
char vShaderStr[] = " #version 110 \n" // NOTE: Equivalent to version 100 on ES2
|
||||
#elif defined(GRAPHICS_API_OPENGL_ES2)
|
||||
char vShaderStr[] = " #version 100 \n" // NOTE: Must be defined this way! 110 doesn't work!
|
||||
#endif
|
||||
"uniform mat4 projectionMatrix; \n"
|
||||
"uniform mat4 modelviewMatrix; \n"
|
||||
"attribute vec3 vertexPosition; \n"
|
||||
"attribute vec2 vertexTexCoord; \n"
|
||||
"attribute vec3 vertexNormal; \n"
|
||||
"varying vec2 fragTexCoord; \n"
|
||||
"void main() \n"
|
||||
"{ \n"
|
||||
" fragTexCoord = vertexTexCoord; \n"
|
||||
" gl_Position = projectionMatrix * modelviewMatrix * vec4(vertexPosition, 1.0); \n"
|
||||
"} \n";
|
||||
|
||||
// Fragment shader directly defined, no external file required
|
||||
#if defined(GRAPHICS_API_OPENGL_33)
|
||||
char fShaderStr[] = " #version 110 \n" // NOTE: Equivalent to version 100 on ES2
|
||||
#elif defined(GRAPHICS_API_OPENGL_ES2)
|
||||
char fShaderStr[] = " #version 100 \n" // NOTE: Must be defined this way! 110 doesn't work!
|
||||
"precision mediump float; \n" // WebGL, required for emscripten
|
||||
#endif
|
||||
"uniform sampler2D texture0; \n"
|
||||
"varying vec2 fragTexCoord; \n"
|
||||
"uniform vec4 fragColor; \n"
|
||||
"void main() \n"
|
||||
"{ \n"
|
||||
" gl_FragColor = texture2D(texture0, fragTexCoord) * fragColor; \n"
|
||||
"} \n";
|
||||
|
||||
GLuint program;
|
||||
GLuint vertexShader;
|
||||
GLuint fragmentShader;
|
||||
|
||||
vertexShader = glCreateShader(GL_VERTEX_SHADER);
|
||||
fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
|
||||
|
||||
const char *pvs = vShaderStr;
|
||||
const char *pfs = fShaderStr;
|
||||
|
||||
glShaderSource(vertexShader, 1, &pvs, NULL);
|
||||
glShaderSource(fragmentShader, 1, &pfs, NULL);
|
||||
|
||||
GLint success = 0;
|
||||
|
||||
glCompileShader(vertexShader);
|
||||
|
||||
glGetShaderiv(vertexShader, GL_COMPILE_STATUS, &success);
|
||||
|
||||
if (success != GL_TRUE) TraceLog(WARNING, "[VSHDR ID %i] Failed to compile simple vertex shader...", vertexShader);
|
||||
else TraceLog(INFO, "[VSHDR ID %i] Simple vertex shader compiled successfully", vertexShader);
|
||||
|
||||
glCompileShader(fragmentShader);
|
||||
|
||||
glGetShaderiv(fragmentShader, GL_COMPILE_STATUS, &success);
|
||||
|
||||
if (success != GL_TRUE) TraceLog(WARNING, "[FSHDR ID %i] Failed to compile simple fragment shader...", fragmentShader);
|
||||
else TraceLog(INFO, "[FSHDR ID %i] Simple fragment shader compiled successfully", fragmentShader);
|
||||
|
||||
program = glCreateProgram();
|
||||
|
||||
glAttachShader(program, vertexShader);
|
||||
glAttachShader(program, fragmentShader);
|
||||
|
||||
glLinkProgram(program);
|
||||
|
||||
glGetProgramiv(program, GL_LINK_STATUS, &success);
|
||||
|
||||
if (success == GL_FALSE)
|
||||
{
|
||||
int maxLength;
|
||||
int length;
|
||||
|
||||
glGetProgramiv(program, GL_INFO_LOG_LENGTH, &maxLength);
|
||||
|
||||
char log[maxLength];
|
||||
|
||||
glGetProgramInfoLog(program, maxLength, &length, log);
|
||||
|
||||
TraceLog(INFO, "Shader program fail log: %s", log);
|
||||
}
|
||||
else TraceLog(INFO, "[SHDR ID %i] Simple shader program loaded successfully", program);
|
||||
|
||||
glDeleteShader(vertexShader);
|
||||
glDeleteShader(fragmentShader);
|
||||
|
||||
return program;
|
||||
}
|
||||
|
||||
// Load shaders from text files
|
||||
static GLuint LoadCustomShader(char *vertexFileName, char *fragmentFileName)
|
||||
{
|
||||
// Shaders loading from external text file
|
||||
char *vShaderStr = TextFileRead(vertexFileName);
|
||||
|
@ -1687,12 +1787,16 @@ static GLuint LoadShaders(char *vertexFileName, char *fragmentFileName)
|
|||
glDeleteShader(vertexShader);
|
||||
glDeleteShader(fragmentShader);
|
||||
|
||||
free(vShaderStr);
|
||||
free(fShaderStr);
|
||||
|
||||
TraceLog(INFO, "[SHDR ID %i] Shader program loaded successfully", program);
|
||||
|
||||
return program;
|
||||
}
|
||||
|
||||
// Read shader text file
|
||||
// NOTE: text chars array should be freed manually
|
||||
static char *TextFileRead(char *fileName)
|
||||
{
|
||||
FILE *textFile;
|
||||
|
@ -1801,14 +1905,14 @@ static void InitializeBuffersGPU(void)
|
|||
// Lines - Vertex positions buffer binding and attributes enable
|
||||
glBindBuffer(GL_ARRAY_BUFFER, linesBuffer[0]);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(float)*3*2*MAX_LINES_BATCH, lines.vertices, GL_DYNAMIC_DRAW);
|
||||
glEnableVertexAttribArray(vertexLoc);
|
||||
glVertexAttribPointer(vertexLoc, 3, GL_FLOAT, 0, 0, 0);
|
||||
glEnableVertexAttribArray(defaultVertexLoc);
|
||||
glVertexAttribPointer(defaultVertexLoc, 3, GL_FLOAT, 0, 0, 0);
|
||||
|
||||
// Lines - colors buffer
|
||||
glBindBuffer(GL_ARRAY_BUFFER, linesBuffer[1]);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(unsigned char)*4*2*MAX_LINES_BATCH, lines.colors, GL_DYNAMIC_DRAW);
|
||||
glEnableVertexAttribArray(colorLoc);
|
||||
glVertexAttribPointer(colorLoc, 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, 0);
|
||||
glEnableVertexAttribArray(defaultColorLoc);
|
||||
glVertexAttribPointer(defaultColorLoc, 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, 0);
|
||||
|
||||
if (vaoSupported) TraceLog(INFO, "[VAO ID %i] Lines VAO initialized successfully", vaoLines);
|
||||
else TraceLog(INFO, "[VBO ID %i][VBO ID %i] Lines VBOs initialized successfully", linesBuffer[0], linesBuffer[1]);
|
||||
|
@ -1827,13 +1931,13 @@ static void InitializeBuffersGPU(void)
|
|||
// Enable vertex attributes
|
||||
glBindBuffer(GL_ARRAY_BUFFER, trianglesBuffer[0]);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(float)*3*3*MAX_TRIANGLES_BATCH, triangles.vertices, GL_DYNAMIC_DRAW);
|
||||
glEnableVertexAttribArray(vertexLoc);
|
||||
glVertexAttribPointer(vertexLoc, 3, GL_FLOAT, 0, 0, 0);
|
||||
glEnableVertexAttribArray(defaultVertexLoc);
|
||||
glVertexAttribPointer(defaultVertexLoc, 3, GL_FLOAT, 0, 0, 0);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, trianglesBuffer[1]);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(unsigned char)*4*3*MAX_TRIANGLES_BATCH, triangles.colors, GL_DYNAMIC_DRAW);
|
||||
glEnableVertexAttribArray(colorLoc);
|
||||
glVertexAttribPointer(colorLoc, 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, 0);
|
||||
glEnableVertexAttribArray(defaultColorLoc);
|
||||
glVertexAttribPointer(defaultColorLoc, 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, 0);
|
||||
|
||||
if (vaoSupported) TraceLog(INFO, "[VAO ID %i] Triangles VAO initialized successfully", vaoTriangles);
|
||||
else TraceLog(INFO, "[VBO ID %i][VBO ID %i] Triangles VBOs initialized successfully", trianglesBuffer[0], trianglesBuffer[1]);
|
||||
|
@ -1852,18 +1956,18 @@ static void InitializeBuffersGPU(void)
|
|||
// Enable vertex attributes
|
||||
glBindBuffer(GL_ARRAY_BUFFER, quadsBuffer[0]);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(float)*3*4*MAX_QUADS_BATCH, quads.vertices, GL_DYNAMIC_DRAW);
|
||||
glEnableVertexAttribArray(vertexLoc);
|
||||
glVertexAttribPointer(vertexLoc, 3, GL_FLOAT, 0, 0, 0);
|
||||
glEnableVertexAttribArray(defaultVertexLoc);
|
||||
glVertexAttribPointer(defaultVertexLoc, 3, GL_FLOAT, 0, 0, 0);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, quadsBuffer[1]);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(float)*2*4*MAX_QUADS_BATCH, quads.texcoords, GL_DYNAMIC_DRAW);
|
||||
glEnableVertexAttribArray(texcoordLoc);
|
||||
glVertexAttribPointer(texcoordLoc, 2, GL_FLOAT, 0, 0, 0);
|
||||
glEnableVertexAttribArray(defaultTexcoordLoc);
|
||||
glVertexAttribPointer(defaultTexcoordLoc, 2, GL_FLOAT, 0, 0, 0);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, quadsBuffer[2]);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(unsigned char)*4*4*MAX_QUADS_BATCH, quads.colors, GL_DYNAMIC_DRAW);
|
||||
glEnableVertexAttribArray(colorLoc);
|
||||
glVertexAttribPointer(colorLoc, 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, 0);
|
||||
glEnableVertexAttribArray(defaultColorLoc);
|
||||
glVertexAttribPointer(defaultColorLoc, 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, 0);
|
||||
|
||||
// Fill index buffer
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, quadsBuffer[3]);
|
||||
|
@ -1885,6 +1989,8 @@ static void InitializeBuffersGPU(void)
|
|||
// TODO: If no data changed on the CPU arrays --> No need to update GPU arrays every frame!
|
||||
static void UpdateBuffers(void)
|
||||
{
|
||||
if (lines.vCounter > 0)
|
||||
{
|
||||
// Activate Lines VAO
|
||||
if (vaoSupported) glBindVertexArray(vaoLines);
|
||||
|
||||
|
@ -1897,9 +2003,11 @@ static void UpdateBuffers(void)
|
|||
glBindBuffer(GL_ARRAY_BUFFER, linesBuffer[1]);
|
||||
//glBufferData(GL_ARRAY_BUFFER, sizeof(float)*4*2*MAX_LINES_BATCH, lines.colors, GL_DYNAMIC_DRAW);
|
||||
glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(unsigned char)*4*lines.cCounter, lines.colors);
|
||||
|
||||
}
|
||||
//--------------------------------------------------------------
|
||||
|
||||
if (triangles.vCounter > 0)
|
||||
{
|
||||
// Activate Triangles VAO
|
||||
if (vaoSupported) glBindVertexArray(vaoTriangles);
|
||||
|
||||
|
@ -1912,9 +2020,11 @@ static void UpdateBuffers(void)
|
|||
glBindBuffer(GL_ARRAY_BUFFER, trianglesBuffer[1]);
|
||||
//glBufferData(GL_ARRAY_BUFFER, sizeof(float)*4*3*MAX_TRIANGLES_BATCH, triangles.colors, GL_DYNAMIC_DRAW);
|
||||
glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(unsigned char)*4*triangles.cCounter, triangles.colors);
|
||||
|
||||
}
|
||||
//--------------------------------------------------------------
|
||||
|
||||
if (quads.vCounter > 0)
|
||||
{
|
||||
// Activate Quads VAO
|
||||
if (vaoSupported) glBindVertexArray(vaoQuads);
|
||||
|
||||
|
@ -1937,7 +2047,7 @@ static void UpdateBuffers(void)
|
|||
//triangles.vertices = glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE);
|
||||
// Now we can modify vertices
|
||||
//glUnmapBuffer(GL_ARRAY_BUFFER);
|
||||
|
||||
}
|
||||
//--------------------------------------------------------------
|
||||
|
||||
// Unbind the current VAO
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
* raylib now uses OpenGL 1.1 style functions (rlVertex) that are mapped to selected OpenGL version:
|
||||
* OpenGL 1.1 - Direct map rl* -> gl*
|
||||
* OpenGL 3.3+ - Vertex data is stored in VAOs, call rlglDraw() to render
|
||||
* OpenGL ES 2 - Same behaviour as OpenGL 3.3+
|
||||
* OpenGL ES 2 - Vertex data is stored in VBOs or VAOs (when available), call rlglDraw() to render
|
||||
*
|
||||
* Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com)
|
||||
*
|
||||
|
|
|
@ -40,7 +40,6 @@ LOCAL_SRC_FILES :=\
|
|||
../../src/core.c \
|
||||
../../src/rlgl.c \
|
||||
../../src/raymath.c \
|
||||
../../src/stb_image.c \
|
||||
../../src/textures.c \
|
||||
../../src/text.c \
|
||||
../../src/shapes.c \
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue