Panel użytkownika
Nazwa użytkownika:
Hasło:
Nie masz jeszcze konta?

[OpenGL] Mam problem z wstawieniem bmp do programu.

Ostatnio zmodyfikowano 2013-03-14 06:04
Autor Wiadomość
nextt1994
Temat założony przez niniejszego użytkownika
[OpenGL] Mam problem z wstawieniem bmp do programu.
» 2013-03-11 15:16:31
Mam oddać program na zaliczenie, lecz nie mam pojęcia jak zrobić by obłożyć jakiś obiekt jakąś bmp'ą.
Prosze o pomoc.
C/C++
#include <windows.h>             
#define GLUT_DISABLE_ATEXIT_HACK 
#include <gl/glut.h>
#include <gl/glu.h>
#include <gl/glaux.h>
#include <gl/gl.h>
#include <stdlib.h>
#include <math.h>
/*GLuint      texture[0];
int LoadGLTextures(void)
{
    int status=FALSE;
    AUX_RGBImageRec *TextureImage[1];

    memset(TextureImage,0,sizeof(void *)*1);
    if (TextureImage[0]=LoadBMP("1.bmp"))
    {
        status=TRUE;
        glGenTextures(1, &texture[0]);
        glBindTexture(GL_TEXTURE_2D, texture[0]);
        gluBuild2DMipmaps(GL_TEXTURE_2D, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY,
                          GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);
        glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
        glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
        glTexParameteri( GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_NEAREST);
    }

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

    return status;
} */

float xpos = 90, ypos = - 25, zpos = 90, xrot = 0, yrot = 0, angle = 0.0; // wstępne ustawienie kamery
float step = 0.08, step2 =- 0.03, step3 = 0.03; // prędkości

float xx = 0, yy = 0, zz = 0, xm1, ym1;

void ruchmyszki( int xm, int ym )
{
    xrot =( ym + ym1 ) / 2;
    yrot =( xm + xm1 ) / 2;
    xm1 = xm;
    ym1 = ym;
}

void animacja( int val )
{
    angle += step;
    xx += step; //przesuwamy kulke
    yy -= step2; //
    zz += step3; //
    //<<
    if( xx + 10 >= 30 ) //
         step *=- 1; //
   
    if( xx - 10 <=- 30 ) //  Kolizja kulki
         step *=- 1; //
   
    if( yy + 10 >= 30 ) //
         step2 *=- 1; //
   
    if( yy - 10 <=- 30 ) //
         step2 *=- 1; //
   
    if( zz + 10 >= 30 ) //
         step3 *=- 1; //
   
    if( zz - 10 <=- 30 ) //
         step3 *=- 1; //
    //<<
    if( angle > 360.0f )
         angle = 0.0;
   
    glutPostRedisplay();
}


void kamera( void ) {
    glRotatef( xrot, 1.0, 0.0, 0.0 ); //lewo, prawo
    glRotatef( yrot, 0.0, 1.0, 0.0 ); //góra, dół
    glTranslated( - xpos, - ypos, - zpos );
}

//##########################################################################################
void display( void ) {
    glClearColor( 1, 1, 1, 0 );
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
    glLoadIdentity();
    glEnable( GL_DEPTH_TEST );
    glEnable( GL_LIGHT0 );
    glShadeModel( GL_SMOOTH );
    kamera();
   
    glBegin( GL_LINES );
    glColor3f( 0.0, 0.0, 0.0 );
   
    glVertex3f( 30.0, 30.0, 30.0 );
    glVertex3f( 30.0, - 30.0, 30.0 );
   
    glVertex3f( 30.0, - 30.0, 30.0 );
    glVertex3f( 30.0, - 30.0, - 30.0 );
   
    glVertex3f( 30.0, - 30.0, - 30.0 );
    glVertex3f( 30.0, 30.0, - 30.0 );
   
    glVertex3f( 30.0, 30.0, - 30.0 );
    glVertex3f( 30.0, 30.0, 30.0 );
   
    glVertex3f( - 30.0, 30.0, 30.0 );
    glVertex3f( - 30.0, - 30.0, 30.0 );
   
    glVertex3f( - 30.0, - 30.0, 30.0 );
    glVertex3f( - 30.0, - 30.0, - 30.0 );
   
    glVertex3f( - 30.0, - 30.0, - 30.0 );
    glVertex3f( - 30.0, 30.0, - 30.0 );
   
    glVertex3f( - 30.0, 30.0, - 30.0 );
    glVertex3f( - 30.0, 30.0, 30.0 );
   
    glVertex3f( 30.0, 30.0, 30.0 );
    glVertex3f( - 30.0, 30.0, 30.0 );
   
    glVertex3f( 30.0, - 30.0, 30.0 );
    glVertex3f( - 30.0, - 30.0, 30.0 );
   
    glVertex3f( 30.0, - 30.0, - 30.0 );
    glVertex3f( - 30.0, - 30.0, - 30.0 );
   
    glVertex3f( 30.0, 30.0, - 30.0 );
    glVertex3f( - 30.0, 30.0, - 30.0 );
    glEnd();
    glBegin( GL_QUADS );
    glColor3f( 1.0, 9.0, 0.0 );
    glVertex3d( 100, - 30.0, 100 );
    glVertex3d( - 100, - 30.0, 100 );
    glVertex3d( - 100, - 30.0, - 100 );
    glVertex3d( 100, - 30.0, - 100 );
    glEnd();
   
    glTranslatef( xx, yy, zz );
    glColor3f( 0.0, 2.0, 1.0 );
   
    glutWireSphere( 10, 20, 10 );
   
    glutSwapBuffers();
    angle++;
    glutTimerFunc( 100, animacja, 1 );
}

