Creating Tests in OpenGL
Skills:
Tool Use & Function Calling90%Agent Foundations80%Multi-Agent Systems60%Autonomous Workflows50%
Key Takeaways
The video demonstrates creating tests in OpenGL, covering topics such as test menu design, test instance creation, and GUI button implementation. It utilizes tools like OpenGL, C++, and STD function class to create a test framework and manage tests.
Full Transcript
hey what's up guys my name is Jenna welcome back to my OpenGL series so we are back last time we talked about creating this whole test framework and test classes and all that and we had something where we could actually create test classes which extended like kind of a base test class and we could kind of demonstrate each individual OpenGL or feature or whatever we wanted to really do with OpenGL in kind of a sandbox test environment that was really clear for us to kind of I guess demonstrate and have samples of the various pages that we learned about in OpenGL and just various kind of neural graphical tests that's the kind of stuff that we're going to use it for in the future so if you haven't seen that video then definitely check that out because today we're gonna be extending that and last time I gave you guys a bit of homework to figure out how we could create some kind of test menu where we could click on a test and it would construct a new test and then when we went back to the main menu it would kind of delete that test unload all the resources and then kind of present us with that test menu again and today I'm going to show you one of the ways that we can actually implement this so thank you to all those people who shared their solutions I think most them will shed on discord so if you guys have enjoyed my discord that is discord sorry it's the channel of calm slash discord and then that's kind of the invite link it's just a great community of people where you can talk about all kind of aspects of programming develop and graphics games whatever it is you want to talk about all that stuff is there so that we join that community if you haven't already anyway let's just dive into some code and check out a way for us to create that test menu and have it kind of construct and destruct class instances for us okay so jumping into the application does the agree file that we have if you guys don't have access to this yet by the way definitely go to pager I'm a chrome for slash the Cherno help support this series it really does help me make more videos for you guys and you'll also receive all of the code kind of episode by episode as separate commits on github so definitely check that out and help support series this is the code from the beginning of the test framework episode and if we take a look at what we have here essentially we already have this test that we're kind of presenting this test clear color but what I'm actually going to do is start off by just going to these tech this test folder and adding a new and it's gonna be actually you know what wouldn't even have to create a new file we're just going to do this in the test on H header file and we will need a CBP file because I do want to separate the implementation so I will create a CPP file called test dot CPP and over here in the in Silvis namespace I'm gonna create this test menu and this test menu class is going to have it's just going to be a test really so if we implement a rather extend test class here and then we'll have pretty much all of this stuff so I'll just copy and paste that over here umm I won't implement this and I'll just mark it as override override and override the cool thing about this by the way is that because I didn't make them cure virtual functions let's get rid of this because I didn't make them pure virtual functions we don't actually have to have other ones we don't mean so this is a great example I think someone asked in the comments below why why I didn't make these functions pure virtual and I would do that by just writing equals adora like this the reason I kind of left them as just special functions and implemented them with a blank body like this is said that we could selectively choose which ones we actually wanted to implement ourselves if there were equals zero if they were all pure virtual I'd have to have all three but with this method I don't actually want on a potato or and just I don't need to have them I can just go ahead and delete them and then everything will still work fine I don't have to implement them it's just an option that's given to me so this test menu class is going to do two things first of all it's going to contain a collection of all of our tests and we want a way to be able to basically I guess present them with a specific name so we need a pointer to a test class a test instance I guess a test object instance but I also want to store a name that we can provide the test so that that's kind of the label I guess that appears for our button in the test menu so what I'm gonna do is print a vector of STD pair and we're gonna have a pair of string and the actual test pointer like this now here's where it gets a little bit interesting I don't actually want a test pointa because that implies that the instance already exists which would be great if we kind of went with the strategy of I just want to create all of my tests at the beginning of my obligation and then add them to my menu and then like switching to them would activate them maybe but I don't really want to do that because what I'm doing right is I've got my constructor and destructor so what I actually want to happen is when I press the button I don't want to just activate a test instance I actually wanted to create and construct a test instance I literally wanted to say new tests and when I kind of go back out of that test I wanted to delete the test so I can't just add a test pointer because the test pointer of course would be appointed to an already existing object what I mean instead is a way to construct that object and one way that I could do that which I'm is what I'm gonna do now here is I could actually just provide it with a lambda I could provide it with a function that constructs that that test class of mine so if we go back here I'm gonna make the second element of the pair here an STD function of just test point a here and no parameters so this basically means that this function returns a test pointer and it doesn't take any parameters so this is basically going to return new tests depending on which test we actually create and then that's gonna be my vector now I'm going to call this tests okay so I need one one angular bracket here I'll include functional so that I get access to the STD function glass okay cool so there we go I've got a I've got a vector of pairs and each pair contains a string and a function which returns a test pointer and takes no parameters okay so I could have printed a struct hit so creating an STD pad but this is actually rather trivial I don't really want to create called you type in a new struct called like I don't know test I don't know what I call it somebody got tests so maybe like test menu instance or something I'm not sure there's no need to declare anything like that we can keep it kind of anonymous because we know it here that basically this is just a collect a list write a vector of strings and the actual test classes which those those strings kind of create because the string is just bad because we want to give our button a label this little makes sense when we actually see it on the screen okay cool and then one other thing I actually want is a pointer to the current test now the reason we need this is because our menu is going going to change the current test is active right now application we don't have a current test we've just got this what I'm actually going to do here is have an actual test pointer which is our current text a cow is called current current this is what we actually need to modify it and we want the test menu to actually do that for us now we could again pass in some kind of lambda or something which modifies this but an easier way is going to be just depositing a reference through that test pointer and then this test menu is actually going to be able to write to that pointer and thus change the current test so in the constructor here to pass in that I guess we'll call a current test pointer and then if we right click yeah actually let's go back to that say cookie file so I can include tests don't age and we put in namespace the tests and then we can go back here and implement everything we need by creating the method implementations okay cool I don't think when you disrupt it actually because everything's stack allocated anyway so we can get rid of that destructor and then this is great to merely do what I want that's because it's the test namespace not tests so get rid of that and do that okay so constructor is gonna set current tests to current test point up like that and then online GUI render is going to actually render that list that we have so I'll just say for auto and this would be I guess tests in our tests what we're going to do is actually create a render and I'm good button room now wise okay what's wrong on here Esther didn't know okay we need to include a vector oops okay so inside this tests when I'm going to base the red or line blue button so we'll say I'm going button label is going to be that test this is a pad or yeah so test first and the a dot visual assist thank you dot C string because it wants a C string one second star pointer and then of course if that button is pressed we basically want to execute what that button says to do and that button what that button says to do is that actual function so we really just need to call test dot second like that because it's the function we want to execute now we don't just need to call it this returns remember this returns a test pointer this returns the new test pointer that is supposed to construct for us so that's what we actually want to set current test to so current test gets set to that lambda that constructs our actual test class instance we haven't actually created that lambda yet that function but we will in a second let's include I am going here because we need to okay cool there we go so that looks pretty good to me so we've got a we should have a list of buttons and if we press the button then it will hopefully change that current test pointer to be whatever this test actually returns as it's kind of creation function okay cool that looks pretty good to me let's go ahead and create that test menu I'll go ahead and include it over here as well so actually to already be included because it's in the test a shadow file so we'll say test menu menu equals new test test menu we're going to pass in this current test I'll actually call this current test just so that it's a bit more split by default we'll set this equal to null and then when it does get created over here we'll set the current test equal to menu because we wanted to basically start off with the menu now at this point you could add some kind of command line argument or something like that if you wanted this application to boot up already with a specific test this is very useful if you're actually trying to test something because if you're actually working on a test or working on a new technique or something or trying to implement something whatever it is and it's implemented as a test you don't want to have the menu come up every time and you have to click on it so every time you debug your code many comes up then you have to click on it menu comes up that's a waste of time so you can just get it to kind of open a test for you kind of from the get-go without having to go first to the menu and instead of hard-coding that to just go to a specific test or whatever you could just have it as a command-line argument that's really nice if you're working in a team as well because it means that instead of you accidentally checking in the code that sets the test for specific tests the one that you're working on you can just have it as a command-line argument which is technically still kind of in your user settings and those wouldn't actually be committed to the project so yeah you could do something like that if you like that could be on those homework tasks or make it take in the name of a testers command-line argument and open that in maybe if that's actually exact command line argument and actually say ok cool so we weren't worried about this test psychologists yet now we are creating everything on the heap here by the way because we do want explicit deletion and all that stuff so this test clear call or whatever will kind of change in a minute let's just make sure this works first we have no way to actually add tests and I'm aware of that we'll fix that in a minute but I want to set this up first basically what we're going to do is when we start a new frame we're gonna say if the current test is not null right so if current test then we're going to basically update the current test and render the current test and then we're going to begin our I'm GUI window which is going to be just called test I guess which is going to be we can actually set the name of the test but we'll keep it as just test for now on up table taken zero I guess is at Delta time and then this is actually what's going to call I guess contest on Renda oh sorry on I'm going rendered now we are going to have to implement that back button that I talked about let's go ahead and do that now actually so if our current test is not the menu test so it doesn't equal menu which record menu or something like that text menu just so that we're not too confused here I like to call my variables meaningful things even if it does mean making them longer so we'll call this test menu so the so if the current test is not test menu and I'm going button I guess we'll just draw a back our for now so basically we're going to draw an iron GUI button I can't believe I drew that that was we're going to draw an iron GUI button which is our back arrow but that's something gonna happen if the test is in test menu right so I couldn't ask these if statements but I've just added them kind of side by side with and and operator which means of course this condition won't even be evaluated if this is false so if it can if the current test is not test menu then we'll draw this button and if that button is clicked and that's when we get into this stage so what we want to do is delete the current test and then set the current test equal to test menu and that is pretty much it okay cool so now we have a way to get back to our test menu really all we need now as a way to actually create kind of tests right so the way I want to do that is I'm actually gonna add a function and I'm actually gonna kind of write the code it as its function exists already a lot of people ask me what a good way to write kind of modular complex code oh just how to write code really when you're kind of not sure if like you know you don't want to just start running a function because you're not really sure what's the best for 10 what parameters that you take the best way to do that is just to pretend that the function already exists and just actually start by using the function so in this case I'm going to pretend that that function exists and into test menu I'm going to just write test menu our register test now I want to register the test I need a pass and the types is going to be a template so I want to register the test clear color and then of course I want to give it a name so I'll just use a parameter for that and I'll call it I don't know clear color or something like that right that's gonna be our play call a test that is now what I want the function to do okay I now nor the function needs to be a template it needs to take in the type it needs to also take in the name of the test so that it can display it in the test menu right because we have our test menu which displays those names as the button label and then of course the actual function needs to create a lambda that creates a new instance of this class type so it's really straightforward from now basically because I've already created the function I just need to implement it now so it's gonna be template type name t it's gonna be a void function called register test going to take in a Const string I guess we can just take in a concert pointer we are storing at string though so I guess we could take in a char pointer because of course we know that this actually this I'm going rent as a child pointer but I am converting it into a string which is also fine because we might want to do some manipulation or whatever and we should be using strings anyway so I'll still keep that here and then all this is really going to do is add that test into that list so just M tests don't push back now we're gonna have to make a pair here so make pair we're gonna pass them that name and then we're going to just create a very simple lambda doesn't it capture any variables that's just going to return nirrti and that's it because t is the type of class that we're actually creating okay and then what's gonna happen is of course as we call this register test class with every kind of different test type that would create the compiler is gonna create a new version of this register test function you know code base that actually returns the new kind of class instance that we requested based on the type okay one thing I will do is just quickly write for our sanity registering test and then we'll kind of print the name just because it would be nice to know which tests we actually kind of create I guess I'll not really create but register because of course we're deferring the creation until we run this lambda and we're running that lambda when we actually press that button to create it because it gets wrong right over here hopefully all this is making sense play your videos for you guys to watch about this definitely watch the one on lambdas I'll have it linked up there because and that of course is going to explain how lambdas work and how these kind of functions that work career getting called later how that whole thing works also templates another good video to watch so inside just check out my secret feed series my c++ series if you're not kind of sure what some of these things are because I have I think I've covered pretty much everything I'm using this video in that series okay so we are pretty much good to go we don't need to create this anymore at all because remember that actually gets created when we press the button so let's get rid of all this I think I've implemented everything I'm not sure because obviously I'm running the code right here live so let's just hit f5 and see what happens that's if I say that very often well I just hit f5 and see what happens actually get that on a t-shirt okay cool so we have this test we have clear color and then hopefully if I press clear color look at that it opens the clear color test shows us our clear color we can change all of that everything works pretty good I think and then if I go back we go back to the click on test now in this case you can see it hasn't actually changed the big collar which makes me think maybe it hasn't work but I'm pretty sure it has what I'm pretty sure has happened because you can see it does go back is that we're just not setting the click color so if we go back here and do we have a way to set the click color inside the renderer I don't think we do we'll just got clear right so maybe into clear we could maybe add another function called set clear color and then this would take in we have a math library we're never math library I think right okay this is gonna be too hot and I really want to do this right now so if we come back to application does CBP we're just going to when we clear the call out of waste going to the college for black so she'll quit follow a server 2000 from stairs over and 0 and we'll set the Alpha to one just like that okay so now hopefully we should say that go back to black when we go out of the test because that's how much you work okay cool so if we click click color we go there go back it takes us back to play color now we'll be fantastic we had an additional to actually test this out and see if it works properly but we're gonna kind of get into that as we saw them coming doing more tests the texturing tests and all that I think next episode are probably going to create a bunch of tests and kind of divide out all the kind of concepts that we've learned right now in two separate tests so as we continue on with the OpenGL series we will be adding more and more tests but you can simply come in to basis of the framework is up and running you can just add kind of multiple tests to this thing and you'll have them all nice they've cleared the menu and they should be created upon creation upon like actually looking a button and then destroy it when we just right now there is a little bit of a memory leak of course because we don't delete the test menu or anything like that so what we actually need to do here is what I want to do is I will eat the current test form actually close the application now you could argue that of course if we do close the application of course the operating system is going to clean up anyway so we don't really need to do it ourselves however to be nice if we should still technically do it so what I want to do is delete the current test when we actually close the application so of course when this while loop terminates the while loop does the jealous of the window just close while loop and we start to chop this up shout everything down and terminate it I'm actually going to write delete current test now here's the thing and the process needs to be in this scope here's the thing I also want to delete the test menu however if the current test is the test menu I'll be deleting things twice so if current test does not equal test menu then we're going to delete test menu otherwise current tests already is the test menu and that's been your nation's leader so we shouldn't get any crashes with this code let's just hit f5 and see what we can do here so if we just close it right now we should be fine because it just deletes the current test which is the test menu and then if we hit f5 again am I going to go into that test and if we close it now it should kind of delay but if the current test and the test menu because the contest is no longer test menu ok anyway hope you guys enjoy this video you did you can hit that like button you can also show your support by your educational conversation picture no great way to get access to all the code of course that I wrote today and all of the other episodes as well huge shout out as always to all of my lovely supporters because these videos would not be here without you guys so I really am thankful for that and your support means a lot to me I will see you guys next time I'm gonna continue writing these tests I'm gonna write one for textures next time and then from then on of course we can start learning more about OpenGL and we'll have kind of a separate test class demonstrating all the stuff we learn kind of corrupt so it so I'm really excited about that I'll see you guys next time goodbye [Music]
Original Description
Patreon ► https://patreon.com/thecherno
Twitter ► https://twitter.com/thecherno
Instagram ► https://instagram.com/thecherno
Discord ► https://thecherno.com/discord
Series Playlist ► https://thecherno.com/opengl
Thank you to the following Patreon supporters:
- Dominic Pace
- Kevin Gregory Agwaze
- Sébastien Bervoets
- Tobias Humig
- Peter Siegmund
- Kerem Demirer
Gear I use:
-----------------
BEST laptop for programming! ► http://geni.us/pakTES
My FAVOURITE keyboard for programming! ► http://geni.us/zNhB
FAVOURITE monitors for programming! ► http://geni.us/Ig6KBq
MAIN Camera ► http://geni.us/t6xyDRO
MAIN Lens ► http://geni.us/xGoDWT
Second Camera ► http://geni.us/CYUQ
Microphone ► http://geni.us/wqO6g7K
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from The Cherno · The Cherno · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
3D Game Programming - Episode 1 - Window
The Cherno
3D Game Programming - Episode 2 - Game Loop
The Cherno
3D Game Programming - Episode 3 - Arrays
The Cherno
3D Game Programming - Episode 4 - Drawing Pixels!
The Cherno
3D Game Programming - Episode 4.5 - How Rendering Works
The Cherno
3D Game Programming - Episode 5 - Playing with Pixels!
The Cherno
3D Game Programming - Episode 6 - Performance Boosting
The Cherno
3D Game Programming - Episode 7 - FPS Counter
The Cherno
3D Game Programming - Episode 8 - Alpha Support and More
The Cherno
3D Game Programming - Episode 9 - Beginning 3D
The Cherno
3D Game Programming - Episode 10 - Floors and Animation
The Cherno
3D Game Programming - Episode 11 - Rotation
The Cherno
3D Game Programming - Episode 12 - User Input
The Cherno
3D Game Programming - Episode 13 - Render Distance Limiter!
The Cherno
3D Game Programming - Episode 14 - Basic Mouse Movement
The Cherno
3D Game Programming - Episode 15 - Textures + More!
The Cherno
3D Game Programming - Episode 16 - Walking, Crouching, Sprinting + More
The Cherno
3D Game Programming - Episode 16.5 - Exporting Runnable Jars
The Cherno
3D Game Programming - Episode 17 - Small Adjustments + Birthday!
The Cherno
3D Game Programming - Episode 17.5 - Creating an Applet
The Cherno
3D Game Programming - Episode 18 - The Beginning of Walls
The Cherno
3D Game Programming - Episode 18.1 - A Few More Things
The Cherno
Episode 18.5 - Creating an EXE File in Java
The Cherno
3D Game Programming - Episode 19 - Rendering Walls
The Cherno
3D Game Programming - Episode 20 - Continuing Walls, Fixing Bugs, and Managing Crashes
The Cherno
3D Game Programming - Episode 21 - Texturing Walls, Fixing Clipping, and Fixing the Mouse
The Cherno
3D Game Programming - Episode 22 - Random Level Generator + Properly Fixing Clipping
The Cherno
3D Game Programming - Episode 23 - Graphical User Interface (GUI) Launcher
The Cherno
3D Game Programming - Episode 24 - Making Our Launcher Work
The Cherno
3D Game Programming - Episode 25 - Writing and Reading Files
The Cherno
3D Game Programming - Episode 26 - Custom Resolutions
The Cherno
3D Game Programming - Episode 27 - Decorating the Launcher
The Cherno
3D Game Programming - Episode 28 - Continuing our Custom Launcher!
The Cherno
3D Game Programming - Episode 29 - Launching The Game
The Cherno
3D Game Programming - Episode 30 - Colour Processing In-Depth
The Cherno
3D Game Programming - Episode 31 - Sprites!
The Cherno
3D Game Programming - Episode 32 - Sprite Mapping
The Cherno
3D Game Programming - Episode 33 - High Resolution Rendering
The Cherno
3D Game Programming - Episode 34 - Entities
The Cherno
Genesis - My Game for Ludum Dare 24
The Cherno
Vlog + Ludum Dare Results
The Cherno
Game Programming - Episode 1 - Resolution
The Cherno
Game Programming - Episode 2 - Threads
The Cherno
Game Programming - Episode 3 - Game Loop
The Cherno
Game Programming - Episode 4 - Window
The Cherno
Episode 5 - Buffer Strategy
The Cherno
Game Programming - Episode 6 - Graphics Initialized
The Cherno
Game Programming - Episode 7 - Buffered Image and Rasters
The Cherno
Game Programming - Episode 8 - The Screen Class
The Cherno
Game Programming - Episode 9 - Rendering Pixels
The Cherno
Game Programming - Episode 10 - Clearing the Screen
The Cherno
Game Programming - Episode 11 - "Out of Bounds, Baby!"
The Cherno
Game Programming - Episode 12 - Negative Bounds
The Cherno
Game Programming - Episode 13 - Timer
The Cherno
Game Programming - Episode 14 - FPS Counter
The Cherno
Episode 15 - Tiles
The Cherno
Game Programming - Episode 16 - The Map
The Cherno
The Walls 2 - Minecraft PvP Survival Map
The Cherno
Game Programming - Episode 17 - Key Input
The Cherno
Game Programming - Episode 18 - Controlling The Map
The Cherno
More on: Tool Use & Function Calling
View skill →Related Reads
📰
📰
📰
📰
Anthropic’s Mythos Preview Shows How AI Is Reshaping Defensive Vulnerability Research
Dev.to AI
How The Artificial Intelligence (AI) Safety Market Is Evolving And What To Expect By 2030
Dev.to AI
Protecting The Frontline From AI's Silent Failure
Forbes Innovation
AI Hyper-Scaling Digital Inequality
IEEE Spectrum
🎓
Tutor Explanation
DeepCamp AI