Results 1 to 3 of 3

Thread: Doesnt look like a crystal ball

  1. #1
    Junior Member Newbie
    Join Date
    Jun 2008
    Posts
    1

    Doesnt look like a crystal ball

    I want make small DLG that looks like 3DMax Material Editor,but I find it dosent go well,may code was below.


    I think my code can be divided into two blocks.
    first, I think draw the transparent ball,because I use the
    glColor4f(1.0f,0.0f,0.0f,0.5f);
    glBlendFunc(GL_SRC_ALPHA,GL_ONE);
    But,it doesnt make it transparent.

    second,the plane after the ball seems been affected the color,it looks like only has the red color. In fact, I want it to appeare its BMP file,which was drew by myself, a colorful chessboard,that always appears in 3D Max Material Editor when you make some glass material.

    So what is worng with my code?



    #include <GL/glut.h>
    #include <stdlib.h>
    #include <stdio.h>
    #include <assert.h>
    #include <gl/glaux.h>

    #pragma comment (lib,"glaux.lib")

    /* Create checkerboard texture */



    GLuint texture[1];

    void init(char* filename)
    {
    FILE *file=NULL;
    assert(filename);
    file = fopen(filename,"r");
    if ( !file )
    return;

    fclose(file);

    AUX_RGBImageRec *TextureImage[1];
    memset( TextureImage, 0, sizeof(void *)*1);

    TextureImage[0] = auxDIBImageLoad(filename);


    glGenTextures(1, &texture[0]);
    glBindTexture(GL_TEXTURE_2D, texture[0]);
    glTexImage2D( GL_TEXTURE_2D, 0, 3,
    TextureImage[0]->sizeX,
    TextureImage[0]->sizeY,
    0, GL_RGB, GL_UNSIGNED_BYTE,
    TextureImage[0]->data
    );

    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_LINEAR);

    if (TextureImage[0])
    {
    if (TextureImage[0]->data)
    {
    free(TextureImage[0]->data);
    }

    free(TextureImage[0]);
    }
    // glBindTexture(GL_TEXTURE_2D, texture[0]);
    }

    void display(void)
    {

    //LIGHT
    GLfloat ambient[] = { 0.0, 0.0, 0.0, 1.0 };
    GLfloat diffuse[] = { 1.0, 1.0, 1.0, 1.0 };
    GLfloat specular[] = { 1.0, 1.0, 1.0, 1.0 };
    GLfloat position[] = { 0.0, 3.0, 2.0, 0.0 };
    GLfloat lmodel_ambient[] = { 0.4, 0.4, 0.4, 1.0 };
    GLfloat local_view[] = { 0.0 };



    glClearColor(0.1, 0.1, 0.1, 0.0);
    glEnable(GL_DEPTH_TEST);
    glShadeModel(GL_SMOOTH);

    glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);
    glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
    glLightfv(GL_LIGHT0, GL_POSITION, position);
    glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
    glLightModelfv(GL_LIGHT_MODEL_LOCAL_VIEWER, local_view);

    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);


    // BALL
    glEnable( GL_COLOR_MATERIAL );
    glEnable(GL_BLEND);
    glColor4f(1.0f,0.0f,0.0f,0.5f);
    glBlendFunc(GL_SRC_ALPHA,GL_ONE);
    glColorMaterial( GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
    glutSolidSphere(1.0, 32, 32);
    glDisable(GL_COLOR_MATERIAL);
    glDisable(GL_BLEND);


    // BACKGROUND
    glEnable(GL_TEXTURE_2D);
    glBegin(GL_QUADS);
    glTexCoord2f(0.0f,0.0f); glVertex3f(-1.0f,-1.0f, 0.0f);
    glTexCoord2f(1.0f,0.0f); glVertex3f( 1.0f,-1.0f, 0.0f);
    glTexCoord2f(1.0f,1.0f); glVertex3f( 1.0f, 1.0f, 0.0f);
    glTexCoord2f(0.0f,1.0f); glVertex3f(-1.0f, 1.0f, 0.0f);
    glEnd();
    glFlush();
    }

    void reshape(int w, int h)
    {
    glViewport(0, 0, (GLsizei) w, (GLsizei) h);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(60.0, (GLfloat) w/(GLfloat) h, 1.0, 30.0);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glTranslatef(0.0, 0.0, -3.6);
    }

    void keyboard(unsigned char key, int x, int y)
    {
    switch (key) {
    case 27:
    exit(0);
    break;
    }
    }

    #include <list>
    #include <iostream>
    using namespace std;

    int main(int argc, char** argv)
    {
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
    glutInitWindowSize(250, 250);
    glutInitWindowPosition(100, 100);
    glutCreateWindow(argv[0]);
    init("s.bmp");
    glutReshapeFunc(reshape);
    glutDisplayFunc(display);
    glutKeyboardFunc (keyboard);
    glutMainLoop();

    return 0;
    }

  2. #2
    Senior Member Frequent Contributor
    Join Date
    Apr 2000
    Location
    Melbourne,Victoria,Australia
    Posts
    748

    Re: Doesnt look like a crystal ball

    Try drawing your background BEFORE your ball.

  3. #3
    Senior Member Frequent Contributor
    Join Date
    Apr 2000
    Location
    Melbourne,Victoria,Australia
    Posts
    748

    Re: Doesnt look like a crystal ball

    And you should also call:

    glColor4f( 1.0f, 1.0f, 1.0f, 1.0f);

    Before drawing your plane. Otherwise the plane will be affected by the colour that you've selected from the previous call to glColor4f() (when you last drew the ball).

Similar Threads

  1. Ball to Ball Collisions
    By elasolova in forum OpenGL: General
    Replies: 3
    Last Post: 07-29-2010, 09:58 PM
  2. New developers wanted for Crystal Space
    By jorritTyberghein in forum OpenGL: General
    Replies: 0
    Last Post: 02-16-2007, 12:13 AM
  3. Crystal Space is looking for engine/OpenGL programmers
    By Jorrit Tyberghein in forum OpenGL: Advanced Coding
    Replies: 0
    Last Post: 05-06-2004, 12:23 AM
  4. crystal display lightning using opengl
    By in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 07-26-2002, 08:08 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean