Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

#ActualSalatinjsh

Posted 28 September 2012 - 08:45 AM

Hello!

I have decided to move from glut to SDL to make window and handle other things. But now i encounter an issue. When im trying to print texture on objects it does nothing. I have tried different ways of loading textures but it seems not to be the problem

Linker:
SOIL
mingw32
SDLmain
SDL
opengl32
glu32

Im using classes:

Main App:
[source lang="cpp"]#include "CApp.h"CApp::CApp() { Surf_Display = NULL; w = 640; h = 480; Running = true; angle = 0;}int CApp::OnExecute() { if(OnInit() == false) { return -1; } glLoadIdentity(); SDL_Event Event; while(Running) { while(SDL_PollEvent(&Event)) { OnEvent(&Event); } OnLoop(); OnRender(); } OnCleanup(); glGetError(); return 0;}int main(int argc, char* argv[]) { CApp theApp; return theApp.OnExecute();}[/source]
Main header
[source lang="cpp"]#ifndef _CAPP_H_ #define _CAPP_H_#include <SDL/SDL.h>#include <GL/gl.h>#include <GL/glu.h>#include <GL/SOIL.h>#include <iostream>#include "CEvent.h"class CApp : public CEvent { private: // local variables bool Running; int w,h; //window width and height SDL_Surface* Surf_Display; GLuint texture[3]; GLUquadricObj* quadratic; GLfloat angle; public: CApp(); int OnExecute(); public: // Natural things in game application bool OnInit(); void OnEvent(SDL_Event* Event); void OnLoop(); void OnRender(); void OnCleanup(); public: // Events used void OnKeyDown(SDLKey sym, SDLMod mod, Uint16 unicode); void OnExit();};#endif[/source]
Init:
[source lang="cpp"]#include "CApp.h"void RenderInit();GLuint LoadTextures(const char* filename);bool CApp::OnInit() { if(SDL_Init(SDL_INIT_EVERYTHING) < 0) { return false; } SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE,   8); SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE,   8); SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE,   8); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE,   16); SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 32); SDL_GL_SetAttribute(SDL_GL_ACCUM_RED_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_ACCUM_GREEN_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_ACCUM_BLUE_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_ACCUM_ALPHA_SIZE, 8); SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS,  1); SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES,  2); if((Surf_Display = SDL_SetVideoMode(w, h, 32, SDL_HWSURFACE | SDL_GL_DOUBLEBUFFER | SDL_OPENGL)) == NULL) { return false; } SDL_ShowCursor(SDL_DISABLE); texture[0] = LoadTextures("Crate.bmp"); quadratic=gluNewQuadric(); gluQuadricNormals(quadratic, GLU_SMOOTH); gluQuadricTexture(quadratic, GL_TRUE); RenderInit(); glClearColor(0,0,0,1); glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); gluPerspective(45, (double)w / (double)h, 1, 200); GLfloat AmbientLightColor[] = {0,0,0, 1}; glLightModelfv(GL_LIGHT_MODEL_AMBIENT, AmbientLightColor); GLfloat Light0Color[] = {0.8,0.8,0.8,1}; GLfloat Light0Pos[] = {0.000000000000000000000000000000000000015,0,0}; glLightfv(GL_LIGHT0, GL_DIFFUSE, Light0Color); glLightfv(GL_LIGHT0, GL_POSITION, Light0Pos); glMatrixMode(GL_MODELVIEW); glEnable(GL_BLEND); glEnable(GL_DEPTH_TEST); glEnable(GL_TEXTURE_2D); glShadeModel(GL_SMOOTH); glClearColor(0.0f, 0.0f, 0.0f, 0.5f);    // Black Background glClearDepth(1.0f); glDepthFunc(GL_LEQUAL); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); return true;}void RenderInit(){ glNewList(1, GL_COMPILE); glBegin(GL_QUADS); glNormal3f(0,0,-1); glTexCoord2d(0,0);glVertex3d(-1,-1,-1); glTexCoord2d(1,0);glVertex3d(1,-1,-1); glTexCoord2d(1,1);glVertex3d(1,1,-1); glTexCoord2d(0,1);glVertex3d(-1,1,-1); glNormal3f(0,0,1); glTexCoord2d(0,0);glVertex3d(-1,-1,1); glTexCoord2d(1,0);glVertex3d(1,-1,1); glTexCoord2d(1,1);glVertex3d(1,1,1); glTexCoord2d(0,1);glVertex3d(-1,1,1); glNormal3f(-1,0,0); glTexCoord2d(1,0);glVertex3d(-1,-1,-1); glTexCoord2d(1,1);glVertex3d(-1,1,-1); glTexCoord2d(0,1);glVertex3d(-1,1,1); glTexCoord2d(0,0);glVertex3d(-1,-1,1); glNormal3f(1,0,0); glTexCoord2d(1,0);glVertex3d(1,-1,-1); glTexCoord2d(1,1);glVertex3d(1,1,-1); glTexCoord2d(0,1);glVertex3d(1,1,1); glTexCoord2d(0,0);glVertex3d(1,-1,1); glEnd(); glEndList();}GLuint LoadTextures(const char* filename){ GLuint texture = SOIL_load_OGL_texture ( filename, SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_INVERT_Y ); if(texture == 0) return false; glBindTexture(GL_TEXTURE_2D, texture); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); return texture;}[/source]
Render:
[source lang="cpp"]#include "CApp.h"void CApp::OnRender() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslated(0,0,-5); glTranslated(0,0,-5); glRotatef(angle,0,1,0); //glRotatef(90,-1,0,0); glBindTexture(GL_TEXTURE_2D, texture[0]); //gluSphere(quadratic,1.3,32,16); glBegin(GL_QUADS); glTexCoord2d(0,0);glVertex3d(-1,-1,0); glTexCoord2d(0,1);glVertex3d(-1,1,0); glTexCoord2d(1,1);glVertex3d(1,1,0); glTexCoord2d(1,0);glVertex3d(1,-1,0); glEnd(); SDL_GL_SwapBuffers();}[/source]

