Is there a way, for the program, to resize a lwjgl3 window, and also when a window is resized (By user or program) how do I change, I think it's called viewport, so that openGL diplayed on the hole screen.
Yes.
To resize a window use glfwSetWindowSize(): http://www.glfw.org/docs/latest/group__window.html#ga371911f12c74c504dd8d47d832d095cb (http://www.glfw.org/docs/latest/group__window.html#ga371911f12c74c504dd8d47d832d095cb)
To set the correct viewport, it is best to act on frambuffer resize events which can be done by setting the framebuffer size callback with glfwSetFramebufferSizeCallback(): http://www.glfw.org/docs/latest/group__window.html#ga3203461a5303bf289f2e05f854b2f7cf (http://www.glfw.org/docs/latest/group__window.html#ga3203461a5303bf289f2e05f854b2f7cf). If you really want to work on window resize events then there is the window size callback too: http://www.glfw.org/docs/latest/group__window.html#gaa40cd24840daa8c62f36cafc847c72b6 (http://www.glfw.org/docs/latest/group__window.html#gaa40cd24840daa8c62f36cafc847c72b6).
If you need help setting up callbacks ask as I can't seem to find a general tutorial on using them in LWJGL3.
I know Callbackes. I mean When the window is recized how do I have my textures projected on the hole screen. When I recize my window the textures show only on the part seen befor resizeing the window.
You can set the dimensions of the viewport using glViewport(). The viewport is the area of the window into which OpenGL draws and it is specified in pixels.
So waht does glOrtho do than
glOrtho() specifies a projection matrix.
Using the camera analogy, the projection matrix is the position & lens of the camera and the viewport is the position and size of the photo the camera produces.
There's more info on the various different parts of the OpenGL pipeline here: http://www.songho.ca/opengl/gl_transform.html (http://www.songho.ca/opengl/gl_transform.html)
Also I played around with glViewport(). It streches out the textures to fit the window. that's not what i want. I mean when the window get larger the parts that are now reveled I can't draw on (The textures seem to go behined the new parts). And I want the the textures not to chane size.
Not entirely sure what it is you need. Sounds like probably update the projection matrix and the viewport. Have a read of the link and it should be clear.
I made some simple images to represent my program.
One is the normal window
One is the window resized and I try going past the new reveled point
And one is what happes with glViewport
Still not sure what exactly what you want, and all the information you should need is in that link.
But try this code in your resize callback:
//width and height are the window's dimensions.
glViewport(0, 0, width, height);
glLoadIdentity();
glOrtho(0, width, 0, height, -1, 1);
That resizes the viewport to fill the entire window and resizes the projection to keep everything taking up the same space in the window.
It didn't seem to work, the glOrtho messed suff up (Nothing was being drawn on the screen). My best guess is I have to do something after it, but om not chore what. I use glOrtho when i statrt my program and every thing works well. By the way this image might help you understand what I mean.
Well you probably have the wrong matrix mode set. Try calling glMatrixMode(GL_PROJECTION) at the start of my previous code snippet and glMatrixMode (GL_MODELVIEW) at the end.
Tried that already . Nothing. ;D
Well then I'm not sure. Would need to know your code better to know what the problem is.
Here's some of my Code:
Main:
errorCallback = Callbacks.errorCallbackPrint(System.err);
glfwSetErrorCallback(errorCallback);
glfwInit();
LanchWindow(800, 600, "Game");
glDisable(GL_DEPTH_TEST);
glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glMatrixMode(GL_MODELVIEW);
glClearColor(0.5f, 0.0f, 1.0f, 1.0f);
int TankDown = loadTex("/home/dennis/Black Hole Breakers/Graphics/TankDown.png");
int TankSide = loadTex("/home/dennis/Black Hole Breakers/Graphics/TankSide.png");
int TankUp = loadTex("/home/dennis/Black Hole Breakers/Graphics/TankUp.png");
int Alien = loadTex("/home/dennis/Black Hole Breakers/Graphics/Alien.png");
Bullet = loadTex("/home/dennis/Black Hole Breakers/Graphics/Bullet.png");
initKey();
Keyboard_MouseManagerInit(windowID);
while(GLFW.glfwWindowShouldClose(windowID) == GL_FALSE)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
Move(100, 2);
Shoot(1, 5, 800, 600, 50);
AlienAPI(2);
glfwPollEvents();
//Draws acording to direction (way)
//Simple if statements
// \\
// _|
glBindTexture(GL_TEXTURE_2D, TankUp);
glBegin(GL_QUADS);
{
glTexCoord2f(1,1);glVertex2f(x,y);
glTexCoord2f(0,1);glVertex2f(x+100,y);
glTexCoord2f(0,0);glVertex2f(x+100,y+100);
glTexCoord2f(1,0);glVertex2f(x,y+100);
}
glEnd();
glBindTexture(GL_TEXTURE_2D, Alien);
glBegin(GL_QUADS);
{
glTexCoord2f(0,0);glVertex2f(Ax+100,Ay+100);
glTexCoord2f(1,0);glVertex2f(Ax,Ay+100);
glTexCoord2f(1,1);glVertex2f(Ax,Ay);
glTexCoord2f(0,1);glVertex2f(Ax+100,Ay);
}
glEnd();
glfwSwapBuffers(windowID);
try { Thread.sleep(5); } catch (InterruptedException e) {Thread.currentThread().interrupt();}
}
System.out.println("Player Got: "+PP);
System.out.println("Alien Got: "+AP);
System.exit(1);
The Launch Window function is:
private static void LanchWindow(int width, int height, String Title)
{
windowID = glfwCreateWindow(width, height, Title, MemoryUtil.NULL, MemoryUtil.NULL);
if(windowID == MemoryUtil.NULL) throw new IllegalStateException("Window Failed");
glfwWindowHint(GLFW_RESIZABLE, GL_TRUE);
ByteBuffer vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
glfwSetWindowPos(windowID, (GLFWvidmode.width(vidmode) - width) / 2, (GLFWvidmode.height(vidmode) - height) / 2);
glfwMakeContextCurrent(windowID);
glfwShowWindow(windowID);
GLContext.createFromCurrent();
glMatrixMode(GL_PROJECTION);
glOrtho(0, width, 0 , height, -1, 1);
}
If you need any thing else just tell me. ;D
Well then I can't see why my code would not be working.
BTW, gfwWindowHint() should be called before glfwCreateWindow(). It specifies hints to create the window with.
I fuigured it out ! ! !
I did't have my code in the right order. I payed orund with it and I got it. Here it is:
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, w, 0, h, -1, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
Thanks for all the help ! ! ! ;D :o ::)
To clarify, you moved "glMatrixMode(GL_PROJECTION)" to after "glViewport()" and that is what made it work?