Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8462147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T14:05:14+00:00 2026-06-10T14:05:14+00:00

I have been following an opengl tutorial, but for some reason when i added

  • 0

I have been following an opengl tutorial, but for some reason when i added the reshape function(for window resize to fix ratio). the opengl window doesnt show the object(shape) at all, just a black screen.
i dont know if i made a misspelling or something.

Is the reshape function messing things up?

#include <GL/gl.h>
#include <GL/glut.h>

void renderScene(void);
void changeSize(int w, int h);

int main(int argc, char **argv){

// init GLUT and create window
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowPosition(100,100);
glutInitWindowSize(320,320);
glutCreateWindow("Testing");

// register callbacks
glutDisplayFunc(renderScene);

// animation in reshaping
glutReshapeFunc(changeSize);

// enter GLUT event processing cycle
glutMainLoop();

return 1;
}

void renderScene(void){

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glBegin(GL_TRIANGLES);
    glVertex3f(-0.5,-0.5,0.0);
    glVertex3f(0.5,0.0,0.0);
    glVertex3f(0.0,0.5,0.0);
glEnd();

glutSwapBuffers();
}

void changeSize(int w, int h){

if (h==0)
    h = 1;
float ratio = 1.0*w/h;

// use the projection matrix
glMatrixMode(GL_PROJECTION);

//reset matrix
glLoadIdentity();

// set the viewpoint to be the entire window
glViewport(0,0,w,h);

// set the correct perspective
gluPerspective(45, ratio, 1, 1000);

// get back to the modelview
glMatrixMode(GL_MODELVIEW);
}

Thanks for any help!
This is from the Lighthouse3d tutorials.

PS: if i take out the reshape function, the triangle shows up(works fine).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T14:05:16+00:00Added an answer on June 10, 2026 at 2:05 pm

    Your triangle, as is, is not visible from that projection matrix you have defined with gluPerspective.

    That matrix defines a view cone, pointing in the -z direction, with a near plane at z=-1 and far plane at z=-1000.

    Your triangle lays on the z=0 plane, and as such is not visible.

    You can either:

    1. Move the triangle further back on the z direction (glTranslate(0,0,-2), or move the vertices manually).

    2. Use a view matrix that moves the camera away from (0,0,0), such as with gluLookAt

    3. Use an orthographic projection matrix that includes the z=0 plane, such as glOrtho(-1, 1, -1, 1, -1, 1)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have been following apps snowfall tutorial, but i am getting some issue in
I have been following this tutorial series for OpenGL : GLUT : http://www.lighthouse3d.com/opengl/glut/ I
Ive been following the android opengl tutorials at http://blog.jayway.com/2009/12/03/opengl-es-tutorial-for-android-part-i/ and have searched on how
I have been following the affableBean tutorial from the NetBeans site located here .
I have been following a tutorial on how to write a basic tile map
I have been following the tutorial on Microsofts website and they use GameTime to
I have been following a short tutorial to build a tab menu on my
Have been following Rails Tutorial by Michael Hart rails version 3.0 on mac OS
I have been following the RestKit installation instructions but I now have an error
I have been following this tutorial and everything was going nice and easy until

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.