• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Salatinjsh

SDL and opengl textures

4 posts in this topic

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.
0

Share this post


Link to post
Share on other sites
I don't see anything wrong with you code but try setting:
[CODE]
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
[/CODE]

in case your texture is too small and is being mapped somewhere you cant see.

also since you're already using SDL you might want to try using SDL_image for image loading instead of SOIL. you use SDL_image to load an image to a surface and then find the format and number of colors. then you use glteximage2d to get the image from surface->pixels.

[CODE]
surface = IMG_Load("texture.png");

GLenum texture_format;
GLint nOfColors;
GLuint texture;
nOfColors = surface->format->BytesPerPixel;

glGenTextures( 1, &texture );
glBindTexture( GL_TEXTURE_2D, texture );

if (nOfColors == 4) // contains an alpha channel
{
if (surface->format->Rmask == 0x000000ff)
{
texture_format = GL_RGBA;
}
else
{
texture_format = GL_BGRA;
}
}
else if (nOfColors == 3) // no alpha channel
{
if (surface->format->Rmask == 0x000000ff)
{
texture_format = GL_RGB;
}
else
{
texture_format = GL_BGR;
}
}


glTexImage2D( GL_TEXTURE_2D, 0, nOfColors, surface->w, surface->h, 0, texture_format, GL_UNSIGNED_BYTE, surface->pixels );

SDL_FreeSurface(surface);
[/CODE] Edited by ic0de
0

Share this post


Link to post
Share on other sites
Well thanks for answer. :)
I have tryed usng soil and SDL but no difference and

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

didn't help. :(
Can it be problem with libraries? can they be at wrong positions?
0

Share this post


Link to post
Share on other sites
You are using immediate mode, which is deprecated.

Is GLuint LoadTextures(const char* filename) returning successfully? You have it return false when it fails, but you never test to see if it failed, you just assume that it succeeds.

It could be something as simple as not having the correct file path or format of the texture being loaded, and since you just ignore it and try not to set the texture if it fails, you never know. I don't know enough about the bmp format you're using for "Crate.bmp", how SOIL is used, or where the file is located to make a judgment, however I am certain that if you were to fail to load the texture properly and SOIL_load_OGL_texture returned 0, you would experience the issue you are noticing.
0

Share this post


Link to post
Share on other sites
[quote name='zeidrich' timestamp='1349296455' post='4986524']
You are using immediate mode, which is deprecated.
[/quote]

Immediate mode may be deprecated in OpenGL 3.0 but they are still useful for teaching beginners about OpenGL. teaching beginners OGL 3.0 is one sure way to confuse them.
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0