Anonymous
Anonymous
wanting to learn how to use openGL in C++
Anonymous
oh okie 👍
Dima
I think you should go with Vulkan. it’s a successor of opengl
Anonymous
Please no
Anonymous
But still how would i fix this
Anonymous
to render a triangle in vulkan it takes ~1k lines
Dima
but learning opengl 2.0 is useless ¯\_(ツ)_/¯
Anonymous
Ok
Anonymous
/start@MissRose_bot
Mihail
http://this.is-a-professional-domain.com/5FNNPha.png
const char* vertex = readFile(vertexFile).c_str(); here you're assigning the pointer of the std::string that the function returned, but that object is then destroyed and accessing that memory is no longer guaranteed to have the string you wanted
Anonymous
Whats the best to use then?
Mihail
Whats the best to use then?
why not use std::string instead of those char*'s?
Anonymous
glShaderSource needs a char*
Mihail
glShaderSource needs a char*
give it the c_str of vertex and fragment
Mihail
i'd assume it'd be smart enough that it knows it has to copy the char* you pass it
Anonymous
is it possible to keep a return in memory from a func
Dima
Yes
Dima
depends
Dima
use heap memory
Mihail
is it possible to keep a return in memory from a func
if you put it in memory yeah. like std::string vertex = readFile(vertexFile); would copy the std::string object back into memory
Mihail
Anonymous
How would i then do this
Anonymous
http://this.is-a-professional-domain.com/7e3CaVF.png
Anonymous
I got to write the file reading bit
Anonymous
then trow the readed text into the constructor, then return the created Shader obj
Mihail
http://this.is-a-professional-domain.com/7e3CaVF.png
std::string vertex = readFile(vertexFile); Shader shader (readFile(vertexPath).c_str(), readFile(fragmentPath).c_str());
Mihail
like this?
Mihail
not familiar with OpenGL, so idk
Anonymous
http://this.is-a-professional-domain.com/6sjaWVU.png
Anonymous
Pff
Anonymous
it's garbage when reaching the Shader constructor
Anonymous
:(
Anonymous
@mmihov any tips
Anonymous
return Shader(vertexCode.c_str(), fragmentCode.c_str());
Mihail
it isn't working?
Anonymous
No
Anonymous
http://this.is-a-professional-domain.com/9vA71f8.png
Anonymous
http://this.is-a-professional-domain.com/75nzgem.png
Mihail
http://this.is-a-professional-domain.com/75nzgem.png
why initialize a new std::string called vertexCode?
Anonymous
Becous the way i'm reading the file
Anonymous
that string contains the content of the file
Mihail
well tbh your code doesn't make sense
Dima
Mihail
so you want me to initializa a shader object, so then i can go and load a shader which in turn gives me a new shader object
Anonymous
It's a static method
Anonymous
So i can do Shader shader = Shader::loadShader(filepaths..);
Dima
I don’t recommend you combining these two types of shaders. but also separate them
Dima
there’s also geometry/tesselation, etc.
Mihail
ah then it's ok
Mihail
so you must make it so the constructor copies the two things you pass to it
Mihail
otherwise you'll have lifetime issues
Mihail
because remeber that you're passing pointers to characters
Mihail
not strings
Anonymous
They are seperated
Anonymous
I try to fucking read 2 files but failing hard af
Anonymous
starting to hate C++
Dima
Lol it’s okay
Mihail
starting to hate C++
well you wouldn't be having these issues, if you did it "the C++ way" and used std::string's
Anonymous
How would i do it then
Mihail
just assigning would work as it does a copy
Mihail
which is what you need here
Anonymous
example?
Anonymous
no
Mihail
no
so make sure the constructor takes std::string's and have the member variables be std::string's too
klimi
How is thay c++ related
Dima
Dayum
Anonymous
i tryed
Anonymous
But
Anonymous
the entire variable is null then
Dima
Lol instant ban
Mihail
Dima
Well I thought #ot at least. but yeah. we are not indian tech support.
Mihail
the entire variable is null then
can you try printing vertexCode inside of loadShader, because i'm starting to doubt that part is working
Mihail
tho it should be
Anonymous
What should I learn first STL or SDL?