ill be glad if someone could help. i've been looking for issue for about week now.

#1Salatinjsh

Posted 28 September 2012 - 05:50 AM

Hello!

I have decided to move from glut to SDL to make window and handle other things. But now i encaunter an issue. When im trying to print texture on objects it does nothing.

Linker:
SOIL
mingw32
SDLmain
SDL
opengl32
glu32

Im using classes:

Main App:
[source lang="cpp"]#include "CApp.h"CApp::CApp() {    Surf_Display = NULL;    w = 640;    h = 480;    Running = true;    angle = 0;}int CApp::OnExecute() {    if(OnInit() == false) {        return -1;    }    glLoadIdentity();    SDL_Event Event;    while(Running) {        while(SDL_PollEvent(&Event)) {            OnEvent(&Event);        }        OnLoop();        OnRender();    }    OnCleanup();    glGetError();    return 0;}int main(int argc, char* argv[]) {    CApp theApp;    return theApp.OnExecute();}[/source]
Main header
[source lang="cpp"]#ifndef _CAPP_H_    #define _CAPP_H_#include <SDL/SDL.h>#include <GL/gl.h>#include <GL/glu.h>#include <GL/SOIL.h>#include <iostream>#include "CEvent.h"class CApp : public CEvent {    private: // local variables        bool            Running;        int             w,h; //window width and height        SDL_Surface*    Surf_Display;        GLuint texture[3];        GLUquadricObj* quadratic;        GLfloat angle;    public:        CApp();        int OnExecute();    public: // Natural things in game application        bool OnInit();        void OnEvent(SDL_Event* Event);        void OnLoop();        void OnRender();        void OnCleanup();    public: // Events used        void OnKeyDown(SDLKey sym, SDLMod mod, Uint16 unicode);        void OnExit();};#endif[/source]
Init:
[source lang="cpp"]#include "CApp.h"void RenderInit();GLuint LoadTextures(const char* filename);bool CApp::OnInit() {    if(SDL_Init(SDL_INIT_EVERYTHING) < 0) {        return false;    }    SDL_GL_SetAttribute(SDL_GL_RED_SIZE,         8);    SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE,       8);    SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE,       8);    SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE,       8);    SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE,       16);    SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE,     32);    SDL_GL_SetAttribute(SDL_GL_ACCUM_RED_SIZE,     8);    SDL_GL_SetAttribute(SDL_GL_ACCUM_GREEN_SIZE, 8);    SDL_GL_SetAttribute(SDL_GL_ACCUM_BLUE_SIZE,     8);    SDL_GL_SetAttribute(SDL_GL_ACCUM_ALPHA_SIZE, 8);    SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS,  1);    SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES,  2);    if((Surf_Display = SDL_SetVideoMode(w, h, 32, SDL_HWSURFACE | SDL_GL_DOUBLEBUFFER | SDL_OPENGL)) == NULL) {        return false;    }    SDL_ShowCursor(SDL_DISABLE);    texture[0] = LoadTextures("Crate.bmp");    quadratic=gluNewQuadric();    gluQuadricNormals(quadratic, GLU_SMOOTH);    gluQuadricTexture(quadratic, GL_TRUE);    RenderInit();    glClearColor(0,0,0,1);    glViewport(0, 0, w, h);    glMatrixMode(GL_PROJECTION);    gluPerspective(45, (double)w / (double)h, 1, 200);    GLfloat AmbientLightColor[] = {0,0,0, 1};    glLightModelfv(GL_LIGHT_MODEL_AMBIENT, AmbientLightColor);    GLfloat Light0Color[] = {0.8,0.8,0.8,1};    GLfloat Light0Pos[] = {0.000000000000000000000000000000000000015,0,0};    glLightfv(GL_LIGHT0, GL_DIFFUSE, Light0Color);    glLightfv(GL_LIGHT0, GL_POSITION, Light0Pos);    glMatrixMode(GL_MODELVIEW);    glEnable(GL_BLEND);    glEnable(GL_DEPTH_TEST);    glEnable(GL_TEXTURE_2D);    glShadeModel(GL_SMOOTH);    glClearColor(0.0f, 0.0f, 0.0f, 0.5f);                   // Black Background    glClearDepth(1.0f);    glDepthFunc(GL_LEQUAL);    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);    glEnable(GL_LIGHTING);    glEnable(GL_LIGHT0);    return true;}void RenderInit(){    glNewList(1, GL_COMPILE);        glBegin(GL_QUADS);            glNormal3f(0,0,-1);            glTexCoord2d(0,0);glVertex3d(-1,-1,-1);            glTexCoord2d(1,0);glVertex3d(1,-1,-1);            glTexCoord2d(1,1);glVertex3d(1,1,-1);            glTexCoord2d(0,1);glVertex3d(-1,1,-1);            glNormal3f(0,0,1);            glTexCoord2d(0,0);glVertex3d(-1,-1,1);            glTexCoord2d(1,0);glVertex3d(1,-1,1);            glTexCoord2d(1,1);glVertex3d(1,1,1);            glTexCoord2d(0,1);glVertex3d(-1,1,1);            glNormal3f(-1,0,0);            glTexCoord2d(1,0);glVertex3d(-1,-1,-1);            glTexCoord2d(1,1);glVertex3d(-1,1,-1);            glTexCoord2d(0,1);glVertex3d(-1,1,1);            glTexCoord2d(0,0);glVertex3d(-1,-1,1);            glNormal3f(1,0,0);            glTexCoord2d(1,0);glVertex3d(1,-1,-1);            glTexCoord2d(1,1);glVertex3d(1,1,-1);            glTexCoord2d(0,1);glVertex3d(1,1,1);            glTexCoord2d(0,0);glVertex3d(1,-1,1);        glEnd();    glEndList();}GLuint LoadTextures(const char* filename){    GLuint texture = SOIL_load_OGL_texture        (        filename,        SOIL_LOAD_AUTO,        SOIL_CREATE_NEW_ID,        SOIL_FLAG_INVERT_Y        );    if(texture == 0)        return false;    glBindTexture(GL_TEXTURE_2D, texture);    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);    return texture;}[/source]
Render:
[source lang="cpp"]#include "CApp.h"void CApp::OnRender() {    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);    glMatrixMode(GL_MODELVIEW);    glLoadIdentity();    glTranslated(0,0,-5);    glTranslated(0,0,-5);    glRotatef(angle,0,1,0);    //glRotatef(90,-1,0,0);    glBindTexture(GL_TEXTURE_2D, texture[0]);    //gluSphere(quadratic,1.3,32,16);    glBegin(GL_QUADS);        glTexCoord2d(0,0);glVertex3d(-1,-1,0);        glTexCoord2d(0,1);glVertex3d(-1,1,0);        glTexCoord2d(1,1);glVertex3d(1,1,0);        glTexCoord2d(1,0);glVertex3d(1,-1,0);    glEnd();    SDL_GL_SwapBuffers();}[/source]

ill be glad if someone could help. i've been looking for issue for about week now.

PARTNERS