OpenGL空白屏?

时间:2015-10-04 17:02:10

标签: c++ opengl

我正在从书中学习OpenGL,我完成了书中的内容,但是当我运行它(Eclipse C ++ IDE)时,我只得到了空白屏幕。 本书是“程序员的OpenGL指南”。我认为错误在Reshape()中,但代码来自book。

#include <iostream>
#include <GL/glew.h>
#include <GL/glut.h>

typedef const char* String;

String TITLE = "OpenGL";
int HEIGHT = 480;
int WIDTH = HEIGHT / 9 * 12;

void Update(int time){
    glutPostRedisplay();
    glutTimerFunc( 10, Update, 1);
}

void Init(){
    glClearColor(1.0, 1.0, 1.0, 0.0);
    glShadeModel(GL_FLAT);
}

void Render(){
    glClear(GL_COLOR_BUFFER_BIT);

    glColor3f(1.0, 1.0, 0.0);
    glLoadIdentity();
    gluLookAt(0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
    glScalef(1.0, 2.0, 1.0); // Modeling transformation
    glutWireCube(1.0);

    glutSwapBuffers();
}

void Reshape(int w, int h){
    glViewport(0, 0, (GLsizei) w, (GLsizei) h);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glMatrixMode(GL_MODELVIEW);
}

int main(int argc, char** argv){
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
    glutInitWindowSize(WIDTH, HEIGHT);
    glutCreateWindow(TITLE);

    glewExperimental = true;
    GLenum err = glewInit();
    if(err!=GLEW_OK){
        exit(1);
    }

    Init();
    Update(1);
    glutDisplayFunc(Render);
    glutReshapeFunc(Reshape);

    glutMainLoop();
    return 0;
}

1 个答案:

答案 0 :(得分:1)

是重塑功能肯定是错误的

使用

/**
 * Background Async Task to  Save product Details
 */
class SaveProductDetails extends AsyncTask<String, String, String> {

    /**
     * Before starting background thread Show Progress Dialog
     */
    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        Toast.makeText(getApplicationContext(), "saving..", Toast.LENGTH_SHORT).show();
        // Displays the progress bar for the first time.
        mBuilder.setProgress(100, 0, true);
        mNotifyManager.notify(id, mBuilder.build());
    }

    /**
     * Saving product
     */
    protected String doInBackground(String... args) {

        // getting updated data from EditTexts
        String name = editTextUserName.getText().toString();

        // Building Parameters
        List<NameValuePair> params = new ArrayList<NameValuePair>();
        params.add(new BasicNameValuePair(StaticVariables.UID, idOfCustomer));
        params.add(new BasicNameValuePair(StaticVariables.NAME, name));

        // sending modified data through http request
        // Notice that update product url accepts POST method
        JSONObject json = jsonParser.makeHttpRequest(StaticVariables.url_update_username,
                "POST", params);

        // check json success tag
        try {
            int success = json.getInt(StaticVariables.TAG_SUCCESS);

            if (success == 1) {
                // successfully updated
                Intent i = getIntent();
                // send result code 100 to notify about product update
                setResult(100, i);
                finish();
            } else if (success == 2) {
                // failed to update product
                Toast.makeText(getApplicationContext(), json.getString("message"), Toast.LENGTH_SHORT).show();
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }

        return null;
    }

    /**
     * After completing background task Dismiss the progress dialog
     **/
    protected void onPostExecute(String file_url) {
        // dismiss the dialog once product uupdated
        // dismiss the dialog once product uupdated
        Toast.makeText(getApplicationContext(), "succesfully", Toast.LENGTH_SHORT).show();
        mBuilder.setContentText("Upload complete");
        // Removes the progress bar
        mBuilder.setProgress(0, 0, false);
        mNotifyManager.notify(id, mBuilder.build());
        finish();
    }
}

代替