//##################################################################################
void reshape( int w, int h ) {
    glViewport( 0, 0,( GLsizei ) w,( GLsizei ) h ); //set the viewport to the current window specifications
    glMatrixMode( GL_PROJECTION ); //set the matrix to projection
   
    glLoadIdentity();
    gluPerspective( 60,( GLfloat ) w /( GLfloat ) h, 2.0, 1000.0 ); //set the perspective (angle of sight, width, height, , depth)
    glMatrixMode( GL_MODELVIEW ); //set the matrix back to model
   
}
//*********************************************************************************
void keyboard( unsigned char key, int x, int y ) // zwykłe klawisze np. q,w,e,r,t,y itd.
{
    if( key == 's' )
    {
        float xrotrad, yrotrad; //
        yrotrad =( yrot / 180 * 3.141592654f ); //
        xrotrad =( xrot / 180 * 3.141592654f ); //  zoom -
        xpos -= float( sin( yrotrad ) ); //
        zpos += float( cos( yrotrad ) ); //
        //  ypos += float(sin(xrotrad));                          //
    }
   
    if( key == 'w' )
    {
        float xrotrad, yrotrad; //
        yrotrad =( yrot / 180 * 3.141592654f ); //
        xrotrad =( xrot / 180 * 3.141592654f ); //  zoom +
        xpos += float( sin( yrotrad ) ); //
        zpos -= float( cos( yrotrad ) ); //
        // ypos -= float(sin(xrotrad)) ;                         //
    }
   
    if( key == 'd' )
    {
        yrot += 1;
        if( yrot > 360 ) yrot -= 360;
       
    }
   
    if( key == 'a' )
    {
        yrot -= 1;
        if( yrot < - 360 ) yrot += 360;
       
    }
    if( key == 27 ) // ESC
    {
        exit( 0 );
    }
   
    if( key == '+' ) //
    { //                   
       
    } //
   
    if( key == '-' ) //
    { //
       
    } //
   
   
}
//**********************************************************
void SpecialKeys( int key, int x, int y )
{
    switch( key )
    {
       
       
    case GLUT_KEY_UP:
        ypos += 1;
        break;
    case GLUT_KEY_DOWN:
        ypos -= 1;
        break;
       
       
       
    }
   
   
}
//**********************************************************
int main( int argc, char ** argv ) {
   
   
   
   
   
    glutInit( & argc, argv );
    glutInitDisplayMode( GLUT_DOUBLE | GLUT_DEPTH );
    glutInitWindowSize( 800, 800 );
    glutInitWindowPosition( 100, 100 );
    glutCreateWindow( "Mateusz Sulecki" );
    glutFullScreen();
    glutDisplayFunc( display );
    glutIdleFunc( display );
    glutReshapeFunc( reshape );
    ShowCursor( FALSE );
    glutPassiveMotionFunc( ruchmyszki );
    glutKeyboardFunc( keyboard );
    glutSpecialFunc( SpecialKeys );
    glutMainLoop();
    return 0;
}

P-78098
SeaMonster131
» 2013-03-11 15:22:23
P-78100
Gabes
» 2013-03-11 15:30:59
Do odpowiedniego ustawienia tekstury masz koordynaty.
  
