void EditorUI::BrowseForTexture(int textureIndex) { const char *fn=FileChooser("Select texture:", 0, 0,false); if(fn) { Texture *tex = new Texture (fn); if (!tex->IsLoaded ()) { delete tex; } else SetModelTexture (textureIndex, tex); } }
void EditorUI::ReloadTexture (int index) { /*fltk::FileInput *input = index ? inputTexture2 : inputTexture1;*/ if (int(model->texBindings.size ()) <= index) model->texBindings.resize (index+1); TextureBinding& tb = model->texBindings[index]; RefPtr<Texture> tex = new Texture(tb.name); SetModelTexture (index, tex->IsLoaded () ? tex.Get() : 0); BACKUP_POINT("Texture reload"); Update(); }
void EditorUI::BrowseForTexture(int textureIndex) { static std::string fn; if (FileOpenDlg ("Select texture:", ImageFileExt, fn)) { Texture *tex = new Texture (fn); if (!tex->IsLoaded ()) delete tex; else SetModelTexture (textureIndex, tex); BACKUP_POINT("Texture change"); Update(); } }
void EditorUI::ReloadTexture (int index) { fltk::FileInput *input = index ? inputTexture2 : inputTexture1; if (input->empty()) { model->textureNames[index].clear(); SAFE_DELETE(model->textures [index]); } else { Texture *tex = new Texture(input->value()); if (!tex->IsLoaded ()) { delete tex; } else SetModelTexture (index, tex); } viewsGroup->redraw(); }
void EditorUI::ConvertToS3O() { static int texW = 256; static int texH = 256; texW = atoi (fltk::input ("Enter texture width: ", SPrintf("%d", texW).c_str())); texH = atoi (fltk::input ("Enter texture height: ", SPrintf("%d", texH).c_str())); std::string name_ext = fltk::filename_name (filename.c_str()); std::string name (name_ext.c_str(), fltk::filename_ext (name_ext.c_str())); if (model->ConvertToS3O(GetFilePath(filename) + "/" + name + "_tex.bmp", texW, texH)) { // Update the UI SetModelTexture (0, model->texBindings[0].texture.Get()); SetMapping (MAPPING_S3O); BACKUP_POINT("Converted to S3O texturing"); } else BackupManager::Get().ReloadLast (); Update(); }
void EditorUI::SetModel (Model *mdl) { SAFE_DELETE(model); model = mdl; objectViewer->Update(); viewsGroup->redraw (); mappingChooser->value (mdl->mapping); SetMapping (mdl->mapping); inputTexture1->value(0); inputTexture2->value(0); for (unsigned int a=0;a<mdl->texBindings.size();a++) SetModelTexture (a, mdl->texBindings[a].texture.Get()); Update (); }
void EditorUI::SetModel (Model *mdl) { model = mdl; modelDrawer->SetModel (mdl); objectViewer->Update(); viewsGroup->redraw (); mappingChooser->value (mdl->mapping); SetMapping (mdl->mapping); inputTexture1->value(0); inputTexture2->value(0); for (int a=0; a<2; a++) { if (mdl->textures[a]) SetModelTexture (a, mdl->textures [a]); fltk::FileInput *input = a ? inputTexture2 : inputTexture1; input->value (mdl->textureNames [a].c_str()); } Update (); }
int main() { // Initialization //-------------------------------------------------------------------------------------- int screenWidth = 800; int screenHeight = 450; SetConfigFlags(FLAG_MSAA_4X_HINT); // Enable Multi Sampling Anti Aliasing 4x (if available) InitWindow(screenWidth, screenHeight, "raylib [shaders] example - postprocessing shader"); // Define the camera to look into our 3d world Camera camera = {{ 3.0, 3.0, 3.0 }, { 0.0, 1.5, 0.0 }, { 0.0, 1.0, 0.0 }}; Model dwarf = LoadModel("resources/model/dwarf.obj"); // Load OBJ model Texture2D texture = LoadTexture("resources/model/dwarf_diffuse.png"); // Load model texture SetModelTexture(&dwarf, texture); // Bind texture to model Vector3 position = { 0.0, 0.0, 0.0 }; // Set model position Shader shader = LoadShader("resources/shaders/base.vs", "resources/shaders/bloom.fs"); // Load postpro shader SetPostproShader(shader); // Set fullscreen postprocessing shader // Setup orbital camera SetCameraMode(CAMERA_ORBITAL); // Set an orbital camera mode SetCameraPosition(camera.position); // Set internal camera position to match our camera position SetCameraTarget(camera.target); // Set internal camera target to match our camera target SetTargetFPS(60); // Set our game to run at 60 frames-per-second //-------------------------------------------------------------------------------------- // Main game loop while (!WindowShouldClose()) // Detect window close button or ESC key { // Update //---------------------------------------------------------------------------------- UpdateCamera(&camera); // Update internal camera and our camera //---------------------------------------------------------------------------------- // Draw //---------------------------------------------------------------------------------- BeginDrawing(); ClearBackground(RAYWHITE); Begin3dMode(camera); DrawModel(dwarf, position, 2.0f, WHITE); // Draw 3d model with texture DrawGrid(10.0, 1.0); // Draw a grid End3dMode(); DrawText("(c) Dwarf 3D model by David Moreno", screenWidth - 200, screenHeight - 20, 10, BLACK); DrawFPS(10, 10); EndDrawing(); //---------------------------------------------------------------------------------- } // De-Initialization //-------------------------------------------------------------------------------------- UnloadShader(shader); // Unload shader UnloadTexture(texture); // Unload texture UnloadModel(dwarf); // Unload model CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- return 0; }
//---------------------------------------------------------------------------------- // Main entry point //---------------------------------------------------------------------------------- int main() { // Initialization //-------------------------------------------------------------------------------------- const char windowTitle[30] = "raylib functionality demo"; //SetupFlags(FLAG_FULLSCREEN_MODE); InitWindow(screenWidth, screenHeight, windowTitle); InitAudioDevice(); // Initialize audio device // TITLE screen variables Initialization fontAlagard = LoadSpriteFont("resources/fonts/alagard.rbmf"); // rBMF font loading fontPixelplay = LoadSpriteFont("resources/fonts/pixelplay.rbmf"); // rBMF font loading fontMecha = LoadSpriteFont("resources/fonts/mecha.rbmf"); // rBMF font loading fontSetback = LoadSpriteFont("resources/fonts/setback.rbmf"); // rBMF font loading fontRomulus = LoadSpriteFont("resources/fonts/romulus.rbmf"); // rBMF font loading pongBallPosition = (Vector2){ screenWidth/2, screenHeight/2 + 20 }; pongBallSpeed = (Vector2){ 6, 6 }; pongPlayerRec = (Rectangle){ 20, screenHeight/2 - 50 + 40, 20, 100 }; pongEnemyRec = (Rectangle){ screenWidth - 40, screenHeight/2 - 60, 20, 120 }; // LOGO screen variables Initialization logoPositionX = screenWidth/2 - 128; logoPositionY = screenHeight/2 - 128; // MODULES screen variables Initialization raylibWindow = LoadTexture("resources/raylib_window.png"); raylibWindow01 = LoadTexture("resources/raylib_window_01.png"); raylibWindow02 = LoadTexture("resources/raylib_window_02.png"); raylibWindow03 = LoadTexture("resources/raylib_window_03.png"); platforms = LoadTexture("resources/platforms.png"); raylibLogoB = LoadTexture("resources/raylib_logo128x128.png"); lena = LoadTexture("resources/lena.png"); mandrill = LoadTexture("resources/mandrill.png"); texAlagard = LoadTexture("resources/fonts/custom_alagard.png"); fontMechaC = LoadSpriteFont("resources/fonts/custom_mecha.png"); fontAlagardC = LoadSpriteFont("resources/fonts/custom_alagard.png"); fontJupiterC = LoadSpriteFont("resources/fonts/custom_jupiter_crash.png"); ballPosition = (Vector2){ 520 + 656/2, 220 + 399/2 }; camera = (Camera){{ 0.0, 12.0, 15.0 }, { 0.0, 3.0, 0.0 }, { 0.0, 1.0, 0.0 }}; catTexture = LoadTexture("resources/catsham.png"); // Load model texture cat = LoadModel("resources/cat.obj"); // Load OBJ model SetModelTexture(&cat, catTexture); fxWav = LoadSound("resources/audio/weird.wav"); // Load WAV audio file fxOgg = LoadSound("resources/audio/tanatana.ogg"); // Load OGG audio file for (int i = 0; i < MAX_BALLS; i++) { soundBallsPosition[i] = (Vector2){ 650 + 560/2 + GetRandomValue(-280, 280), 220 + 200 + GetRandomValue(-200, 200) }; soundBallsColor[i] = (Color){ GetRandomValue(0, 255), GetRandomValue(0, 255), GetRandomValue(0, 255), 255 }; soundBallsRadius[i] = GetRandomValue(2, 50); soundBallsAlpha[i] = 1.0f; soundBallsActive[i] = false; } // ENDING screen variables Initialization raylibLogoA = LoadTexture("resources/raylib_logo.png"); #ifndef PLATFORM_WEB SetTargetFPS(60); #endif #if defined(PLATFORM_WEB) emscripten_set_main_loop(UpdateDrawOneFrame, 0, 1); #else //-------------------------------------------------------------------------------------- // Main game loop while (!WindowShouldClose() && !closeWindow) // Detect window close button or ESC key { UpdateDrawOneFrame(); } #endif // De-Initialization //-------------------------------------------------------------------------------------- // Unload all loaded data (textures, fonts, audio) UnloadSpriteFont(fontAlagard); // SpriteFont unloading UnloadSpriteFont(fontPixelplay); // SpriteFont unloading UnloadSpriteFont(fontMecha); // SpriteFont unloading UnloadSpriteFont(fontSetback); // SpriteFont unloading UnloadSpriteFont(fontRomulus); // SpriteFont unloading UnloadTexture(raylibWindow); UnloadTexture(raylibWindow01); UnloadTexture(raylibWindow02); UnloadTexture(raylibWindow03); UnloadTexture(platforms); UnloadTexture(raylibLogoA); UnloadTexture(raylibLogoB); UnloadTexture(lena); UnloadTexture(mandrill); UnloadTexture(texAlagard); UnloadSpriteFont(fontMechaC); UnloadSpriteFont(fontAlagardC); UnloadSpriteFont(fontJupiterC); UnloadTexture(catTexture); UnloadModel(cat); UnloadSound(fxWav); UnloadSound(fxOgg); CloseAudioDevice(); CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- return 0; }
int main() { // Initialization //-------------------------------------------------------------------------------------- int screenWidth = 800; int screenHeight = 450; InitWindow(screenWidth, screenHeight, "raylib [models] example - cubesmap loading and drawing"); // Define the camera to look into our 3d world Camera camera = {{ 16.0, 14.0, 16.0 }, { 0.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 }}; Image image = LoadImage("resources/cubicmap.png"); // Load cubicmap image (RAM) Texture2D cubicmap = LoadTextureFromImage(image); // Convert image to texture to display (VRAM) Model map = LoadCubicmap(image); // Load cubicmap model (generate model from image) // NOTE: By default each cube is mapped to one part of texture atlas Texture2D texture = LoadTexture("resources/cubicmap_atlas.png"); // Load map texture SetModelTexture(&map, texture); // Bind texture to map model Vector3 mapPosition = { -16, 0.0, -8 }; // Set model position UnloadImage(image); // Unload cubesmap image from RAM, already uploaded to VRAM SetCameraMode(CAMERA_ORBITAL); // Set an orbital camera mode SetCameraPosition(camera.position); // Set internal camera position to match our custom camera position SetTargetFPS(60); // Set our game to run at 60 frames-per-second //-------------------------------------------------------------------------------------- // Main game loop while (!WindowShouldClose()) // Detect window close button or ESC key { // Update //---------------------------------------------------------------------------------- UpdateCamera(&camera); // Update internal camera and our camera //---------------------------------------------------------------------------------- // Draw //---------------------------------------------------------------------------------- BeginDrawing(); ClearBackground(RAYWHITE); Begin3dMode(camera); DrawModel(map, mapPosition, 1.0f, WHITE); End3dMode(); DrawTextureEx(cubicmap, (Vector2){ screenWidth - cubicmap.width*4 - 20, 20 }, 0.0f, 4.0f, WHITE); DrawRectangleLines(screenWidth - cubicmap.width*4 - 20, 20, cubicmap.width*4, cubicmap.height*4, GREEN); DrawText("cubicmap image used to", 658, 90, 10, GRAY); DrawText("generate map 3d model", 658, 104, 10, GRAY); DrawFPS(10, 10); EndDrawing(); //---------------------------------------------------------------------------------- } // De-Initialization //-------------------------------------------------------------------------------------- UnloadTexture(cubicmap); // Unload cubicmap texture UnloadTexture(texture); // Unload map texture UnloadModel(map); // Unload map model CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- return 0; }