C/C++
glBegin( GL_QUADS );
glTexCoord2f( 1.0f, 0.0f ); glVertex3f( 1.0, - 1.0, 0.0 );
glTexCoord2f( 0.0f, 0.0f ); glVertex3f( - 1.0, - 1.0, 0.0 );
glTexCoord2f( 0.0f, 1.0f ); glVertex3f( - 1.0, 1.0, 0.0 );
glTexCoord2f( 1.0f, 1.0f ); glVertex3f( 1.0, 1.0, 0.0 );
P-78101
nextt1994
Temat założony przez niniejszego użytkownika
» 2013-03-12 17:32:01
Teraz mam problem z linkierem.

  [Linker error] undefined reference to `glGetString@4'
  more undefined references to `glGetString@4' follow
  [Linker error] undefined reference to `wglGetProcAddress@4'
  [Linker error] undefined reference to `glTexImage2D@36'
  [Linker error] undefined reference to `glDeleteTextures@8'
  [Linker error] undefined reference to `glReadPixels@28'
  [Linker error] undefined reference to `glGetIntegerv@8'
  [Linker error] undefined reference to `glTexImage2D@36'
  [Linker error] undefined reference to `glGenTextures@8'
  [Linker error] undefined reference to `glTexImage2D@36'

to co mam w Project > Project Opcions > Patameters > Linker:
-lopengl32
lib/libopengl32.a
lib/libglu32.a
lib/libglut32.a
lib/libSOIL.a
lib/libSOIL.a


a oto cały kod

C/C++
#include <windows.h>             
#define GLUT_DISABLE_ATEXIT_HACK 
#include "glut.h"
#include "SOIL.h"
#include <gl/glu.h>
#include <gl/gl.h>
#include <stdlib.h>
#include <math.h>
GLuint texture[ 0 ];
int LoadGLTextures() // Load Bitmaps And Convert To Textures
{
    /* load an image file directly as a new OpenGL texture */
    texture[ 0 ] = SOIL_load_OGL_texture
    (
    "Data/obraz1.bmp",
    SOIL_LOAD_AUTO,
    SOIL_CREATE_NEW_ID,
    SOIL_FLAG_INVERT_Y
    );
   
    if( texture[ 0 ] == 0 )
         return false;
   
   
    // Typical Texture Generation Using Data From The Bitmap
    glBindTexture( GL_TEXTURE_2D, texture[ 0 ] );
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
   
    return true; // Return Success
}

//##########################################################################################
void display( void ) {
    glClearColor( 1, 1, 1, 0 );
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
    glLoadIdentity();
    glEnable( GL_DEPTH_TEST );
    glEnable( GL_LIGHT0 );
    glShadeModel( GL_SMOOTH );
   
   
   
    glBegin( GL_QUADS );
    glColor3f( 1.0, 9.0, 0.0 );
    glVertex3f( 0.5, - 0.5, 0.0 );
    glVertex3f( - 0.5, - 0.5, 0.0 );
    glVertex3f( - 0.5, 0.5, 0.0 );
    glVertex3f( 0.5, 0.5, 0.0 );
    glEnd();
   
    glutSwapBuffers();
}
//##################################################################################

//*********************************************************************************

//**********************************************************
int main( int argc, char ** argv ) {
    glutInit( & argc, argv );
    glutInitDisplayMode( GLUT_DOUBLE | GLUT_DEPTH );
    glutInitWindowSize( 1000, 1000 );
    glutInitWindowPosition( 100, 100 );
    glutCreateWindow( "Mateusz Sulecki" );
   
    glutDisplayFunc( display );
    glutIdleFunc( display );
   
    glutMainLoop();
    return 0;
}
P-78159
pekfos
» 2013-03-12 20:55:34
-lopengl32
lib/libopengl32.a
lib/libglu32.a
lib/libglut32.a
lib/libSOIL.a
lib/libSOIL.a
I jak to ma działać? Tylko pierwsza linia to opcja linkera.
P-78176
Gabes
» 2013-03-12 22:20:40
Najprostszy kod wyglądałby tak:
C/C++
#include "gl/glut.h"
#include "SOIL.h"
GLuint texture[ 0 ];
int LoadGLTextures() {
    texture[ 0 ] = SOIL_load_OGL_texture( "obrazek.bmp",
    SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_INVERT_Y );
    if( texture[ 0 ] == 0 ) return false;
   
    glBindTexture( GL_TEXTURE_2D, texture[ 0 ] );
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
    glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
    return true; // Return Success
}
void display( void ) {
    glClearColor( 1, 1, 1, 0 );
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
    glLoadIdentity();
    glBegin( GL_QUADS );
    glColor3f( 1.0, 1.0, 1.0 );
    glTexCoord2f( 1.0f, 0.0f ); glVertex3f( 0.5, - 0.5, 0.0 );
    glTexCoord2f( 0.0f, 0.0f ); glVertex3f( - 0.5, - 0.5, 0.0 );
    glTexCoord2f( 0.0f, 1.0f ); glVertex3f( - 0.5, 0.5, 0.0 );
    glTexCoord2f( 1.0f, 1.0f ); glVertex3f( 0.5, 0.5, 0.0 );
    glEnd();
    glutSwapBuffers();
}
int main( int argc, char ** argv ) {
    glutInit( & argc, argv );
    glutInitDisplayMode( GLUT_DOUBLE | GLUT_DEPTH );
    glutInitWindowSize( 600, 600 );
    glutInitWindowPosition( 100, 100 );
    glutCreateWindow( ":)" );
    glEnable( GL_DEPTH_TEST );
    glEnable( GL_TEXTURE_2D );
    LoadGLTextures();
    glutDisplayFunc( display );
    glutIdleFunc( display );
    glutMainLoop();
    return 0;
}

do linkera należy wpisać:
SOIL
glut32
opengl32
gdi32
winmm
ważna jest kolejność dodania poszczególnych bibliotek, wielkość liter nie, można zapisać Soil, sOiL.
Wszystkie biblioteki do OpenGL trzymamy w folderze GL.w include. stąd zapis gl/glut.h
No może poza SOIL.


P-78181
nextt1994
Temat założony przez niniejszego użytkownika
» 2013-03-13 07:19:22
No ale jak te:
-lopengl32
lib/libopengl32.a
lib/libglu32.a
lib/libglut32.a
lib/libSOIL.a

 mam zapisane to gdzie mam projekt. a poza tym linker  do gluta tak mi działa ;/
P-78187
nextt1994
Temat założony przez niniejszego użytkownika
» 2013-03-13 19:34:49
Pomóżcie Prosze. Tu na screenie widać  co mam w linkerze wpisane i jaki błąd mi pokazuje w kompilacji. http://www25.speedyshare.com/QZWvZ/download/screen1.jpg.
 Wkleiłem cały kod Gabes'a.
Pliki w katalogu które mam:

  • glut.h
  • SOIL.h
  • makefile.win
  • Project1.dev
  • Project1.exe
  • main.o
  • main.cpp
folder lib, a w nim : libglu32.a libglut32.a libopengl32.a libSOIL.a

Poniżej wkleje kod z Makefile.win :

# Project: Project1
# Makefile created by Dev-C++ 4.9.9.2

CPP  = g++.exe
CC   = gcc.exe
WINDRES = windres.exe
RES  =
OBJ  = main.o $(RES)
LINKOBJ  = main.o $(RES)
LIBS =  -L"D:/Programowanie/49/Dev-Cpp/lib" -L"C:/Users/NeXT/Desktop/Projekt na Psio/lib" -mwindows -SOIL -glut32 -glu32 -opengl32 -gdi32 -winmm 
INCS =  -I"D:/Programowanie/49/Dev-Cpp/include"
CXXINCS =  -I"D:/Programowanie/49/Dev-Cpp/lib/gcc/mingw32/3.4.2/include"  -I"D:/Programowanie/49/Dev-Cpp/include/c++/3.4.2/backward"  -I"D:/Programowanie/49/Dev-Cpp/include/c++/3.4.2/mingw32"  -I"D:/Programowanie/49/Dev-Cpp/include/c++/3.4.2"  -I"D:/Programowanie/49/Dev-Cpp/include"
BIN  = Project1.exe
CXXFLAGS = $(CXXINCS) 
CFLAGS = $(INCS) 
RM = rm -f

.PHONY: all all-before all-after clean clean-custom

all: all-before Project1.exe all-after


clean: clean-custom
${RM} $(OBJ) $(BIN)

$(BIN): $(OBJ)
$(CPP) $(LINKOBJ) -o "Project1.exe" $(LIBS)

main.o: main.cpp
$(CPP) -c main.cpp -o main.o $(CXXFLAGS)

Proszę pomóżcie.
P-78244
« 1 » 2
  Strona 1 z 2 Następna strona